Bulk updating Pathauto node aliases - Manually, from cron, or command line
Pathauto supports bulk generation of aliases for nodes that are not aliased.
The number of unaliased nodes that will be updated is controlled by the Pathauto setting:
"Maximum number of objects to alias in a bulk update"
Drupal 5.x
Updating via the admin interface
As at Pathauto 5.x-2.0, the bulk update is currently a manual action done by:
- visiting the pathauto settings (/admin/settings/pathauto)
- ticking the checkbox under "Node Path Settings" for:
"Bulk generate aliases for nodes that are not aliased" - clicking "Save Configuration" button
- repeating as many times as required to generate all aliases
If you have a lot of nodes to update, this can be a very tedious button clicking process!
Creating a command line script to bulk update unaliased nodes
A faster way to update would be from a command line. To do so, I set up a cron-update-pathauto.php script which contains:
<?php
include_once './includes/bootstrap.inc';
include_once './sites/all/modules/contrib/pathauto/pathauto.inc';
include_once './sites/all/modules/contrib/pathauto/pathauto_node.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
node_pathauto_bulkupdate();
?>The include paths here assume you'll put this cron-update-pathauto.php file in your top level Drupal directory with appropriate permissions (eg `chmod 500 cron-update-pathauto.php` assuming the file is owned by your web server user).
Adding the unaliased node update to cron
To enable this to be called from cron I also setup a modified version of the cron script from http://drupal.org/node/65307 as cron-pathauto.sh:
#!/bin/bash
#############################
# CONFIGURATION OPTIONS
#############################
# Set the complete local path to where the cron.php file
# is (ie the root path) Default is /var/www/html/
root_path=/home/htdocs/drupal/
# Set the complete path to the php parser if
# different from standard
parse=/usr/bin/php
cronjob=cron-update-pathauto.php
##############################
# END OF CONFIGURATION OPTIONS
##############################
cd $root_path
if [ -e "$cronjob" ]
then
$parse $cronjob
if [ "$?" -ne "0" ]
then
echo "$cronjob not parsed."
else
echo "$cronjob has succesfully been parsed."
fi
else
echo "$cronjob not found."
exit
fi
exitFinally, added the actual cronjob to run this every 15 minutes:
crontab -e# minute hour mday month wday command
*/15 * * * * /home/htdocs/cron-pathauto.sh >/dev/null 2>&1Note that this cron job should not be left on a site permanently. It is only a one-time maintenance solution. If you leave this cron job enabled on a site you will have performance problems every time the script runs.
Drupal 6.x
Updating via the admin interface
- Visit the pathauto settings (/admin/build/path/pathauto)
- Tick the checkbox under "Node Path Settings" for:
"Bulk generate aliases for nodes that are not aliased" - Click "Save Configuration" button
- Repeat as many times as required to generate all aliases
Updating via the command line
This can be done with a PHP script as shown above. The syntax is similar to Drupal 5.x, except that the function _pathauto_include() must be called before node_pathauto_bulkupdate(). The easiest way to do this is to install Drush and then run this command:
drush eval '_pathauto_include() ; node_pathauto_bulkupdate()'
As shown above, this command could be included in a script called periodically via cron.

I've got a better
I've got a better idea:
<?phpfunction mymodule_cron() {
module_invoke_all('pathauto_bulkupdate');
}
?>
Is there a version of this for drupal 6?
That currently does not work, and i get missing cache.inc errors.
Multi-site setup
I wanted to use the script on a site of my own, but I have a multi-site setup, which means the settings are in a different place other than default and you need to trick the script so it can find the settings.php properly.
I took a little bit of coding from drush module, maybe this script should be added as a drush pathauto module?
Anyway:
<?php
include_once './includes/bootstrap.inc';
include_once './sites/all/modules/pathauto/pathauto.inc';
include_once './sites/all/modules/pathauto/pathauto_node.inc';
// The URL how you would normaly access your drupal site with a browser
$url = 'http://www.example.com';
$drupal_base_url = parse_url($url);
$_SERVER['HTTP_HOST'] = $drupal_base_url['host'];
$_SERVER['PHP_SELF'] = $drupal_base_url['path'].'/index.php';
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'] = $_SERVER['PHP_SELF'];
$_SERVER['REMOTE_ADDR'] = NULL;
$_SERVER['REQUEST_METHOD'] = NULL;
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
node_pathauto_bulkupdate();
?>
Thank you!
Great piece of code, just what I was looking for. Thank you!
Doesn't work in D6
The PHP script returns immediately. Nothing happens.
Does anyone know, how does that function "node_pathauto_bulkupdate()" run without any arguments? Does it pull the number from General Settings or does it just run limitless?
Anyway, there has to be a better way (in D6 at least) of bulk updating aliases across sites.
Bulk generate path aliases for large sites
Hi,
has anyone managed to fix this script for D6? (also still pending as a support request in #505042: Bulk generate path aliases for large sites)
Thanks & greetings, -asb
Drupal playgrounds: www.kefk.org | www.cinedat.org | www.fotonexus.org | www.encycan.de | www.encymus.de
Bulk generate path aliases for Drupal 6
Hi asb,
The details on this page worked for me. I did adjust the path to pathauto for my installation.
<?php
include_once './includes/bootstrap.inc';
include_once './sites/default/modules/pathauto/pathauto.inc';
include_once './sites/default/modules/pathauto/pathauto_node.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
_pathauto_include();
node_pathauto_bulkupdate();
?>
I looped from my Mac which is missing some shell commands, so I used
for i in {1..250}; do echo $i; curl http://domain/script.php; done
to generate the paths. Doing this manually would have been painful.
I refreshed "Delete aliases" page to monitor the progress.
Thanks to all for the help above!
Best solution for Drupal 6
The best way to update pathauto aliases on Drupal 6 is to use the incredibly powerful Views Bulk Operations. Install it, then create a view of all of your nodes with style VBO. The key step is that VBO supports the Batch API, which allows Drupal to do thousands of tasks without timing out, and with a nice status page showing you its progress. Anyway, the pathauto option is near the bottom. You need to create separate views for terms and users as well.