Drupal 7: Bulk update taxonomy url aliases

Yesterday, we showed how to Bulk update node url aliases. Now we faced similar problems while generating bulk url aliases for taxonomy terms. For some reason the admin interface was not able to generate them. The screen just struct up.


define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
// menu_execute_active_handler();
set_time_limit(0);
error_reporting(E_ALL);
$tid = (int) variable_get("url_alias_last_tid",0);
$result = db_query("SELECT tid FROM taxonomy_term_data WHERE tid > $tid LIMIT 0,5000");
foreach ($result as $record) {
$rr = db_query("SELECT source FROM url_alias WHERE source='taxonomy/term/{$record->tid}'")->fetchField();
if($rr == "") {
$tids[] = $record->tid;
$last_tid = $record->tid;
}
}
try{
pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate');
variable_set("url_alias_last_tid",$last_tid);
} catch(Exception $e){
print_r($e);
}

This code will generate url aliases of taxonomy terms 5000 terms at time.

Hopefully this will save someones' time

Please write to us if you have any question.