Révision 950416da
Ajouté par Assos Assos il y a plus de 5 ans
drupal7/sites/all/modules/rules/rules.drush.inc | ||
---|---|---|
7 | 7 |
|
8 | 8 |
/** |
9 | 9 |
* Implements hook_drush_command(). |
10 |
* |
|
11 |
* @return |
|
12 |
* An associative array describing your command(s). |
|
13 |
* |
|
14 |
* @see drush_parse_command() |
|
15 | 10 |
*/ |
16 | 11 |
function rules_drush_command() { |
17 | 12 |
$items = array(); |
18 | 13 |
|
19 | 14 |
$items['rules-list'] = array( |
20 |
'description' => "List all the active and inactive rules for your site.",
|
|
15 |
'description' => 'List all the active and inactive rules for your site.',
|
|
21 | 16 |
'drupal dependencies' => array('rules'), |
22 | 17 |
'aliases' => array('rules'), |
18 |
'outputformat' => array( |
|
19 |
'default' => 'table', |
|
20 |
'pipe-format' => 'list', |
|
21 |
'field-labels' => array( |
|
22 |
'rule' => dt('Rule'), |
|
23 |
'label' => dt('Label'), |
|
24 |
'event' => dt('Event'), |
|
25 |
'active' => dt('Active'), |
|
26 |
'status' => dt('Status'), |
|
27 |
), |
|
28 |
'output-data-type' => 'format-table', |
|
29 |
), |
|
23 | 30 |
); |
24 | 31 |
$items['rules-enable'] = array( |
25 |
'description' => "Enable a rule on your site.",
|
|
32 |
'description' => 'Enable a rule on your site.',
|
|
26 | 33 |
'arguments' => array( |
27 | 34 |
'rule' => 'Rule name to enable.', |
28 | 35 |
), |
... | ... | |
30 | 37 |
'aliases' => array('re'), |
31 | 38 |
); |
32 | 39 |
$items['rules-disable'] = array( |
33 |
'description' => "Disable a rule on your site.",
|
|
40 |
'description' => 'Disable a rule on your site.',
|
|
34 | 41 |
'arguments' => array( |
35 | 42 |
'rule' => 'Rule name to export.', |
36 | 43 |
), |
37 | 44 |
'drupal dependencies' => array('rules'), |
38 | 45 |
'aliases' => array('rd'), |
39 | 46 |
); |
47 |
$items['rules-revert'] = array( |
|
48 |
'description' => 'Revert a rule to its original state on your site.', |
|
49 |
'arguments' => array( |
|
50 |
'rule' => 'Rule name to revert.', |
|
51 |
), |
|
52 |
'drupal dependencies' => array('rules'), |
|
53 |
); |
|
54 |
$items['rules-delete'] = array( |
|
55 |
'description' => 'Delete a rule on your site.', |
|
56 |
'arguments' => array( |
|
57 |
'rule' => 'Rules name to delete.', |
|
58 |
), |
|
59 |
'drupal dependencies' => array('rules'), |
|
60 |
); |
|
61 |
$items['rules-export'] = array( |
|
62 |
'description' => 'Export a rule.', |
|
63 |
'arguments' => array( |
|
64 |
'rule' => 'Rules name to export.', |
|
65 |
), |
|
66 |
'drupal dependencies' => array('rules'), |
|
67 |
); |
|
40 | 68 |
|
41 | 69 |
return $items; |
42 | 70 |
} |
... | ... | |
46 | 74 |
*/ |
47 | 75 |
function rules_drush_help($section) { |
48 | 76 |
switch ($section) { |
49 |
case 'drush:rules': |
|
50 |
return dt("List all the rules on your site."); |
|
77 |
case 'drush:rules-list': |
|
78 |
return dt('List all the rules on your site.'); |
|
79 |
|
|
51 | 80 |
case 'drush:rules-enable': |
52 |
return dt("Enable/activate a rule on your site."); |
|
81 |
return dt('Enable/activate a rule on your site.'); |
|
82 |
|
|
53 | 83 |
case 'drush:rules-disable': |
54 |
return dt("Disable/deactivate a rule on your site."); |
|
84 |
return dt('Disable/deactivate a rule on your site.'); |
|
85 |
|
|
86 |
case 'drush:rules-revert': |
|
87 |
return dt('Revert a module-provided rule to its original state on your site.'); |
|
88 |
|
|
89 |
case 'drush:rules-delete': |
|
90 |
return dt('Delete a rule on your site.'); |
|
91 |
|
|
92 |
case 'drush:rules-export': |
|
93 |
return dt('Export a rule.'); |
|
55 | 94 |
} |
56 | 95 |
} |
57 | 96 |
|
... | ... | |
60 | 99 |
*/ |
61 | 100 |
function drush_rules_list() { |
62 | 101 |
$rules = rules_config_load_multiple(FALSE); |
63 |
$rows = array(array(dt('Rule'), dt('Label'), dt('Event'), dt('Active'), dt('Status')));
|
|
102 |
$rows = array(); |
|
64 | 103 |
foreach ($rules as $rule) { |
65 | 104 |
if (!empty($rule->name) && !empty($rule->label)) { |
66 | 105 |
$events = array(); |
67 | 106 |
$event_info = rules_fetch_data('event_info'); |
68 | 107 |
if ($rule instanceof RulesTriggerableInterface) { |
69 | 108 |
foreach ($rule->events() as $event_name) { |
70 |
$event_info += array($event_name => array('label' => dt('Unknown event "!event_name"', array('!event_name' => $event_name)))); |
|
109 |
$event_info += array( |
|
110 |
$event_name => array( |
|
111 |
'label' => dt('Unknown event "!event_name"', array('!event_name' => $event_name)), |
|
112 |
), |
|
113 |
); |
|
71 | 114 |
$events[] = check_plain($event_info[$event_name]['label']); |
72 | 115 |
} |
73 | 116 |
} |
74 |
$rows[] = array( |
|
75 |
$rule->name, |
|
76 |
$rule->label, |
|
77 |
implode(', ', $events), |
|
78 |
$rule->active ? dt('Enabled') : dt('Disabled'), |
|
79 |
$rule->status ? theme('entity_status', array('status' => $rule->status, 'html' => FALSE)) : '', |
|
117 |
$rows[$rule->name] = array(
|
|
118 |
'rule' => $rule->name,
|
|
119 |
'label' => $rule->label,
|
|
120 |
'event' => implode(', ', $events),
|
|
121 |
'active' => $rule->active ? dt('Enabled') : dt('Disabled'),
|
|
122 |
'status' => $rule->status ? theme('entity_status', array('status' => $rule->status, 'html' => FALSE)) : '',
|
|
80 | 123 |
); |
81 | 124 |
} |
82 | 125 |
} |
83 |
drush_print_table($rows, TRUE); |
|
126 |
if (version_compare(DRUSH_VERSION, '6.0', '<')) { |
|
127 |
drush_print_table($rows, TRUE); |
|
128 |
} |
|
129 |
return $rows; |
|
84 | 130 |
} |
85 | 131 |
|
86 | 132 |
/** |
... | ... | |
132 | 178 |
drush_log(dt('The rule "!name" is already disabled.', array('!name' => $rule_name)), 'warning'); |
133 | 179 |
} |
134 | 180 |
} |
181 |
|
|
182 |
/** |
|
183 |
* Reverts a rule on the site. |
|
184 |
*/ |
|
185 |
function drush_rules_revert() { |
|
186 |
$args = func_get_args(); |
|
187 |
$rule_name = (!empty($args) && is_array($args)) ? array_shift($args) : ''; |
|
188 |
if (empty($rule_name)) { |
|
189 |
return drush_set_error('', 'No rule name given.'); |
|
190 |
} |
|
191 |
|
|
192 |
$rule = rules_config_load($rule_name); |
|
193 |
if (empty($rule)) { |
|
194 |
return drush_set_error('', dt('Could not load rule named "!rule-name".', array('!rule-name' => $rule_name))); |
|
195 |
} |
|
196 |
|
|
197 |
if (($rule->status & ENTITY_OVERRIDDEN) == ENTITY_OVERRIDDEN) { |
|
198 |
if (drush_confirm(dt('Are you sure you want to revert the rule named "!rule-name"? This action cannot be undone.', array('!rule-name' => $rule_name)))) { |
|
199 |
$rule->delete(); |
|
200 |
drush_log(dt('The rule "!name" has been reverted to its default state.', array('!name' => $rule_name)), 'success'); |
|
201 |
} |
|
202 |
else { |
|
203 |
drush_user_abort(); |
|
204 |
} |
|
205 |
} |
|
206 |
else { |
|
207 |
drush_log(dt('The rule "!name" has not been overridden and can\'t be reverted.', array('!name' => $rule_name)), 'warning'); |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* Deletes a rule on the site. |
|
213 |
*/ |
|
214 |
function drush_rules_delete() { |
|
215 |
$args = func_get_args(); |
|
216 |
$rule_name = (!empty($args) && is_array($args)) ? array_shift($args) : ''; |
|
217 |
if (empty($rule_name)) { |
|
218 |
return drush_set_error('', 'No rule name given.'); |
|
219 |
} |
|
220 |
|
|
221 |
$rule = rules_config_load($rule_name); |
|
222 |
if (empty($rule)) { |
|
223 |
return drush_set_error('', dt('Could not load rule named "!rule-name".', array('!rule-name' => $rule_name))); |
|
224 |
} |
|
225 |
|
|
226 |
if (drush_confirm(dt('Are you sure you want to delete the rule named "!rule-name"? This action cannot be undone.', array('!rule-name' => $rule_name)))) { |
|
227 |
$rule->delete(); |
|
228 |
drush_log(dt('The rule "!name" has been deleted.', array('!name' => $rule_name)), 'success'); |
|
229 |
} |
|
230 |
else { |
|
231 |
drush_user_abort(); |
|
232 |
} |
|
233 |
} |
|
234 |
|
|
235 |
/** |
|
236 |
* Exports a single rule. |
|
237 |
*/ |
|
238 |
function drush_rules_export() { |
|
239 |
$args = func_get_args(); |
|
240 |
$rule_name = (!empty($args) && is_array($args)) ? array_shift($args) : ''; |
|
241 |
if (empty($rule_name)) { |
|
242 |
return drush_set_error('', dt('No rule name given.')); |
|
243 |
} |
|
244 |
|
|
245 |
$rule = rules_config_load($rule_name); |
|
246 |
if (empty($rule)) { |
|
247 |
return drush_set_error('', dt('Could not load rule named "!rule-name".', array('!rule-name' => $rule_name))); |
|
248 |
} |
|
249 |
|
|
250 |
drush_print($rule->export()); |
|
251 |
drush_log(dt('The rule "!name" has been exported.', array('!name' => $rule_name)), 'success'); |
|
252 |
} |
Formats disponibles : Unified diff
Weekly update of contrib modules