You are here

function taxonomy_pathauto_bulkupdate in Pathauto 6

Same name and namespace in other branches
  1. 5.2 pathauto_taxonomy.inc \taxonomy_pathauto_bulkupdate()
  2. 5 pathauto_taxonomy.inc \taxonomy_pathauto_bulkupdate()

Generate aliases for all categories without aliases.

File

./pathauto_taxonomy.inc, line 55
Hook implementations for taxonomy module integration.

Code

function taxonomy_pathauto_bulkupdate() {

  // From all node types, only attempt to update those with patterns
  $pattern_vids = array();
  foreach (taxonomy_get_vocabularies() as $vid => $info) {

    // Exclude forum module's vocabulary.
    if ($vid == variable_get('forum_nav_vocabulary', '')) {
      continue;
    }
    $pattern = trim(variable_get('pathauto_taxonomy_' . $vid . '_pattern', ''));

    // If it's not set, check the default
    // TODO - If there's a default we shouldn't do this crazy where statement because all vocabs get aliases
    // TODO - Special casing to exclude the forum vid (and the images vid and...?)
    if (empty($pattern)) {
      $pattern = trim(variable_get('pathauto_taxonomy_pattern', ''));
    }
    if (!empty($pattern)) {
      $pattern_vids[] = $vid;
    }
  }
  $count = 0;
  if (!empty($pattern_vids)) {
    $concat = _pathauto_sql_concat("'taxonomy/term/'", 'td.tid');
    $sql = "SELECT td.tid FROM {term_data} td LEFT JOIN {url_alias} ua ON {$concat} = ua.src WHERE ua.src IS NULL AND td.vid IN (" . db_placeholders($pattern_vids, 'int') . ")";
    $query = db_query_range($sql, $pattern_vids, 0, variable_get('pathauto_max_bulk_update', 50));
    while ($tid = db_result($query)) {
      $term = taxonomy_get_term($tid);
      $count += _taxonomy_pathauto_alias($term, 'bulkupdate');
    }
  }
  drupal_set_message(format_plural($count, 'Bulk generation of terms completed, one alias generated.', 'Bulk generation of terms completed, @count aliases generated.'));
}