How to programmatically bulk alias node urls by using only drupal 7 core (with it's great batch API !)?
My question is actually how to make drupal use and recognise the aliases stored in url_alias table?
The project I work on has more than 200,000 nodes (Drupal 7) and aliasing the system default url of all those nodes would literally take years with pathauto module (10 aliases every 20 minutes). I tried everything to improve those performances but failed (tried different servers, different mysql optimisations, different patterns).
I have already the batch process functions up and ready, they alias 200,000 nodes in 20 minutes, they create clean aliases stored in table "url_alias". I took lots of time looking at pathauto code, but couldn't find or understand how the module was giving drupal the order to recognize the bulk updated paths.
Thank you for your hints, answers or ideas..much appreciated!
Here is function that will update aliases for all nodes of specified type
<?php
module_load_include('inc', 'pathauto');
module_load_include('inc', 'pathauto.pathauto');
// Get all nodes that need to be updated
$query = db_select('node', 'n');
$query->addField('n', 'nid');
$query->condition('n.type', array('TYPE1', 'TYPE2'), 'IN');
$nids = $query->execute()->fetchCol();
// Save current action for new aliases and change it to delete old one.
$alias_action = variable_get('pathauto_update_action', 0);
variable_set('pathauto_update_action', PATHAUTO_UPDATE_ACTION_DELETE);
pathauto_node_update_alias_multiple($nids, 'bulkupdate');
// Restore original action for new aliases.
variable_set('pathauto_update_action', $alias_action);
?>