uc_catalog_pathauto_bulkupdate

  1. drupal
    1. 6 uc_catalog.module function
    2. 7 uc_catalog.pathauto.inc function
Drupal 7 uc_catalog_pathauto_bulkupdate(&$context)

Implements hook_pathauto_bulkupdate().

Generate aliases for all categories without aliases.

1 string reference to 'uc_catalog_pathauto_bulkupdate'

File

sites/all/modules/ubercart/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'];
  }
}