You are here

function faq_pathauto_bulkupdate in Frequently Asked Questions 7

Same name and namespace in other branches
  1. 7.2 faq.module \faq_pathauto_bulkupdate()

Batch processing callback; Generate aliases for faq pages.

1 string reference to 'faq_pathauto_bulkupdate'
faq_pathauto in ./faq.module
Implements hook_pathauto().

File

./faq.module, line 1514
The FAQ module allows users to create a FAQ page, with questions and answers displayed in different styles, according to the settings.

Code

function faq_pathauto_bulkupdate() {
  module_load_include('inc', 'pathauto');
  if (!isset($context['sandbox']['current'])) {
    $context['sandbox']['count'] = 0;
    $context['sandbox']['current'] = 0;
  }
  $faq_path = _faq_path();

  // Get the allowed vocabs.
  $vocabularies = taxonomy_get_vocabularies('faq');
  $vocab_omit = variable_get('faq_omit_vocabulary', array());
  $faq_vocabs = array();
  foreach ($vocabularies as $vid => $vobj) {
    if (isset($vocab_omit[$vid]) && $vocab_omit[$vid] != 0) {
      continue;
    }
    $faq_vocabs[$vid] = $vid;
  }

  // Get tids that need aliasing.
  $query = db_select('taxonomy_term_data', 'td');
  $query
    ->leftJoin('url_alias', 'ua', "CONCAT({$faq_path} . '/', td.tid) = ua.source");
  $query
    ->addField('td', 'tid');
  $query
    ->isNull('ua.source');
  $query
    ->condition('td.tid', $context['sandbox']['current'], '>');
  $query
    ->condition('td.vid', $faq_vocabs, 'IN');
  $query
    ->orderBy('td.tid');
  $query
    ->addTag('pathauto_bulk_update');
  $query
    ->addMetaData('entity', 'taxonomy_term');

  // 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();
  $terms = taxonomy_term_load_multiple($tids);
  foreach ($terms as $term) {
    pathauto_create_alias('faq', 'bulkupdate', $faq_path . '/' . $term->tid, array(
      'term' => $term,
    ));
  }
  $context['sandbox']['count'] += count($tids);
  $context['sandbox']['current'] = max($tids);
  $context['message'] = t('Updated alias for faq page @tid.', array(
    '@tid' => end($tids),
  ));
  if ($context['sandbox']['count'] != $context['sandbox']['total']) {
    $context['finished'] = $context['sandbox']['count'] / $context['sandbox']['total'];
  }
}