You are here

function node_pathauto_bulk_update_batch_process in Pathauto 7

Same name and namespace in other branches
  1. 6.2 pathauto.pathauto.inc \node_pathauto_bulk_update_batch_process()

Batch processing callback; Generate aliases for nodes.

1 string reference to 'node_pathauto_bulk_update_batch_process'
node_pathauto in ./pathauto.module
Implements hook_pathauto() on behalf of node module.

File

./pathauto.pathauto.inc, line 13
Pathauto integration for core modules.

Code

function node_pathauto_bulk_update_batch_process(&$context) {
  if (!isset($context['sandbox']['current'])) {
    $context['sandbox']['count'] = 0;
    $context['sandbox']['current'] = 0;
  }
  $query = db_select('node', 'n');
  $query
    ->leftJoin('url_alias', 'ua', "CONCAT('node/', n.nid) = ua.source");
  $query
    ->addField('n', 'nid');
  $query
    ->isNull('ua.source');
  $query
    ->condition('n.nid', $context['sandbox']['current'], '>');
  $query
    ->orderBy('n.nid');
  $query
    ->addTag('pathauto_bulk_update');
  $query
    ->addMetaData('entity', 'node');

  // Get the total amount of items to process.
  if (!isset($context['sandbox']['total'])) {
    $context['sandbox']['total'] = $query
      ->countQuery()
      ->execute()
      ->fetchField();

    // If there are no nodes to update, the stop immediately.
    if (!$context['sandbox']['total']) {
      $context['finished'] = 1;
      return;
    }
  }
  $query
    ->range(0, 25);
  $nids = $query
    ->execute()
    ->fetchCol();
  pathauto_node_update_alias_multiple($nids, 'bulkupdate');
  $context['sandbox']['count'] += count($nids);
  $context['sandbox']['current'] = max($nids);
  $context['message'] = t('Updated alias for node @nid.', array(
    '@nid' => end($nids),
  ));
  if ($context['sandbox']['count'] != $context['sandbox']['total']) {
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  }
}