-
Notifications
You must be signed in to change notification settings - Fork 29
/
redirect.drush.inc
72 lines (60 loc) · 1.78 KB
/
redirect.drush.inc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<?php
/**
* @file
* Drush integration for the redirect module.
*/
/**
* Implements hook_drush_command().
*/
function redirect_drush_command() {
$items['generate-redirects'] = array(
'description' => 'Create redirects.',
'drupal dependencies' => array('devel_generate'),
'arguments' => array(
'count' => 'Number of redirects to generate.',
),
'options' => array(
'delete' => 'Delete all redirects before generating new ones.',
),
);
return $items;
}
/**
* Command callback. Generate a number of redirects.
*/
function drush_redirect_generate_redirects($count = NULL) {
if (drush_generate_is_number($count) == FALSE) {
return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', t('Invalid number of redirects.'));
}
module_load_include('inc', 'redirect', 'redirect.generate');
drush_generate_include_devel();
redirect_run_unprogressive_batch('redirect_generate_redirects_batch_info', $count, drush_get_option('delete'));
}
/**
* Perform an unprogressive batch process for CLI.
*/
function redirect_run_unprogressive_batch() {
$batch = batch_get();
if (!empty($batch)) {
// If there is already something in the batch, don't run.
return FALSE;
}
$args = func_get_args();
$batch_callback = array_shift($args);
if (!lock_acquire($batch_callback)) {
return FALSE;
}
// Attempt to increase the execution time.
drupal_set_time_limit(240);
// Build the batch array.
$batch = call_user_func_array($batch_callback, $args);
batch_set($batch);
// We need to manually set the progressive variable again.
// @todo Remove when http://drupal.org/node/638712 is fixed.
$batch =& batch_get();
$batch['progressive'] = FALSE;
// Run the batch process.
batch_process();
lock_release($batch_callback);
return TRUE;
}