1 |
85ad3d82
|
Assos Assos
|
<?php
|
2 |
|
|
/**
|
3 |
|
|
* @file
|
4 |
|
|
* Drush commands for Variable Realm.
|
5 |
|
|
*/
|
6 |
|
|
|
7 |
|
|
/**
|
8 |
|
|
* Implements hook_drush_command().
|
9 |
|
|
*/
|
10 |
|
|
function variable_realm_drush_command() {
|
11 |
|
|
$items['variable-realm-get'] = array(
|
12 |
|
|
'description' => 'Get a variable for a specific realm and key.',
|
13 |
|
|
'examples' => array(
|
14 |
|
|
'drush variable-realm-get language es site_frontpage',
|
15 |
|
|
'drush variable-realm-get language es',
|
16 |
|
|
),
|
17 |
|
|
'arguments' => array(
|
18 |
|
|
'domain_name' => 'The realm name for the variable.',
|
19 |
|
|
'domain_key' => 'The domain key for the variable.',
|
20 |
|
|
'variable_name' => 'Optional variable name variable to get. If not present list all variables for that realm and key.',
|
21 |
|
|
),
|
22 |
|
|
);
|
23 |
|
|
$items['variable-realm-set'] = array(
|
24 |
|
|
'description' => 'Set a variable for a specific realm and key.',
|
25 |
|
|
'examples' => array(
|
26 |
|
|
'drush variable-realm-set language es site_frontpage /home ',
|
27 |
|
|
),
|
28 |
|
|
'arguments' => array(
|
29 |
|
|
'domain_name' => 'The realm name for the variable.',
|
30 |
|
|
'domain_key' => 'The domain key for the variable.',
|
31 |
|
|
'variable_name' => 'The name variable to set (e.g. site_frontpage).',
|
32 |
|
|
'value' => 'The value to set for this variable.'
|
33 |
|
|
),
|
34 |
|
|
);
|
35 |
|
|
$items['variable-realm-del'] = array(
|
36 |
|
|
'description' => 'Delete a variable for a specific realm and key.',
|
37 |
|
|
'examples' => array(
|
38 |
|
|
'drush variable-realm-del language es site_frontpage',
|
39 |
|
|
),
|
40 |
|
|
'arguments' => array(
|
41 |
|
|
'domain_name' => 'The realm name for the variable.',
|
42 |
|
|
'domain_key' => 'The domain key for the variable.',
|
43 |
|
|
'variable_name' => 'The name variable to set (e.g. site_frontpage).',
|
44 |
|
|
),
|
45 |
|
|
);
|
46 |
|
|
return $items;
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
/**
|
50 |
|
|
* Implements hook_drush_help().
|
51 |
|
|
*/
|
52 |
|
|
function variable_realm_drush_help($section) {
|
53 |
|
|
$items = variable_realm_drush_command();
|
54 |
|
|
$name = str_replace('domain:', '', $section);
|
55 |
|
|
if (isset($items[$name])) {
|
56 |
|
|
return dt($items[$name]['description']);
|
57 |
|
|
}
|
58 |
|
|
}
|
59 |
|
|
|
60 |
|
|
/**
|
61 |
|
|
* Drush command callback.
|
62 |
|
|
* Set realm's variables.
|
63 |
|
|
*/
|
64 |
|
|
function drush_variable_realm_set($realm_name, $realm_key, $variable_name, $value) {
|
65 |
|
|
variable_realm_set($realm_name, $realm_key, $variable_name, $value);
|
66 |
|
|
drush_print('Variable set.');
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
/**
|
70 |
|
|
* Drush command callback.
|
71 |
|
|
* Validate parameters
|
72 |
|
|
*/
|
73 |
|
|
function drush_variable_realm_set_validate($realm_name = NULL, $realm_key = NULL, $variable_name = NULL, $value = NULL) {
|
74 |
|
|
if (is_null($realm_name) | is_null($realm_key) || is_null($variable_name) || is_null($value)) {
|
75 |
|
|
return drush_set_error('variable_realm', dt('Please enter all four required arguments, "dc-set realm_name realm_key variable_name value".'));
|
76 |
|
|
}
|
77 |
|
|
}
|
78 |
|
|
|
79 |
|
|
/**
|
80 |
|
|
* Drush command callback.
|
81 |
|
|
* Delete realm's variables.
|
82 |
|
|
*/
|
83 |
|
|
function drush_variable_realm_del($realm_name, $realm_key, $variable_name) {
|
84 |
|
|
variable_realm_del($realm_name, $realm_key, $variable_name);
|
85 |
|
|
drush_print('Variable deleted.');
|
86 |
|
|
}
|
87 |
|
|
|
88 |
|
|
/**
|
89 |
|
|
* Drush command callback.
|
90 |
|
|
* List realm's variables.
|
91 |
|
|
*/
|
92 |
|
|
function drush_variable_realm_get($realm_name, $realm_key, $variable_name) {
|
93 |
|
|
if ($variable_name) {
|
94 |
|
|
$variables[$variable_name] = variable_realm_get($realm_name, $realm_key, $variable_name);
|
95 |
|
|
}
|
96 |
|
|
else {
|
97 |
|
|
$variables = variable_realm($realm_name, $realm_key)->variable_list();
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
foreach ($variables as $name => $value) {
|
101 |
|
|
drush_print_pipe(drush_format($value, $name, 'export'));
|
102 |
|
|
drush_print(drush_format($value, $name));
|
103 |
|
|
$returns[$name] = $value;
|
104 |
|
|
}
|
105 |
|
|
|
106 |
|
|
if (empty($variables)) {
|
107 |
|
|
return drush_set_error('No matching variable found.');
|
108 |
|
|
}
|
109 |
|
|
else {
|
110 |
|
|
return $returns;
|
111 |
|
|
}
|
112 |
|
|
} |