You are here

function uc_catalog_pathauto_bulkupdate in Ubercart 7.3

Same name and namespace in other branches
  1. 5 uc_catalog/uc_catalog.module \uc_catalog_pathauto_bulkupdate()
  2. 6.2 uc_catalog/uc_catalog.module \uc_catalog_pathauto_bulkupdate()

Implements hook_pathauto_bulkupdate().

Generate aliases for all categories without aliases.

1 string reference to 'uc_catalog_pathauto_bulkupdate'
uc_catalog_pathauto in uc_catalog/uc_catalog.pathauto.inc
Implements hook_pathauto().

File

uc_catalog/uc_catalog.pathauto.inc, line 33
Pathauto hooks.

Code

function uc_catalog_pathauto_bulkupdate(&$context) {
  if (!isset($context['sandbox']['current'])) {
    $context['sandbox']['count'] = 0;
    $context['sandbox']['current'] = 0;
  }
  $catalog_vid = variable_get('uc_catalog_vid', 0);
  $query = db_select('taxonomy_term_data', 'td');
  $query
    ->leftJoin('url_alias', 'ua', "CONCAT('catalog/', td.tid) = ua.source");
  $query
    ->addField('td', 'tid');
  $query
    ->isNull('ua.source');
  $query
    ->condition('vid', $catalog_vid);
  $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);
  $count = 0;
  $placeholders = array();
  foreach ($terms as $category) {
    $count = _uc_catalog_pathauto_alias($category, 'bulkupdate') + $count;
  }
  $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'];
  }
}