You are here

function drush_auto_nodetitle_drush_update in Automatic Nodetitles 7

Drush callback to perform actual auto_nodetitle preset flush.

1 string reference to 'drush_auto_nodetitle_drush_update'
auto_nodetitle_drush_command in ./auto_nodetitle.drush.inc
Implementation of hook_drush_command().

File

./auto_nodetitle.drush.inc, line 33

Code

function drush_auto_nodetitle_drush_update() {
  global $user;
  $user = user_load(1);
  $args = func_get_args();
  $blocksize = 10;
  if (empty($args)) {
    drush_set_error(dt('You must specify a node type name to recreate or specify "all".' . "\n" . 'Node types are: ') . implode(' ', array_keys(_node_types_build()->types)));
    return FALSE;
  }
  else {

    // Implement 'all'
    if (count($args) == 1 && $args[0] == 'all') {
      $args = array_keys(node_type_get_types());
    }
    foreach ($args as $type) {
      $total = db_query("select count(nid) as count from node where type=:type", array(
        ':type' => $type,
      ))
        ->fetchField();
      $count = 0;
      drush_log(dt('Updating @total auto node titles for type "@type".', array(
        '@type' => $type,
        '@total' => $total,
      )), 'ok');
      do {
        $result = db_query_range("select nid from node where type=:type", $count, $blocksize, array(
          ':type' => $type,
        ));
        $nids = array();
        foreach ($result as $row) {
          $nids[] = $row->nid;
        }
        auto_nodetitle_operations_update($nids);
        $count += count($nids);
        print "{$count}/{$total} done\n";
        drush_log(dt('  @count done', array(
          '@count' => $count,
        )));
      } while ($count < $total);
      drush_log(dt('All done for type "@type".', array(
        '@type' => $type,
      )), 'ok');
    }
    return TRUE;
  }
}