1 | <?php |
||
13 | class DrushDriver extends BaseDriver { |
||
14 | /** |
||
15 | * Store a drush alias for tests requiring shell access. |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | public $alias; |
||
20 | |||
21 | /** |
||
22 | * Stores the root path to a Drupal installation. |
||
23 | * |
||
24 | * This is an alternative to using drush aliases. |
||
25 | * |
||
26 | * @var string |
||
27 | */ |
||
28 | public $root; |
||
29 | |||
30 | /** |
||
31 | * Store the path to drush binary. |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | public $binary; |
||
36 | |||
37 | /** |
||
38 | * Track bootstrapping. |
||
39 | */ |
||
40 | private $bootstrapped = FALSE; |
||
41 | |||
42 | /** |
||
43 | * Random generator. |
||
44 | * |
||
45 | * @var \Drupal\Component\Utility\Random |
||
46 | */ |
||
47 | private $random; |
||
48 | |||
49 | /** |
||
50 | * Global arguments or options for drush commands. |
||
51 | * |
||
52 | * @var string |
||
53 | */ |
||
54 | private $arguments = ''; |
||
55 | |||
56 | /** |
||
57 | * Set drush alias or root path. |
||
58 | * |
||
59 | * @param string $alias |
||
60 | * A drush alias. |
||
61 | * @param string $root_path |
||
62 | * The root path of the Drupal install. This is an alternative to using |
||
63 | * aliases. |
||
64 | * @param string $binary |
||
65 | * The path to the drush binary. |
||
66 | * @param \Drupal\Component\Utility\Random $random |
||
67 | * Random generator. |
||
68 | * |
||
69 | * @throws \Drupal\Driver\Exception\BootstrapException |
||
70 | * Thrown when a required parameter is missing. |
||
71 | */ |
||
72 | public function __construct($alias = NULL, $root_path = NULL, $binary = 'drush', Random $random = NULL) { |
||
73 | if (!empty($alias)) { |
||
74 | // Trim off the '@' symbol if it has been added. |
||
75 | $alias = ltrim($alias, '@'); |
||
76 | |||
77 | $this->alias = $alias; |
||
78 | } |
||
79 | elseif (!empty($root_path)) { |
||
80 | $this->root = realpath($root_path); |
||
81 | } |
||
82 | else { |
||
83 | throw new BootstrapException('A drush alias or root path is required.'); |
||
84 | } |
||
85 | |||
86 | $this->binary = $binary; |
||
87 | |||
88 | if (!isset($random)) { |
||
89 | $random = new Random(); |
||
90 | } |
||
91 | $this->random = $random; |
||
92 | } |
||
93 | |||
94 | /** |
||
95 | * {@inheritdoc} |
||
96 | */ |
||
97 | public function getRandom() { |
||
98 | return $this->random; |
||
99 | } |
||
100 | |||
101 | /** |
||
102 | * {@inheritdoc} |
||
103 | */ |
||
104 | public function bootstrap() { |
||
105 | // Check that the given alias works. |
||
106 | // @todo check that this is a functioning alias. |
||
107 | // See http://drupal.org/node/1615450 |
||
108 | if (!isset($this->alias) && !isset($this->root)) { |
||
109 | throw new BootstrapException('A drush alias or root path is required.'); |
||
110 | } |
||
111 | $this->bootstrapped = TRUE; |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * {@inheritdoc} |
||
116 | */ |
||
117 | public function isBootstrapped() { |
||
118 | return $this->bootstrapped; |
||
119 | } |
||
120 | |||
121 | /** |
||
122 | * {@inheritdoc} |
||
123 | */ |
||
124 | public function userCreate(\stdClass $user) { |
||
139 | |||
140 | /** |
||
141 | * {@inheritdoc} |
||
142 | */ |
||
143 | public function userDelete(\stdClass $user) { |
||
151 | |||
152 | /** |
||
153 | * {@inheritdoc} |
||
154 | */ |
||
155 | public function userAddRole(\stdClass $user, $role) { |
||
156 | $arguments = array( |
||
157 | sprintf('"%s"', $role), |
||
158 | sprintf('"%s"', $user->name), |
||
159 | ); |
||
160 | $this->drush('user-add-role', $arguments); |
||
161 | } |
||
162 | |||
163 | /** |
||
164 | * {@inheritdoc} |
||
165 | */ |
||
166 | public function fetchWatchdog($count = 10, $type = NULL, $severity = NULL) { |
||
167 | $options = array( |
||
168 | 'count' => $count, |
||
169 | 'type' => $type, |
||
170 | 'severity' => $severity, |
||
171 | ); |
||
172 | return $this->drush('watchdog-show', array(), $options); |
||
173 | } |
||
174 | |||
175 | /** |
||
176 | * {@inheritdoc} |
||
177 | */ |
||
178 | public function clearCache($type = 'all') { |
||
179 | $type = array($type); |
||
180 | return $this->drush('cache-clear', $type, array()); |
||
181 | } |
||
182 | |||
183 | /** |
||
184 | * {@inheritdoc} |
||
185 | */ |
||
186 | public function clearStaticCaches() { |
||
190 | |||
191 | /** |
||
192 | * Decodes JSON output returned by Drush. |
||
193 | * |
||
194 | * It will clean up any junk that may have appeared before the JSON. |
||
195 | * |
||
196 | * @param string $output |
||
197 | * The output from Drush. |
||
198 | * @return object |
||
199 | * The decoded JSON object. |
||
200 | */ |
||
201 | protected function decodeJsonOutput($output) { |
||
206 | |||
207 | /** |
||
208 | * {@inheritdoc} |
||
209 | */ |
||
210 | public function createNode($node) { |
||
214 | |||
215 | /** |
||
216 | * {@inheritdoc} |
||
217 | */ |
||
218 | public function nodeDelete($node) { |
||
221 | |||
222 | /** |
||
223 | * {@inheritdoc} |
||
224 | */ |
||
225 | public function createTerm(\stdClass $term) { |
||
229 | |||
230 | /** |
||
231 | * {@inheritdoc} |
||
232 | */ |
||
233 | public function termDelete(\stdClass $term) { |
||
236 | |||
237 | /** |
||
238 | * {@inheritdoc} |
||
239 | */ |
||
240 | public function isField($entity_type, $field_name) { |
||
254 | |||
255 | /** |
||
256 | * Sets common drush arguments or options. |
||
257 | * |
||
258 | * @param string $arguments |
||
259 | * Global arguments to add to every drush command. |
||
260 | */ |
||
261 | public function setArguments($arguments) { |
||
264 | |||
265 | /** |
||
266 | * Get common drush arguments. |
||
267 | */ |
||
268 | public function getArguments() { |
||
271 | |||
272 | /** |
||
273 | * Parse arguments into a string. |
||
274 | * |
||
275 | * @param array $arguments |
||
276 | * An array of argument/option names to values. |
||
277 | * |
||
278 | * @return string |
||
279 | * The parsed arguments. |
||
280 | */ |
||
281 | protected static function parseArguments(array $arguments) { |
||
293 | |||
294 | /** |
||
295 | * Execute a drush command. |
||
296 | */ |
||
297 | public function drush($command, array $arguments = array(), array $options = array()) { |
||
328 | |||
329 | /** |
||
330 | * {@inheritdoc} |
||
331 | */ |
||
332 | public function processBatch() { |
||
336 | |||
337 | /** |
||
338 | * {@inheritdoc} |
||
339 | */ |
||
340 | public function runCron() { |
||
343 | |||
344 | /** |
||
345 | * Run Drush commands dynamically from a DrupalContext. |
||
346 | */ |
||
347 | public function __call($name, $arguments) { |
||
350 | |||
351 | } |
||
352 |