diff --git a/pathauto.drush.inc b/pathauto.drush.inc new file mode 100644 index 0000000..6946ef1 --- /dev/null +++ b/pathauto.drush.inc @@ -0,0 +1,67 @@ + DRUSH_BOOTSTRAP_MAX, + 'drupal_dependencies' => array('pathauto'), + 'description' => 'Generate aliases for all unaliased entities of a specific type, or all possible entities.', + 'arguments' => array( + 'type' => 'The particular entity type to process. Omit this argument to choose from available entity types.', + ), + 'callback' => 'drush_pathauto_aliases_generate', + 'aliases' => array('pag'), + ); + + return $items; +} + +/** + * Command callback for drush pathauto-aliases-generate. + */ +function drush_pathauto_aliases_generate($type = NULL) { + $types = array(); + $form['#update_callbacks'] = array(); + foreach (module_invoke_all('pathauto', 'settings') as $settings) { + if (!empty($settings->batch_update_callback)) { + $form['#update_callbacks'][$settings->batch_update_callback] = $settings; + $types[$settings->module] = $settings->batch_update_callback; + } + } + + // Check if the provided type ($type) is a valid bulk generate type. + if ($type) { + if ($type != 'all' && !isset($types[$type])) { + return drush_set_error(dt("'!type' entity type is not a valid entity type for bulk generation", array('!type' => $type))); + } + } + else { + $type = drush_choice(array('all' => 'all') + $types, 'Enter a number to choose which entity types to bulk generate aliases.', '!key'); + } + + if ($type !== FALSE) { + // Set up the batch using the bulk generate form submission handler. + module_load_include('inc', 'pathauto', 'pathauto.admin'); + $form_state = array(); + if ($type == 'all') { + $form_state['values']['update'] = $types; + } + else { + $form_state['values']['update'][] = $types[$type]; + } + pathauto_bulk_update_form_submit($form, $form_state); + + $batch =& batch_get(); + $batch['progressive'] = FALSE; + + // Process the batch. + drush_backend_batch_process(); + } +}