5 * Drush integration for the redirect module.
9 * Implements hook_drush_command().
11 function redirect_drush_command() {
12 $items['generate-redirects'] = array(
13 'description' => 'Create redirects.',
14 'drupal dependencies' => array('devel_generate'),
16 'count' => 'Number of redirects to generate.',
19 'delete' => 'Delete all redirects before generating new ones.',
27 * Command callback. Generate a number of redirects.
29 function drush_redirect_generate_redirects($count = NULL) {
30 if (drush_generate_is_number($count) == FALSE) {
31 return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid number of redirects.'));
33 module_load_include('inc', 'redirect', 'redirect.generate');
34 drush_generate_include_devel();
35 redirect_run_unprogressive_batch('redirect_generate_redirects_batch_info', $count, drush_get_option('delete'));
39 * Perform an unprogressive batch process for CLI.
41 function redirect_run_unprogressive_batch() {
44 // If there is already something in the batch, don't run.
48 $args = func_get_args();
49 $batch_callback = array_shift($args);
51 if (!lock_acquire($batch_callback)) {
55 // Attempt to increase the execution time.
56 drupal_set_time_limit(240);
58 // Build the batch array.
59 $batch = call_user_func_array($batch_callback, $args);
62 // We need to manually set the progressive variable again.
63 // @todo Remove when http://drupal.org/node/638712 is fixed.
64 $batch =& batch_get();
65 $batch['progressive'] = FALSE;
67 // Run the batch process.
70 lock_release($batch_callback);