REGENERATING PATH ALIASES PROGRAMATICALLY IN DRUPAL 7

Public

Get raw version
php
  1. // Thanks to http://samhassell.com/regenerating-path-aliases-programatically-in-drupal-7/
  2. /**
  3. * Update path aliases for taxonomy terms and nodes.
  4. */
  5. function gateway_controller_update_7057() {
  6. module_load_include('inc', 'pathauto');
  7. module_load_include('inc', 'pathauto.pathauto');
  8.  
  9. // Delete the existing node aliases.
  10. db_delete('url_alias')
  11. ->condition('source', 'node/%', 'LIKE')
  12. ->execute();
  13.  
  14. // Regenerate the node aliases.
  15. $nids = db_query("SELECT nid FROM {node}")->fetchCol();
  16. pathauto_node_update_alias_multiple($nids, 'bulkupdate');
  17.  
  18. // Delete the topics taxonomy aliases.
  19. db_delete('url_alias')
  20. ->condition('source', 'taxonomy/term/%', 'LIKE')
  21. ->execute();
  22.  
  23. // Regenerate the taxonomy aliases.
  24. $tids = db_query("SELECT tid FROM {taxonomy_term_data} where vid = 8")->fetchCol();
  25. pathauto_taxonomy_term_update_alias_multiple($tids, 'bulkupdate');
  26. }