From 9c1781936f421121d71d7e70232a5cd6e6c54a68 Mon Sep 17 00:00:00 2001
From: wonder95 <killshot91@gmail.com>
Date: Fri, 8 Jul 2011 18:07:15 -0700
Subject: [PATCH] Adding drush command to re-generate URL aliases using batch API.  Attempts to mimc code from pathauto_bulk_update_form_submit().

---
 pathauto.drush.inc |  116 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 116 insertions(+), 0 deletions(-)
 create mode 100644 pathauto.drush.inc

diff --git a/pathauto.drush.inc b/pathauto.drush.inc
new file mode 100644
index 0000000..e9edd7a
--- /dev/null
+++ b/pathauto.drush.inc
@@ -0,0 +1,116 @@
+<?php
+
+/**
+ * @file
+ *   drush integration for cnsnews.
+ */
+
+/**
+ * Implementation of hook_drush_command().
+ *
+ * In this hook, you specify which commands your
+ * drush module makes available, what it does and
+ * description.
+ *
+ * Notice how this structure closely resembles how
+ * you define menu hooks.
+ *
+ * @See drush_parse_command() for a list of recognized keys.
+ *
+ * @return
+ *   An associative array describing your command(s).
+ */
+function pathauto_drush_command() {
+  $items = array();
+  
+  $items['pathauto-bulk-update'] = array(
+    // the name of the function implementing your command.
+    'callback' => 'pathauto_bulk_update',
+    // a short description of your command
+    'description' => dt('Creates URL aliases for unaliased nodes using Batch API.'),
+    'arguments' => array(
+      'update_types' => 'Comma delimited list of aliases to update (e.g. node, taxonomy, user).  If no types are specified, all three types will be run.',
+    ),    
+    'aliases' => array('pabu'),
+  );
+ 
+  return $items;
+}
+
+/**
+ * Implementation of hook_drush_help().
+ *
+ * This function is called whenever a drush user calls
+ * 'drush help <name-of-your-command>'
+ *
+ * @param
+ *   A string with the help section (prepend with 'drush:')
+ *
+ * @return
+ *   A string with the help text for your command.
+ */
+function pathauto_drush_help($section) {
+  switch ($section) {
+    case 'drush:pathauto-bulk-updates':
+      return dt("Creates URL aliases for unaliased nodes using Batch API."); 
+  }
+}
+
+/**
+ * Command callback. Runs URL alias bulk creation using batch API.
+ * Modification of pathauto_bulk_update_form_submit().
+ */
+function pathauto_bulk_update($types = 'all') {
+  $batch = array(
+    'title' => t('Bulk updating URL aliases'),
+    'operations' => array(
+      array('pathauto_bulk_update_batch_start', array()),
+    ),
+    'finished' => 'pathauto_bulk_update_batch_finished',
+    'file' => drupal_get_path('module', 'pathauto') . '/pathauto.admin.inc',
+  );
+    
+  // Get pathauto settings for each callback type.
+  $pathauto_settings = module_invoke_all('pathauto', 'settings');
+  foreach ($pathauto_settings as $settings) {
+    $callbacks[$settings->module] = $settings;  
+  }  
+    
+  // Set $list to contain all three types if no arguments passed.
+  if ($types == 'all') {
+    $list = array('node', 'taxonomy', 'user');
+  }
+  // Otherwise create $list from passed arguments.
+  else {
+    $list = explode(',', $types);
+  }
+  
+  foreach ($list as $type) {
+    $settings = $callbacks[$type];
+    if (!empty($settings->batch_file)) {
+      $batch['operations'][] = array('pathauto_bulk_update_batch_process', array($settings->batch_update_callback, $settings));
+    }
+    else {
+      $batch['operations'][] = array($settings->batch_update_callback, array());
+    }
+  }
+
+  batch_set($batch);
+  
+  batch_process();
+  
+  $msg = dt("URL aliases generated for !types types.", array("!types" => $types));
+  drush_print("\n" . $msg . "\n");  
+}
\ No newline at end of file
-- 
1.7.4.1

