You are here

function blog_pathauto_bulk_update_batch_process in Pathauto 7

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

Batch processing callback; Generate aliases for blogs.

1 string reference to 'blog_pathauto_bulk_update_batch_process'
blog_pathauto in ./pathauto.module
Implements hook_pathauto() on behalf of blog module.

File

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

Code

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

  // 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);
  $uids = $query
    ->execute()
    ->fetchCol();
  $accounts = user_load_multiple($uids);
  foreach ($accounts as $account) {
    pathauto_blog_update_alias($account, 'bulkupdate');
  }
  $context['sandbox']['count'] += count($uids);
  $context['sandbox']['current'] = max($uids);
  $context['message'] = t('Updated alias for blog user @uid.', array(
    '@uid' => end($uids),
  ));
  if ($context['sandbox']['count'] != $context['sandbox']['total']) {
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  }
}