Index: pathauto_node.inc
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/pathauto/pathauto_node.inc,v
retrieving revision 1.47.2.1
diff -u -F^function -r1.47.2.1 pathauto_node.inc
--- pathauto_node.inc	5 Aug 2008 17:28:13 -0000	1.47.2.1
+++ pathauto_node.inc	29 Jan 2009 17:44:03 -0000
@@ -95,30 +95,64 @@ function node_pathauto_bulkupdate() {
     }
   }
 
-  $count = 0;
   if (count($pattern_types)) {
-    $query = "SELECT n.nid, n.vid, n.type, n.title, n.uid, n.created, n.language, alias.src, alias.dst FROM {node} n LEFT JOIN {url_alias} alias ON CONCAT('node/', CAST(n.nid AS CHAR)) = alias.src WHERE alias.src IS NULL AND n.type IN (". db_placeholders($pattern_types, 'varchar') .')';
-    $result = db_query_range($query, $pattern_types, 0, variable_get('pathauto_max_bulk_update', 50));
+    $batch = _node_pathauto_batch_build($pattern_types, variable_get('pathauto_max_bulk_update', 50));
+    batch_set($batch);
+  }
+}
+
+/**
+ * Build a batch of nodes to bulk update.
+ */
+function _node_pathauto_batch_build($pattern_types, $max_bulk_update) {
+  $query = "SELECT n.nid, n.vid, n.type, n.title, n.uid, n.created, n.language, alias.src, alias.dst FROM {node} n LEFT JOIN {url_alias} alias ON CONCAT('node/', CAST(n.nid AS CHAR)) = alias.src WHERE alias.src IS NULL AND n.type IN (". db_placeholders($pattern_types, 'varchar') .')';
+  $result = db_query_range($query, $pattern_types, 0, $max_bulk_update);
+
+  $operations = array();
+  while ($node_ref = db_fetch_object($result)) {
+    $operations[] = array('_node_pathauto_batch_process', array($node_ref, $max_bulk_update));
+  }
+  $batch = array(
+    'operations' => $operations,
+    'finished' => '_node_pathauto_batch_finished',
+    'title' => t('Processing bulk generation of node aliases.'),
+    'init_message' => t('Starting bulk generation of node aliases.'),
+    'error_message' => t('An error was encountered during the bulk generation of node aliases.'),
+    'file' => drupal_get_path('module', 'pathauto') .'/pathauto_node.inc',
+  );
+  return $batch;
+}
 
-    $placeholders = array();
-    while ($node_ref = db_fetch_object($result)) {
-      $node = node_load($node_ref->nid, NULL, TRUE);
-      $node->src = $node_ref->src;
-      $node->dst = $node_ref->dst;
-      if (module_exists('taxonomy')) {
-        // Must populate the terms for the node here for the category
-        // placeholders to work
-        $node->taxonomy = array_keys(taxonomy_node_get_terms($node));
-      }
-      $placeholders = pathauto_get_placeholders('node', $node);
-      $src = "node/$node->nid";
-      if (pathauto_create_alias('node', 'bulkupdate', $placeholders, $src, $node->nid, $node->type, $node->language)) {
-        $count++;
-      }
-    }
+/**
+ * Callback for batch node bulk update.
+ */
+function _node_pathauto_batch_process($node_ref, $max, &$context) {
+  // Process a node.
+  $node = node_load($node_ref->nid, NULL, TRUE);
+  $node->src = $node_ref->src;
+  $node->dst = $node_ref->dst;
+  if (module_exists('taxonomy')) {
+    // Must populate the terms for the node here for the category
+    // placeholders to work.
+    $node->taxonomy = array_keys(taxonomy_node_get_terms($node));
+  }
+  $placeholders = pathauto_get_placeholders('node', $node);
+  $src = "node/$node->nid";
+  if (pathauto_create_alias('node', 'bulkupdate', $placeholders, $src, $node->nid, $node->type, $node->language)) {
+    // Store result for use in the finished callback.
+    $context['results'][] = l($node->title, 'node/'. $node->nid);
   }
+}
 
-  drupal_set_message(format_plural($count,
-    'Bulk generation of nodes completed, one alias generated.',
-    'Bulk generation of nodes completed, @count aliases generated.'));
+/**
+ * Callback for finished batch node bulk update.
+ */
+function _node_pathauto_batch_finished($success, $results, $operations) {
+  if ($success) {
+    $message = t('The bulk generation of aliases has been performed.');
+  }
+  else {
+    $message = t('An error was encountered during the bulk generation of node aliases.');
+  }
+  drupal_set_message($message .' '. format_plural(count($results), '1 node successfully processed.', '@count nodes successfully processed.'));
 }
