You are here

function forum_pathauto_bulk_update_batch_process in Pathauto 6.2

Same name and namespace in other branches
  1. 7 pathauto.pathauto.inc \forum_pathauto_bulk_update_batch_process()

Batch processing callback; Generate aliases for forums.

1 string reference to 'forum_pathauto_bulk_update_batch_process'
_forum_pathauto in ./pathauto.pathauto.inc
Implements hook_pathauto() for forum module.

File

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

Code

function forum_pathauto_bulk_update_batch_process(&$context) {
  if (!isset($context['sandbox']['current'])) {
    $context['sandbox']['count'] = 0;
    $context['sandbox']['current'] = 0;
  }
  $concat = _pathauto_sql_concat("'forum/'", 't.tid');
  $forum_vid = variable_get('forum_nav_vocabulary', '');
  $sql = "SELECT t.tid FROM {term_data} t LEFT JOIN {url_alias} ua ON {$concat} = ua.src WHERE ua.src IS NULL AND t.tid > %d AND t.vid = %d ORDER BY t.tid";
  $args = array(
    $context['sandbox']['current'],
    $forum_vid,
  );

  // 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);
  $tids = array();
  while ($tid = db_result($query)) {
    $tids[] = $tid;
  }
  pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate');
  $context['sandbox']['count'] += count($tids);
  $context['sandbox']['current'] = max($tids);
  $context['message'] = t('Updated alias for forum @tid.', array(
    '@tid' => end($tids),
  ));
  if ($context['sandbox']['count'] >= $context['sandbox']['total']) {
    $context['finished'] = 1;
  }
  else {
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  }
}