diff --git "a/C:\\Temp\\Pat1FC.tmp.inc" "b/C:\\Temp\\pat1FB.tmp\\pathauto.drush-7.x-1..inc" index e69de29..741bbfe 100644 --- "a/C:\\Temp\\Pat1FC.tmp.inc" +++ "b/C:\\Temp\\pat1FB.tmp\\pathauto.drush-7.x-1..inc" @@ -0,0 +1,147 @@ + 'pathauto_drush_bulk_update', + // a short description of your command + 'description' => dt('Creates URL aliases for unaliased nodes using Batch API.'), + 'arguments' => array( + 'update_types' => dt('Comma delimited list of aliases to update (e.g. node, taxonomy_term, user). If no types are specified, all three types will be run.'), + ), + ); + $items['pathauto-delete-alias'] = array( + // the name of the function implementing your command. + 'callback' => 'pathauto_drush_delete_node_alias', + // a short description of your command + 'description' => dt('Delete all URL-aliases'), + 'arguments' => array( + 'update_types' => dt('Comma delimited list of aliases to delete (e.g. node, taxonomy_term, user). If no types are specified, all three types will be deleted.'), + ), + ); + return $items; +} + +/** + * Implementation of hook_drush_help(). + * + */ +function pathauto_drush_help($section) { + switch ($section) { + case 'drush:pathauto-bulk-updates': + return dt("Creates URL aliases for unaliased entity instance using Batch API.You can specify the type (node, taxonomy_term, user). If no types are specified, all three types will be run."); + break; + case 'drush:pathauto-delete-alias': + return dt("Delete URL aliases. You can specify the type (node, taxonomy_term, user). If no types are specified, all alias will be deleted."); + break; + } +} + +/** + * Command callback. Delete URL alias. + * + * @param $types + * List of pathauto alias types delimited by comma + * node/,taxonomy/term/,user/ + * shortcut : node, taxonomy_term, user + * or custom pathauto types like another/module/ + */ +function pathauto_drush_delete_node_alias($types = 'all') { + // Set $list to contain all three types if no arguments passed. + if ($types == 'all') { + db_delete('url_alias') + ->execute(); + return dt("URL aliases deleted for all types."); + } + // Otherwise create $list from passed arguments. + else { + $list = explode(',', $types); + } + foreach ($list as $key) { + $key = trim($key); + if ($key) { + // replace types if it match + if ($key == "node") { + $needle = "node/"; + } elseif ($key == "taxonomy_term") { + $needle = "taxonomy/term/"; + } elseif ($key == "user") { + $needle = "user/"; + } else { + // let the user pass what he want + // like "another_module/" + $needle = $key; + } + $objects = module_invoke_all('path_alias_types'); + if (array_key_exists($needle, $objects)) { + db_delete('url_alias') + ->condition('source', db_like($needle) . '%', 'LIKE') + ->execute(); + $msg .= dt("All of your %type path aliases have been deleted.", array('%type' => $key)) . "\n"; + } + } + } + return $msg . dt("Operation finished."); +} + +/** + * Command callback. Runs URL alias bulk creation + * using drush batch API. + * + * @param $types + * List of pathauto settings types delimited by comma + * node,taxonomy_term,user + */ +function pathauto_drush_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_term', 'user'); + } + // Otherwise create $list from passed arguments. + else { + $list = explode(',', $types); + } + foreach ($list as $type) { + $settings = $callbacks[trim($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 =& batch_get(); + $batch['progressive'] = FALSE; + + // Process the batch. + drush_backend_batch_process(); + + $msg = dt("URL aliases generated for !types types.", array("!types" => $types)); + drush_print("\n" . $msg . "\n"); +} \ No newline at end of file