1 taxonomy.path.inc taxonomy_path_bulk_update_batch_process(&$context)

Batch processing callback; Generate URL aliases for taxonomy terms.

File

core/modules/taxonomy/taxonomy.path.inc, line 74
Path integration.

Code

function taxonomy_path_bulk_update_batch_process(&$context) {
  if (!isset($context['sandbox']['current'])) {
    $context['sandbox']['count'] = 0;
    $context['sandbox']['current'] = 0;
  }

  $query = db_select('taxonomy_term_data', 'td');
  $query->addField('td', 'tid');
  $query->condition('td.tid', $context['sandbox']['current'], '>');
  $query->orderBy('td.tid');
  $query->addTag('path_bulk_update');
  $query->addMetaData('entity', 'taxonomy_term');
  if (!empty($context['choices'])) {
    $query->condition('td.vocabulary', $context['choices'], 'IN');
  }
  $query->leftJoin('url_alias', 'ua', "CONCAT('taxonomy/term/', td.tid) = ua.source");
  if ($context['op'] == 'update') {
    $query->isNotNull('ua.source');
  }
  if ($context['op'] == 'generate') {
    $query->isNull('ua.source');
  }

  // 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);
  $tids = $query->execute()->fetchCol();

  module_load_include('inc', 'path');
  path_verbose_suspend();
  $terms = taxonomy_term_load_multiple($tids);

  foreach ($terms as $term) {
    if (path_save_automatic_entity_alias($term)) {
      $context['results']['total']['taxonomy_term'] += 1;
    }
  }
  path_verbose_resume();

  $context['sandbox']['count'] += count($tids);
  $context['sandbox']['current'] = max($tids);
  $context['message'] = t('Updated alias for term @tid.', array('@tid' => end($tids)));

  if ($context['sandbox']['count'] != $context['sandbox']['total']) {
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  }
}