You are here

function user_pathauto_bulk_update_batch_process in Pathauto 7

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

Batch processing callback; Generate aliases for users.

1 string reference to 'user_pathauto_bulk_update_batch_process'
user_pathauto in ./pathauto.module
Implements hook_pathauto() on behalf of user module.

File

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

Code

function user_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('user/', 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();
  pathauto_user_update_alias_multiple($uids, 'bulkupdate', array(
    'alias blog' => FALSE,
  ));
  $context['sandbox']['count'] += count($uids);
  $context['sandbox']['current'] = max($uids);
  $context['message'] = t('Updated alias for user @uid.', array(
    '@uid' => end($uids),
  ));
  if ($context['sandbox']['count'] != $context['sandbox']['total']) {
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  }
}