You are here

function taxonomy_menu_pathauto_bulkupdate in Taxonomy menu 5

Generate aliases for all categories

File

./taxonomy_menu_pathauto.inc, line 48

Code

function taxonomy_menu_pathauto_bulkupdate() {
  $count = 0;
  foreach (taxonomy_get_vocabularies() as $category) {

    // The Base Vocabulary path
    $path = variable_get('taxonomy_menu_display_page', 'category') . $category->vid;
    $tree = taxonomy_get_tree($category->vid);
    $old_depth = -1;
    $old_path = $path;
    foreach ($tree as $term) {

      // get the tokens and values for this term
      $placeholders = pathauto_get_placeholders('taxonomy_menu', $term);
      if ($term->depth <= $old_depth) {
        $slashes_to_remove = $old_depth - $term->depth + 1;
        for ($i = 0; $i < $slashes_to_remove; $i++) {
          $old_path = substr($old_path, 0, strrpos($old_path, '/'));
        }
      }
      $path = $old_path . '/' . $term->tid;
      $old_depth = $term->depth;
      $old_path = $path;
      if ($alias = pathauto_create_alias('taxonomy_menu', 'bulkupdate', $placeholders, $path, $term->tid, $category->vid)) {
        $count++;
      }
    }
    while ($category = db_fetch_object($result)) {
      $count += _taxonomy_pathauto_alias($category, 'bulkupdate');
    }
    drupal_set_message(format_plural($count, "Bulk generation of terms completed, one alias generated.", "Bulk generation of terms completed, @count aliases generated."));
  }
}