Yaffs site version 1.1
[yaffs-website] / vendor / drush / drush / commands / core / state.drush.inc
1 <?php
2
3 /**
4  * @file
5  *   Provides State commands.
6  */
7
8 /**
9  * Implementation of hook_drush_help().
10  */
11 function state_drush_help($section) {
12   switch ($section) {
13     case 'meta:state:title':
14       return dt('State commands');
15     case 'meta:state:summary':
16       return dt('Interact with the State system.');
17   }
18 }
19
20 /**
21  * Implementation of hook_drush_command().
22  */
23 function state_drush_command() {
24   $items['state-get'] = array(
25     'description' => 'Display a state value.',
26     'arguments' => array(
27       'key' => 'The key name.',
28     ),
29     'required-arguments' => 1,
30     'examples' => array(
31       'drush state-get system.cron_last' => 'Displays last cron run timestamp',
32     ),
33     'outputformat' => array(
34       'default' => 'json',
35       'pipe-format' => 'json',
36     ),
37     'aliases' => array('sget'),
38     'core' => array('8+'),
39   );
40
41   $items['state-set'] = array(
42     'description' => 'Set a state value.',
43     'arguments' => array(
44       'key' => 'The state key, for example "system.cron_last".',
45       'value' => 'The value to assign to the state key. Use \'-\' to read from STDIN.',
46     ),
47     'required arguments' => 2,
48     'options' => array(
49       'format' => array(
50         'description' => 'Deprecated. See input-format option.',
51         'example-value' => 'boolean',
52         'value' => 'required',
53       ),
54       'input-format' => array(
55         'description' => 'Type for  the value. Use "auto" to detect format from value. Other recognized values are string, integer float, or boolean for corresponding primitive type, or json, yaml for complex types.',
56         'example-value' => 'boolean',
57         'value' => 'required',
58       ),
59       // A convenient way to pass a multiline value within a backend request.
60       'value' => array(
61         'description' => 'The value to assign to the state key (if any).',
62         'hidden' => TRUE,
63       ),
64     ),
65     'examples' => array(
66       'drush state-set system.cron_last 1406682882 --format=integer' => 'Sets a timestamp for last cron run.',
67       'php -r "print json_encode(array(\'drupal\', \'simpletest\'));"  | drush state-set --format=json foo.name -'=> 'Set a key to a complex value (e.g. array)',
68     ),
69     'aliases' => array('sset'),
70     'core' => array('8+'),
71   );
72
73   $items['state-delete'] = array(
74     'description' => 'Delete a state value.',
75     'arguments' => array(
76       'key' => 'The state key, for example "system.cron_last".',
77     ),
78     'required arguments' => 1,
79     'examples' => array(
80       'drush state-del system.cron_last' => 'Delete state entry for system.cron_last.',
81     ),
82     'aliases' => array('sdel'),
83     'core' => array('8+'),
84   );
85
86   return $items;
87 }
88
89 /**
90  * State get command callback.
91  *
92  * @state $key
93  *   The state key.
94  */
95 function drush_state_get($key = NULL) {
96   return \Drupal::state()->get($key);
97 }
98
99 /**
100  * State set command callback.
101  *
102  * @param $key
103  *   The config key.
104  * @param $value
105  *    The data to save to state.
106  */
107 function drush_state_set($key = NULL, $value = NULL) {
108   // This hidden option is a convenient way to pass a value without passing a key.
109   $value = drush_get_option('value', $value);
110
111   if (!isset($value)) {
112     return drush_set_error('DRUSH_STATE_ERROR', dt('No state value specified.'));
113   }
114
115   // Special flag indicating that the value has been passed via STDIN.
116   if ($value === '-') {
117     $value = stream_get_contents(STDIN);
118   }
119
120   // If the value is a string (usual case, unless we are called from code),
121   // then format the input.
122   if (is_string($value)) {
123     $value = drush_value_format($value, drush_get_option('format', 'auto'));
124   }
125
126   \Drupal::state()->set($key, $value);
127 }
128
129 /**
130  * State delete command callback.
131  *
132  * @state $key
133  *   The state key.
134  */
135 function drush_state_delete($key = NULL) {
136   \Drupal::state()->delete($key);
137 }