You are here

function blog_pathauto_bulk_update_batch_process in Pathauto 6.2

Same name and namespace in other branches
  1. 7 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.pathauto.inc
Implements hook_pathauto().

File

./pathauto.pathauto.inc, line 316
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;
  }
  $concat = _pathauto_sql_concat("'blog/'", 'u.uid');
  $sql = "SELECT u.uid FROM {users} u LEFT JOIN {url_alias} ua ON {$concat} = ua.src WHERE ua.src IS NULL AND u.uid > %d ORDER BY u.uid";
  $args = array(
    $context['sandbox']['current'],
  );

  // Get the total amount of items to process.
  if (!isset($context['sandbox']['total'])) {
    $context['sandbox']['total'] = db_result(db_query(_pathauto_sql_count($sql), $args));

    // If there are no nodes to update, the stop immediately.
    if (!$context['sandbox']['total']) {
      $context['finished'] = 1;
      return;
    }
  }
  $query = db_query_range($sql, $args, 0, 25);
  $uids = array();
  while ($uid = db_result($query)) {
    $uids[] = $uid;
    $account = user_load($uid);
    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'] = 1;
  }
  else {
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  }
}