commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / redirect / redirect.drush.inc
1 <?php
2
3 /**
4 * @file
5 * Drush integration for the redirect module.
6 */
7
8 /**
9 * Implementation of hook_drush_command().
10 */
11 function redirect_drush_command() {
12 $items['generate-redirects'] = array(
13 'description' => 'Create redirects.',
14 'drupal dependencies' => array('devel_generate'),
15 'arguments' => array(
16 'count' => 'Number of redirects to generate.',
17 ),
18 'options' => array(
19 'delete' => 'Delete all redirects before generating new ones.',
20 ),
21 );
22
23 return $items;
24 }
25
26 /**
27 * Command callback. Generate a number of redirects.
28 */
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.'));
32 }
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'));
36 }
37
38 /**
39 * Perform an unprogressive batch process for CLI.
40 */
41 function redirect_run_unprogressive_batch() {
42 $batch = batch_get();
43 if (!empty($batch)) {
44 // If there is already something in the batch, don't run.
45 return FALSE;
46 }
47
48 $args = func_get_args();
49 $batch_callback = array_shift($args);
50
51 if (!lock_acquire($batch_callback)) {
52 return FALSE;
53 }
54
55 // Attempt to increase the execution time.
56 drupal_set_time_limit(240);
57
58 // Build the batch array.
59 $batch = call_user_func_array($batch_callback, $args);
60 batch_set($batch);
61
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;
66
67 // Run the batch process.
68 batch_process();
69
70 lock_release($batch_callback);
71 return TRUE;
72 }