Drush: includes/drush.inc Source File

  1. 7.x doxygen/html/drush_8inc_source.html
  2. master doxygen/html/drush_8inc_source.html
Go to the documentation of this file.
1 <?php
2 
3 /**
4  * @file
5  * The drush API implementation and helpers.
6  */
7 
8 /**
9 * @name Error status definitions
10 * @{
11 * Error code definitions for interpreting the current error status.
13 */
14 
15 /** The command completed successfully. */
16 define('DRUSH_SUCCESS', 0);
17 /** The command could not be completed because the framework has specified errors that have occured. */
18 define('DRUSH_FRAMEWORK_ERROR', 1);
19 /** The command that was executed resulted in an application error,
20  The most commom causes for this is invalid PHP or a broken SSH
21  pipe when using drush_backend_invoke in a distributed manner. */
22 define('DRUSH_APPLICATION_ERROR', 255);
23 
24 /**
25  * @} End of "name Error status defintions".
26  */
27 
28 /**
29  * The number of bytes in a kilobyte. Copied from Drupal.
30  */
31 define('DRUSH_KILOBYTE', 1024);
32 
33 /**
34  * Default amount of time, in seconds, to cache downloads via
35  * drush_download_file(). One day is 86400 seconds.
36  */
37 define('DRUSH_CACHE_LIFETIME_DEFAULT', 86400);
38 
39 /**
40  * Include a file, selecting a version specific file if available.
41  *
42  * For example, if you pass the path "/var/drush" and the name
43  * "update" when bootstrapped on a Drupal 6 site it will first check for
44  * the presence of "/var/drush/update_6.inc" in include it if exists. If this
45  * file does NOT exist it will proceed and check for "/var/drush/update.inc".
46  * If neither file exists, it will return FALSE.
47  *
48  * @param $path
49  * The path you want to search.
50  * @param $name
51  * The file base name you want to include (not including a version suffix
52  * or extension).
53  * @param $version
54  * The version suffix you want to include (could be specific to the software
55  * or platform your are connecting to) - defaults to the current Drupal core
56  * major version.
57  * @param $extension
58  * The extension - defaults to ".inc".
59  *
60  * @return
61  * TRUE if the file was found and included.
62  */
63 function drush_include($path, $name, $version = NULL, $extension = 'inc') {
64  $version = ($version) ? $version : drush_drupal_major_version();
65  $file = sprintf("%s/%s_%s.%s", $path, str_replace('-', '_', $name), $version, $extension);
66  if (file_exists($file)) {
67  //drush_log(dt('Including version specific file : @file', array('@file' => $file)));
68  include_once($file);
69  return TRUE;
70  }
71  $file = sprintf("%s/%s.%s", $path, str_replace('-', '_', $name), $extension);
72  if (file_exists($file)) {
73  //drush_log(dt('Including non-version specific file : @file', array('@file' => $file)));
74  include_once($file);
75  return TRUE;
76  }
77 }
78 
79 /**
80  * Provide a version-specific class instance.
81  *
82  * @param $class_name
83  * The name of the class to instantiate. Appends the Drupal
84  * major version number to the end of the class name before instantiation.
85  * @param $constructor_args
86  * An array of arguments to pass to the class constructor.
87  *
88  * Example wrapper class to instantiate a widget, called with the
89  * arguments for the WIDGET_CLASS constructor:
90  *
91  * function drush_WIDGET_CLASS_get_class($widgetName, $widgetStyle) {
92  * retrun drush_get_class('Widget_Class', func_get_args()));
93  * }
94  */
95 
96 function drush_get_class($class_name, $constructor_args = array(), $variations = array()) {
97  if (empty($variations)) {
98  $variations[] = drush_drupal_major_version();
99  }
100  for ($i=count($variations); $i > 0; $i--) {
101  $variant_class_name = $class_name . implode('', array_slice($variations, 0, $i));
102  if (class_exists($variant_class_name)) {
103  $reflectionClass = new ReflectionClass($variant_class_name);
104  return $reflectionClass->newInstanceArgs($constructor_args);
105  }
106  }
107  // Something bad happenned. Exception?
108  // drush_set_error('DRUSH_GET_CLASS_ERROR', dt('Unable to load class - %s', $class_name));
109 }
110 
111 /**
112  * Generate an .ini file. used by archive-dump."
113  *
114  * @param array $ini
115  * A two dimensional associative array where top level are sections and
116  * second level are key => value pairs.
117  *
118  * @return string
119  * .ini formatted text.
120  */
121 function drush_export_ini($ini) {
122  $output = '';
123  foreach ($ini as $section => $pairs) {
124  if ($section) {
125  $output .= "[$section]\n";
126  }
127 
128  foreach ($pairs as $k => $v) {
129  if ($v) {
130  $output .= "$k = \"$v\"\n";
131  }
132  }
133  }
134  return $output;
135 }
136 
137 /**
138  * Generate code friendly to the Drupal .info format from a structured array.
140  *
141  * @param $info
142  * An array or single value to put in a module's .info file.
143  *
144  * @param boolean $integer_keys
145  * Use integer in keys.
146  *
147  * @param $parents
148  * Array of parent keys (internal use only).
149  *
150  * @return
151  * A code string ready to be written to a module's .info file.
152  */
153 function drush_export_info($info, $integer_keys = FALSE, $parents = array()) {
154  $output = '';
155  if (is_array($info)) {
156  foreach ($info as $k => $v) {
157  $child = $parents;
158  $child[] = $k;
159  $output .= drush_export_info($v, $integer_keys, $child);
160  }
161  }
162  else if (!empty($info) && count($parents)) {
163  $line = array_shift($parents);
164  foreach ($parents as $key) {
165  $line .= (!$integer_keys && is_numeric($key)) ? "[]" : "[{$key}]";
166  }
167  $line .= " = \"{$info}\"\n";
168  return $line;
169  }
170  return $output;
171 }
172 
173 /**
174  * Convert a csv string, or an array of items which
175  * may contain csv strings, into an array of items.
176  *
177  * @param $args
178  * A simple csv string; e.g. 'a,b,c'
179  * or a simple list of items; e.g. array('a','b','c')
180  * or some combination; e.g. array('a,b','c') or array('a,','b,','c,')
181  *
182  * @returns array
183  * A simple list of items (e.g. array('a','b','c')
184  */
185 function _convert_csv_to_array($args) {
186  //
187  // Step 1: implode(',',$args) converts from, say, array('a,','b,','c,') to 'a,,b,,c,'
188  // Step 2: explode(',', ...) converts to array('a','','b','','c','')
189  // Step 3: array_filter(...) removes the empty items
190  // Step 4: array_map(...) trims extra whitespace from each item
191  // (handles csv strings with extra whitespace, e.g. 'a, b, c')
192  //
193  return array_map('trim', array_filter(explode(',', is_array($args) ? implode(',',$args) : $args)));
194 }
195 
196 /**
197  * Convert a nested array into a flat array. Thows away
198  * the array keys, returning only the values.
199  *
200  * @param $args
201  * An array that may potentially be nested.
202  * e.g. array('a', array('b', 'c'))
203  *
204  * @returns array
205  * A simple list of items (e.g. array('a','b','c')
206  */
207 function drush_flatten_array($a) {
208  $result = array();
209  if (!is_array($a)) {
210  return array($a);
211  }
212  foreach ($a as $value) {
213  $result = array_merge($result, drush_flatten_array($value));
214  }
215  return $result;
216 }
217 
218 /**
219  * Get the available global options. Used by help command. Command files may
220  * modify this list using hook_drush_help_alter().
221  *
222  * @param boolean $brief
223  * Return a reduced set of important options. Used by help command.
224  *
225  * @return
226  * An associative array containing the option definition as the key,
227  * and a descriptive array for each of the available options. The array
228  * elements for each item are:
229  *
230  * - short-form: The shortcut form for specifying the key on the commandline.
231  * - context: The drush context where the value of this item is cached. Used
232  * by backend invoke to propagate values set in code.
233  * - never-post: If TRUE, backend invoke will never POST this item's value
234  * on STDIN; it will always be sent as a commandline option.
235  * - never-propagate: If TRUE, backend invoke will never pass this item on
236  * to the subcommand being executed.
237  * - local-context-only: Backend invoke will only pass this value on for local calls.
238  * - merge: For options such as $options['shell-aliases'] that consist of an array
239  * of items, make a merged array that contains all of the values specified for
240  * all of the contexts (config files) where the option is defined. The value is stored in
241  * the specified 'context', or in a context named after the option itself if the
242  * context flag is not specified.
243  * IMPORTANT: When the merge flag is used, the option value must be obtained via
244  * drush_get_context('option') rather than drush_get_option('option').
245  * - merge-pathlist: For options such as --include and --config, make a merged list
246  * of options from all contexts; works like the 'merge' flag, but also handles string
247  * values separated by the PATH_SEPARATOR.
248  * - merge-associative: Like 'merge-pathlist', but key values are preserved.
249  * - propagate-cli-value: Used to tell backend invoke to include the value for
250  * this item as specified on the cli. This can either override 'context'
251  * (e.g., propagate --include from cli value instead of DRUSH_INCLUDE context),
252  * or for an independent global setting (e.g. --user)
253  * - description: The help text for this item. displayed by `drush help`.
254  */
255 function drush_get_global_options($brief = FALSE) {
256  $options['root'] = array('short-form' => 'r', 'short-has-arg' => TRUE, 'never-post' => TRUE, 'description' => "Drupal root directory to use (default: current directory).", 'example-value' => 'path');
257  $options['uri'] = array('short-form' => 'l', 'short-has-arg' => TRUE, 'never-post' => TRUE, 'description' => 'URI of the drupal site to use (only needed in multisite environments or when running on an alternate port).', 'example-value' => 'http://example.com:8888');
258  $options['verbose'] = array('short-form' => 'v', 'context' => 'DRUSH_VERBOSE', 'description' => 'Display extra information about the command.');
259  $options['debug'] = array('short-form' => 'd', 'context' => 'DRUSH_DEBUG', 'description' => 'Display even more information, including internal messages.');
260  $options['yes'] = array('short-form' => 'y', 'context' => 'DRUSH_AFFIRMATIVE', 'description' => "Assume 'yes' as answer to all prompts.");
261  $options['no'] = array('short-form' => 'n', 'context' => 'DRUSH_NEGATIVE', 'description' => "Assume 'no' as answer to all prompts.");
262  $options['simulate'] = array('short-form' => 's', 'context' => 'DRUSH_SIMULATE', 'never-propagate' => TRUE, 'description' => "Simulate all relevant actions (don't actually change the system).");
263  $options['pipe'] = array('short-form' => 'p', 'hidden' => TRUE, 'description' => "Emit a compact representation of the command for scripting.");
264  $options['help'] = array('short-form' => 'h', 'description' => "This help system.");
265 
266  if (!$brief) {
267  $options['version'] = array('description' => "Show drush version.");
268  $options['php'] = array('description' => "The absolute path to your PHP intepreter, if not 'php' in the path.", 'example-value' => '/path/to/file', 'never-propagate' => TRUE);
269  $options['interactive'] = array('short-form' => 'ia', 'description' => "Force interactive mode for commands run on multiple targets (e.g. `drush @site1,@site2 cc --ia`).", 'never-propagate' => TRUE);
270  $options['tty'] = array('hidden' => TRUE, 'description' => "Force allocation of tty for remote commands", 'never-propagate' => TRUE);
271  $options['quiet'] = array('short-form' => 'q', 'description' => 'Suppress non-error messages.');
272  $options['include'] = array('short-form' => 'i', 'short-has-arg' => TRUE, 'context' => 'DRUSH_INCLUDE', 'never-post' => TRUE, 'propagate-cli-value' => TRUE, 'merge-pathlist' => TRUE, 'description' => "A list of additional directory paths to search for drush commands.", 'example-value' => '/path/dir');
273  $options['exclude'] = array('propagate-cli-value' => TRUE, 'never-post' => TRUE, 'merge-pathlist' => TRUE, 'description' => "A list of files and directory paths to exclude from consideration when searching for drush commandfiles.", 'example-value' => '/path/dir');
274  $options['config'] = array('short-form' => 'c', 'short-has-arg' => TRUE, 'context' => 'DRUSH_CONFIG', 'local-context-only' => TRUE, 'merge-pathlist' => TRUE, 'description' => "Specify an additional config file to load. See example.drushrc.php.", 'example-value' => '/path/file');
275  $options['user'] = array('short-form' => 'u', 'short-has-arg' => TRUE, 'propagate-cli-value' => TRUE, 'description' => "Specify a Drupal user to login with. May be a name or a number.", 'example-value' => 'name_or_number');
276  $options['backend'] = array('short-form' => 'b', 'never-propagate' => TRUE, 'description' => "Hide all output and return structured data.");
277  $options['choice'] = array('description' => "Provide an answer to a multiple-choice prompt.", 'example-value' => 'number');
278  $options['variables'] = array('description' => "Comma delimited list of name=value pairs. These values take precedence even over settings.php variable overrides.", 'example-value' => 'foo=bar,baz=yaz');
279  $options['search-depth'] = array('description' => "Control the depth that drush will search for alias files.", 'example-value' => 'number');
280  $options['ignored-modules'] = array('description' => "Exclude some modules from consideration when searching for drush command files.", 'example-value' => 'token,views');
281  $options['no-label'] = array('description' => "Remove the site label that drush includes in multi-site command output (e.g. `drush @site1,@site2 status`).");
282  $options['label-separator'] = array('description' => "Specify the separator to use in multi-site command output (e.g. `drush @sites pm-list --label-separator=',' --format=csv`).");
283  $options['nocolor'] = array('context' => 'DRUSH_NOCOLOR', 'propagate-cli-value' => TRUE, 'description' => "Suppress color highlighting on log messages.");
284  $options['show-passwords'] = array('description' => "Show database passwords in commands that display connection information.");
285  $options['show-invoke'] = array('description' => "Show all function names which could have been called for the current command. See drush_invoke().");
286  $options['watchdog'] = array('description' => "Control logging of Drupal's watchdog() to drush log. Recognized values are 'log', 'print', 'disabled'. Defaults to log. 'print' shows calls to admin but does not add them to the log.", 'example-value' => 'print');
287  $options['cache-default-class'] = array('description' => "A cache backend class that implements CacheInterface. Defaults to JSONCache.", 'example-value' => 'JSONCache');
288  $options['cache-class-<bin>'] = array('description' => "A cache backend class that implements CacheInterface to use for a specific cache bin.", 'example-value' => 'className');
289  $options['early'] = array('description' => "Include a file (with relative or full path) and call the drush_early_hook() function (where 'hook' is the filename). The function is called pre-bootstrap and offers an opportunity to alter the drush bootstrap environment or process (returning FALSE from the function will continue the bootstrap), or return output very rapidly (e.g. from caches). See includes/complete.inc for an example.");
290  $options['alias-path'] = array('context' => 'ALIAS_PATH', 'local-context-only' => TRUE, 'merge-pathlist' => TRUE, 'propagate-cli-value' => TRUE, 'description' => "Specifies the list of paths where drush will search for alias files.", 'example-value' => '/path/alias1:/path/alias2');
291  $options['backup-location'] = array('description' => "Specifies the directory where drush will store backups.", 'example-value' => '/path/to/dir');
292  $options['confirm-rollback'] = array('description' => 'Wait for confirmation before doing a rollback when something goes wrong.');
293  $options['complete-debug'] = array('hidden' => TRUE, 'description' => "Turn on debug mode forf completion code");
294  $options['php-options'] = array('description' => "Options to pass to `php` when running drush. Only effective when using the `drush` script.", 'never-propagate' => TRUE, 'example-value' => '-d error_reporting="E_ALL"');
295  $options['deferred-sanitization'] = array('hidden' => TRUE, 'description' => "Defer calculating the sanitization operations until after the database has been copied. This is done automatically if the source database is remote.");
296  $options['remote-host'] = array('hidden' => TRUE, 'description' => 'Remote site to execute drush command on. Managed by site alias.');
297  $options['remote-user'] = array('hidden' => TRUE, 'description' => 'User account to use with a remote drush command. Managed by site alias.');
298  $options['remote-os'] = array('hidden' => TRUE, 'description' => 'The operating system used on the remote host. Managed by site alias.');
299  $options['site-list'] = array('hidden' => TRUE, 'description' => 'List of sites to run commands on. Managed by site alias.');
300  $options['reserve-margin'] = array('hidden' => TRUE, 'description' => 'Remove columns from formatted opions. Managed by multi-site command handling.');
301  $options['strict'] = array('hidden' => TRUE, 'description' => 'Check requirements more strictly / remove backwards-compatibility features for unit tests.');
302  $options['command-specific'] = array('hidden' => TRUE, 'merge-associative' => TRUE, 'description' => 'Command-specific options.');
303  $options['site-aliases'] = array('hidden' => TRUE, 'merge-associative' => TRUE, 'description' => 'List of site aliases.');
304  $options['shell-aliases'] = array('hidden' => TRUE, 'merge' => TRUE, 'never-propagate' => TRUE, 'description' => 'List of shell aliases.');
305  $options['path-aliases'] = array('hidden' => TRUE, 'never-propagate' => TRUE, 'description' => 'Path aliases from site alias.');
306  $options['ssh-options'] = array('never-propagate' => TRUE, 'description' => 'A string of extra options that will be passed to the ssh command', 'example-value' => '-p 100');
307  $options['editor'] = array('never-propagate' => TRUE, 'description' => 'A string of bash which launches user\'s preferred text editor. Defaults to ${VISUAL-${EDITOR-vi}}.', 'example-value' => 'vi');
308  $options['db-url'] = array('hidden' => TRUE, 'description' => 'A Drupal 6 style database URL. Used by various commands.', 'example-value' => 'mysql://root:pass@127.0.0.1/db');
309  $options['drush-coverage'] = array('hidden' => TRUE, 'never-post' => TRUE, 'propagate-cli-value' => TRUE, 'description' => 'File to save code coverage data into.');
310  $options['redirect-port'] = array('hidden' => TRUE, 'never-propagate' => TRUE, 'description' => 'Used by the user-login command to specify the redirect port on the local machine; it therefore would not do to pass this to the remote machines.');
311 
312  $command = array(
313  'options' => $options,
314  '#brief' => FALSE,
315  ) + drush_command_defaults('global-options', 'global_options', __FILE__);
316  drush_command_invoke_all_ref('drush_help_alter', $command);
317 
318  $options = $command['options'];
319  }
320  return $options;
321 }
322 
323 /**
324  * Exits with a message. In general, you should use drush_set_error() instead of
325  * this function. That lets drush proceed with other tasks.
326  * TODO: Exit with a correct status code.
327  */
328 function drush_die($msg = NULL, $status = NULL) {
329  die($msg ? "drush: $msg\n" : '');
330 }
331 
332 /**
333  * Check to see if the provided line is a "#!/usr/bin/env drush"
334  * "shebang" script line.
335  */
337  return ((substr($line,0,2) == '#!') && (strstr($line, 'drush') !== FALSE));
338 }
339 
340 /**
341  * Check to see if the provided script file is a "#!/usr/bin/env drush"
342  * "shebang" script line.
343  */
344 function _drush_is_drush_shebang_script($script_filename) {
345  $result = FALSE;
346 
347  if (file_exists($script_filename)) {
348  $fp = fopen($script_filename, "r");
349  if ($fp !== FALSE) {
350  $line = fgets($fp);
351  $result = _drush_is_drush_shebang_line($line);
352  fclose($fp);
353  }
354  }
355 
356  return $result;
357 }
358 
359 /**
360  * @defgroup userinput Get input from the user.
361  * @{
362  */
363 
364 /**
365  * Asks the user a basic yes/no question.
366  *
367  * @param string $msg
368  * The question to ask.
369  * @param int $indent
370  * The number of spaces to indent the message.
371  *
372  * @return bool
373  * TRUE if the user enters "y" or FALSE if "n".
374  */
375 function drush_confirm($msg, $indent = 0) {
376  drush_print_prompt((string)$msg . " (y/n): ", $indent);
377 
378  // Automatically accept confirmations if the --yes argument was supplied.
379  if (drush_get_context('DRUSH_AFFIRMATIVE')) {
380  drush_print("y");
381  return TRUE;
382  }
383  // Automatically cancel confirmations if the --no argument was supplied.
384  elseif (drush_get_context('DRUSH_NEGATIVE')) {
385  drush_print("n");
386  return FALSE;
387  }
388  // See http://drupal.org/node/499758 before changing this.
389  $stdin = fopen("php://stdin","r");
390 
391  while ($line = fgets($stdin)) {
392  $line = trim($line);
393  if ($line == 'y') {
394  return TRUE;
395  }
396  if ($line == 'n') {
397  return FALSE;
398  }
399  drush_print_prompt((string)$msg . " (y/n): ", $indent);
400  }
401 }
402 
403 /**
404  * Ask the user to select an item from a list.
405  * From a provided associative array, drush_choice will
406  * display all of the questions, numbered from 1 to N,
407  * and return the item the user selected. "0" is always
408  * cancel; entering a blank line is also interpreted
409  * as cancelling.
410  *
411  * @param $options
412  * A list of questions to display to the user. The
413  * KEYS of the array are the result codes to return to the
414  * caller; the VALUES are the messages to display on
415  * each line. Special keys of the form '-- something --' can be
416  * provided as separator between choices groups. Separator keys
417  * don't alter the numbering.
418  * @param $prompt
419  * The message to display to the user prompting for input.
420  * @param $label
421  * Controls the display of each line. Defaults to
422  * '!value', which displays the value of each item
423  * in the $options array to the user. Use '!key' to
424  * display the key instead. In some instances, it may
425  * be useful to display both the key and the value; for
426  * example, if the key is a user id and the value is the
427  * user name, use '!value (uid=!key)'.
428  */
429 function drush_choice($options, $prompt = 'Enter a number.', $label = '!value', $widths = array()) {
430  drush_print(dt($prompt));
431 
432  // Preflight so that all rows will be padded out to the same number of columns
433  $array_pad = 0;
434  foreach ($options as $key => $option) {
435  if (is_array($option) && (count($option) > $array_pad)) {
436  $array_pad = count($option);
437  }
438  }
439 
440  $rows[] = array_pad(array('[0]', ':', 'Cancel'), $array_pad + 2, '');
441  $selection_number = 0;
442  foreach ($options as $key => $option) {
443  if ((substr($key, 0, 3) == '-- ') && (substr($key, -3) == ' --')) {
444  $rows[] = array_pad(array('', '', $option), $array_pad + 2, '');
445  }
446  else {
447  $selection_number++;
448  $row = array("[$selection_number]", ':');
449  if (is_array($option)) {
450  $row = array_merge($row, $option);
451  }
452  else {
453  $row[] = dt($label, array('!number' => $selection_number, '!key' => $key, '!value' => $option));
454  }
455  $rows[] = $row;
456  $selection_list[$selection_number] = $key;
457  }
458  }
459  drush_print_table($rows, FALSE, $widths);
460  drush_print_pipe(array_keys($options));
461 
462  // If the user specified --choice, then make an
463  // automatic selection. Cancel if the choice is
464  // not an available option.
465  if (($choice = drush_get_option('choice', FALSE)) !== FALSE) {
466  // First check to see if $choice is one of the symbolic options
467  if (array_key_exists($choice, $options)) {
468  return $choice;
469  }
470  // Next handle numeric selections
471  elseif (array_key_exists($choice, $selection_list)) {
472  return $selection_list[$choice];
473  }
474  return FALSE;
475  }
476 
477  // If the user specified --no, then cancel; also avoid
478  // getting hung up waiting for user input in --pipe and
479  // backend modes. If none of these apply, then wait,
480  // for user input and return the selected result.
481  if (!drush_get_context('DRUSH_NEGATIVE') && !drush_get_context('DRUSH_AFFIRMATIVE') && !drush_get_context('DRUSH_PIPE')) {
482  while ($line = trim(fgets(STDIN))) {
483  if (array_key_exists($line, $selection_list)) {
484  return $selection_list[$line];
485  }
486  }
487  }
488  // We will allow --yes to confirm input if there is only
489  // one choice; otherwise, --yes will cancel to avoid ambiguity
490  if (drush_get_context('DRUSH_AFFIRMATIVE') && (count($options) == 1)) {
491  return $selection_list[1];
492  }
493  drush_print(dt('Cancelled'));
494  return FALSE;
495 }
496 
497 /**
498  * Ask the user to select multiple items from a list.
499  * This is a wrapper around drush_choice, that repeats the selection process,
500  * allowing users to toggle a number of items in a list. The number of values
501  * that can be constrained by both min and max: the user will only be allowed
502  * finalize selection once the minimum number has been selected, and the oldest
503  * selected value will "drop off" the list, if they exceed the maximum number.
504  *
505  * @param $options
506  * Same as drush_choice() (see above).
507  * @param $defaults
508  * This can take 3 forms:
509  * - FALSE: (Default) All options are unselected by default.
510  * - TRUE: All options are selected by default.
511  * - Array of $options keys to be selected by default.
512  * @param $prompt
513  * Same as drush_choice() (see above).
514  * @param $label
515  * Same as drush_choice() (see above).
516  * @param $mark
517  * Controls how selected values are marked. Defaults to '!value (selected)'.
518  * @param $min
519  * Constraint on minimum number of selections. Defaults to zero. When fewer
520  * options than this are selected, no final options will be available.
521  * @param $max
522  * Constraint on minimum number of selections. Defaults to NULL (unlimited).
523  * If the a new selection causes this value to be exceeded, the oldest
524  * previously selected value is automatically unselected.
525  * @param $final_options
526  * An array of additional options in the same format as $options.
527  * When the minimum number of selections is met, this array is merged into the
528  * array of options. If the user selects one of these values and the
529  * selection process will complete (the key for the final option is included
530  * in the return value). If this is an empty array (default), then a built in
531  * final option of "Done" will be added to the available options (in this case
532  * no additional keys are added to the return value).
533  */
534 function drush_choice_multiple($options, $defaults = FALSE, $prompt = 'Select some numbers.', $label = '!value', $mark = '!value (selected)', $min = 0, $max = NULL, $final_options = array()) {
535  $selections = array();
536  // Load default selections.
537  if (is_array($defaults)) {
538  $selections = $defaults;
539  }
540  elseif ($defaults === TRUE) {
541  $selections = array_keys($options);
542  }
543  $complete = FALSE;
544  $final_builtin = array();
545  if (empty($final_options)) {
546  $final_builtin['done'] = dt('Done');
547  }
548  $final_options_keys = array_keys($final_options);
549  while (TRUE) {
550  $current_options = $options;
551  // Mark selections.
552  foreach ($selections as $selection) {
553  $current_options[$selection] = dt($mark, array('!key' => $selection, '!value' => $options[$selection]));
554  }
555  // Add final options, if the minimum number of selections has been reached.
556  if (count($selections) >= $min) {
557  $current_options = array_merge($current_options, $final_options, $final_builtin);
558  }
559  $toggle = drush_choice($current_options, $prompt, $label);
560  if ($toggle === FALSE) {
561  return FALSE;
562  }
563  // Don't include the built in final option in the return value.
564  if (count($selections) >= $min && empty($final_options) && $toggle == 'done') {
565  return $selections;
566  }
567  // Toggle the selected value.
568  $item = array_search($toggle, $selections);
569  if ($item === FALSE) {
570  array_unshift($selections, $toggle);
571  }
572  else {
573  unset($selections[$item]);
574  }
575  // If the user selected one of the final options, return.
576  if (count($selections) >= $min && in_array($toggle, $final_options_keys)) {
577  return $selections;
578  }
579  // If the user selected too many options, drop the oldest selection.
580  if (isset($max) && count($selections) > $max) {
581  array_pop($selections);
582  }
583  }
584 }
585 
586 /**
587  * Prompt the user for input
588  *
589  * The input can be anything that fits on a single line (not only y/n),
590  * so we can't use drush_confirm()
591  *
592  * @param $prompt
593  * The text which is displayed to the user.
594  * @param $default
595  * The default value of the input.
596  * @param $required
597  * If TRUE, user may continue even when no value is in the input.
598  * @param $password
599  * If TRUE, surpress printing of the input.
600  *
601  * @see drush_confirm()
602  */
603 function drush_prompt($prompt, $default = NULL, $required = TRUE, $password = FALSE) {
604  if (isset($default)) {
605  $prompt .= " [" . $default . "]";
606  }
607  $prompt .= ": ";
608 
609  drush_print_prompt($prompt);
610 
611  if (drush_get_context('DRUSH_AFFIRMATIVE')) {
612  return $default;
613  }
614 
615  $stdin = fopen('php://stdin', 'r');
616 
617  if ($password) drush_shell_exec("stty -echo");
618 
619  stream_set_blocking($stdin, TRUE);
620  while (($line = fgets($stdin)) !== FALSE) {
621  $line = trim($line);
622  if ($line === "") {
623  $line = $default;
624  }
625  if ($line || !$required) {
626  break;
627  }
628  drush_print_prompt($prompt);
629  }
630  fclose($stdin);
631  if ($password) {
632  drush_shell_exec("stty echo");
633  print "\n";
634  }
635  return $line;
636 }
637 
638 /**
639  * @} End of "defgroup userinput".
640  */
641 
642 /**
643  * Calls a given function, passing through all arguments unchanged.
644  *
645  * This should be used when calling possibly mutative or destructive functions
646  * (e.g. unlink() and other file system functions) so that can be suppressed
647  * if the simulation mode is enabled.
648  *
649  * Important: Call @see drush_op_system() to execute a shell command,
650  * or @see drush_shell_exec() to execute a shell command and capture the
651  * shell output.
652  *
653  * @param $function
654  * The name of the function. Any additional arguments are passed along.
655  * @return
656  * The return value of the function, or TRUE if simulation mode is enabled.
657  *
658  */
659 function drush_op($function) {
660  $args_printed = array();
661  $args = func_get_args();
662  array_shift($args); // Skip function name
663  foreach ($args as $arg) {
664  $args_printed[] = is_scalar($arg) ? $arg : (is_array($arg) ? 'Array' : 'Object');
665  }
666 
667  // Special checking for drush_op('system')
668  if ($function == 'system') {
669  drush_log(dt("Do not call drush_op('system'); use drush_op_system instead"), 'debug');
670  }
671 
672  if (drush_get_context('DRUSH_VERBOSE') || drush_get_context('DRUSH_SIMULATE')) {
673  drush_log(sprintf("Calling %s(%s)", $function, implode(", ", $args_printed)), 'debug');
674  }
675 
676  if (drush_get_context('DRUSH_SIMULATE')) {
677  return TRUE;
678  }
679 
680  return drush_call_user_func_array($function, $args);
681 }
682 
683 /**
684  * Mimic cufa but still call function directly. See http://drupal.org/node/329012#comment-1260752
685  */
686 function drush_call_user_func_array($function, $args = array() ) {
687  switch (count($args)) {
688  case 0: return $function(); break;
689  case 1: return $function($args[0]); break;
690  case 2: return $function($args[0], $args[1]); break;
691  case 3: return $function($args[0], $args[1], $args[2]); break;
692  case 4: return $function($args[0], $args[1], $args[2], $args[3]); break;
693  case 5: return $function($args[0], $args[1], $args[2], $args[3], $args[4]); break;
694  case 6: return $function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); break;
695  case 7: return $function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); break;
696  case 8: return $function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); break;
697  case 9: return $function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); break;
698  default: return call_user_func_array($function,$args);
699  }
700 }
701 
702 /**
703  * Download a file using wget, curl or file_get_contents, or via download cache.
704  *
705  * @param string $url
706  * The url of the file to download.
707  * @param string $destination
708  * The name of the file to be saved, which may include the full path.
709  * Optional, if omitted the filename will be extracted from the url and the
710  * file downloaded to the current working directory (Drupal root if
711  * bootstrapped).
712  * @param integer $cache_duration
713  * The acceptable age of a cached file. If cached file is too old, a fetch
714  * will occur and cache will be updated. Optional, if ommitted the file will
715  * be fetched directly.
716  *
717  * @return string
718  * The path to the downloaded file, or FALSE if the file could not be
719  * downloaded.
720  */
721 function drush_download_file($url, $destination = FALSE, $cache_duration = 0) {
722  // Generate destination if omitted.
723  if (!$destination) {
724  $file = basename(current(explode('?', $url, 2)));
725  $destination = getcwd() . '/' . basename($file);
726  }
727 
728  // Simply copy local files to the destination
729  if (!_drush_is_url($url)) {
730  return copy($url, $destination) ? $destination : FALSE;
731  }
732 
733  if (drush_get_option('cache') && $cache_duration !== 0 && $cache_file = drush_download_file_name($url)) {
734  // Check for cached, unexpired file.
735  if (file_exists($cache_file) && filectime($cache_file) > ($_SERVER['REQUEST_TIME']-$cache_duration)) {
736  drush_log(dt('!name retrieved from cache.', array('!name' => $cache_file)));
737  }
738  else {
739  if (_drush_download_file($url, $cache_file, TRUE)) {
740  // Cache was set just by downloading file to right location.
741  }
742  elseif (file_exists($cache_file)) {
743  drush_log(dt('!name retrieved from an expired cache since refresh failed.', array('!name' => $cache_file)), 'warning');
744  }
745  else {
746  $cache_file = FALSE;
747  }
748  }
749 
750  if ($cache_file && copy($cache_file, $destination)) {
751  // Copy cached file to the destination
752  return $destination;
753  }
754  }
755  elseif ($return = _drush_download_file($url, $destination)) {
757  return $return;
758  }
759 
760  // Unable to retrieve from cache nor download.
761  return FALSE;
762 }
763 
764 /**
765  * Helper function to determine name of cached file.
766  */
767 function drush_download_file_name($url) {
768  if ($cache_dir = drush_directory_cache('download')) {
769  $cache_name = str_replace(array(':', '/', '?', '='), '-', $url);
770  return $cache_dir . "/" . $cache_name;
771  }
772  else {
773  return FALSE;
774  }
775 }
776 
777 /**
778  * Check whether the given path is just a url or a local path
779  * @param string $url
780  * @return boolean
781  * TRUE if the path does not contain a schema:// part.
782  */
783 function _drush_is_url($url) {
784  return parse_url($url, PHP_URL_SCHEME) !== NULL;
785 }
786 
787 /**
788  * Download a file using wget, curl or file_get_contents. Does not use download
789  * cache.
790  *
791  * @param string $url
792  * The url of the file to download.
793  * @param string $destination
794  * The name of the file to be saved, which may include the full path.
795  * @param boolean $overwrite
796  * Overwrite any file thats already at the destination.
797  * @return string
798  * The path to the downloaded file, or FALSE if the file could not be
799  * downloaded.
800  */
801 function _drush_download_file($url, $destination, $overwrite = TRUE) {
802  static $use_wget;
803  if ($use_wget === NULL) {
804  $use_wget = drush_shell_exec('wget --version');
805  }
806 
807  $destination_tmp = drush_tempnam('download_file');
808  if ($use_wget) {
809  drush_shell_exec("wget -q --timeout=30 -O %s %s", $destination_tmp, $url);
810  }
811  else {
812  drush_shell_exec("curl --fail -s -L --connect-timeout 30 -o %s %s", $destination_tmp, $url);
813  }
814  if (!drush_file_not_empty($destination_tmp) && $file = @file_get_contents($url)) {
815  @file_put_contents($destination_tmp, $file);
816  }
817  if (!drush_file_not_empty($destination_tmp)) {
818  // Download failed.
819  return FALSE;
820  }
821 
822  drush_move_dir($destination_tmp, $destination, $overwrite);
823  return $destination;
824 }
825 
826 /**
827  * Determines the MIME content type of the specified file.
828  *
829  * The power of this function depends on whether the PHP installation
830  * has either mime_content_type() or finfo installed -- if not, only tar,
831  * gz, zip and bzip2 types can be detected.
832  *
833  * If mime type can't be obtained, an error will be set.
834  *
835  * @return mixed
836  * The MIME content type of the file or FALSE.
837  */
838 function drush_mime_content_type($filename) {
839  $content_type = FALSE;
840  if (class_exists('finfo')) {
841  $finfo = new finfo(FILEINFO_MIME_TYPE);
842  $content_type = $finfo->file($filename);
843  if ($content_type == 'application/octet-stream') {
844  drush_log(dt('Mime type for !file is application/octet-stream.', array('!file' => $filename)), 'debug');
845  $content_type = FALSE;
846  }
847  }
848  // If apache is configured in such a way that all files are considered
849  // octet-stream (e.g with mod_mime_magic and an http conf that's serving all
850  // archives as octet-stream for other reasons) we'll detect mime types on our
851  // own by examing the file's magic header bytes.
852  if (!$content_type) {
853  drush_log(dt('Examining !file headers.', array('!file' => $filename)), 'debug');
854  if ($file = fopen($filename, 'rb')) {
855  $first = fread($file, 2);
856  fclose($file);
857 
858  if ($first !== FALSE) {
859  // Interpret the two bytes as a little endian 16-bit unsigned int.
860  $data = unpack('v', $first);
861  switch ($data[1]) {
862  case 0x8b1f:
863  // First two bytes of gzip files are 0x1f, 0x8b (little-endian).
865  $content_type = 'application/x-gzip';
866  break;
867 
868  case 0x4b50:
869  // First two bytes of zip files are 0x50, 0x4b ('PK') (little-endian).
870  // See http://en.wikipedia.org/wiki/Zip_(file_format)#File_headers
871  $content_type = 'application/zip';
872  break;
873 
874  case 0x5a42:
875  // First two bytes of bzip2 files are 0x5a, 0x42 ('BZ') (big-endian).
877  $content_type = 'application/x-bzip2';
878  break;
879 
880  default:
881  drush_log(dt('Unable to determine mime type from header bytes 0x!hex of !file.', array('!hex' => dechex($data[1]), '!file' => $filename,), 'debug'));
882  }
883  }
884  else {
885  drush_log(dt('Unable to read !file.', array('!file' => $filename)), 'warning');
886  }
887  }
888  else {
889  drush_log(dt('Unable to open !file.', array('!file' => $filename)), 'warning');
890  }
891  }
892 
893  // 3. Lastly if above methods didn't work, try to guess the mime type from
894  // the file extension. This is useful if the file has no identificable magic
895  // header bytes (for example tarballs).
896  if (!$content_type) {
897  drush_log(dt('Examining !file extension.', array('!file' => $filename)), 'debug');
898 
899  // Remove querystring from the filename, if present.
900  $filename = basename(current(explode('?', $filename, 2)));
901  $extension_mimetype = array(
902  '.tar' => 'application/x-tar',
903  );
904  foreach ($extension_mimetype as $extension => $ct) {
905  if (substr($filename, -strlen($extension)) === $extension) {
906  $content_type = $ct;
907  break;
908  }
909  }
910  }
911 
912  if ($content_type) {
913  drush_log(dt('Mime type for !file is !mt', array('!file' => $filename, '!mt' => $content_type)), 'notice');
914  return $content_type;
915  }
916 
917  return drush_set_error('MIME_CONTENT_TYPE_UNKNOWN', dt('Unable to determine mime type for !file.', array('!file' => $filename)));
918 }
919 
920 /**
921  * Check whether a file is a supported tarball.
922  *
923  * @return mixed
924  * The file content type if it's a tarball. FALSE otherwise.
925  */
926 function drush_file_is_tarball($path) {
927  $content_type = drush_mime_content_type($path);
928  $supported = array(
929  'application/x-bzip2',
930  'application/x-gzip',
931  'application/x-tar',
932  'application/x-zip',
933  'application/zip',
934  );
935  if (in_array($content_type, $supported)) {
936  return $content_type;
937  }
938  return FALSE;
939 }
940 
941 /**
942  * Extract a tarball.
943  *
944  * @param string $path
945  * Path to the archive to be extracted.
946  * @param string $destination
947  * The destination directory the tarball should be extracted into.
948  * Optional, if ommitted the tarball directory will be used as destination.
949  * @param boolean $listing
950  * If TRUE, a listing of the tar contents will be returned on success.
951  * @param string $tar_extra_options
952  * Extra options to be passed to the tar command.
953  *
954  * @return mixed
955  * TRUE on success, FALSE on fail. If $listing is TRUE, a file listing of the
956  * tarball is returned if the extraction reported success, instead of TRUE.
957  */
958 function drush_tarball_extract($path, $destination = FALSE, $listing = FALSE, $tar_extra_options = '') {
959  // Check if tarball is supported.
960  if (!($mimetype = drush_file_is_tarball($path))) {
961  return drush_set_error('TARBALL_EXTRACT_UNKNOWN_FORMAT', dt('Unable to extract !path. Unknown archive format.', array('!path' => $path)));
962  }
963 
964  // Check if destination is valid.
965  if (!$destination) {
966  $destination = dirname($path);
967  }
968  if (!drush_mkdir($destination)) {
969  // drush_mkdir already set an error.
970  return FALSE;
971  }
972 
973  // Perform the extraction of a zip file.
974  if (($mimetype == 'application/zip') || ($mimetype == 'application/x-zip')) {
975  $return = drush_shell_cd_and_exec(dirname($path), "unzip %s -d %s", $path, $destination);
976  if (!$return) {
977  return drush_set_error('DRUSH_TARBALL_EXTRACT_ERROR', dt('Unable to unzip !filename.', array('!filename' => $path)));
978  }
979  if ($listing) {
980  // unzip prefixes the file listing output with a header line,
981  // and prefixes each line with a verb representing the compression type.
982  $output = drush_shell_exec_output();
983  // Remove the header line.
984  array_shift($output);
985  // Remove the prefix verb from each line.
986  $output = array_map(create_function('$str', 'return substr($str, strpos($str, ":") + 3 + ' . strlen($destination) . ');'), $output);
987  // Remove any remaining blank lines.
988  $return = array_filter($output, create_function('$str', 'return $str != "";'));
989  }
990  }
991  // Otherwise we have a possibly-compressed Tar file.
992  // If we are not on Windows, then try to do "tar" in a single operation.
993  elseif (!drush_is_windows()) {
994  $tar = drush_get_tar_executable();
995  $tar_compression_flag = '';
996  if ($mimetype == 'application/x-gzip') {
997  $tar_compression_flag = 'z';
998  }
999  elseif ($mimetype == 'application/x-bzip2') {
1000  $tar_compression_flag = 'j';
1001  }
1002 
1003  $return = drush_shell_cd_and_exec(dirname($path), "$tar {$tar_extra_options} -C %s -x%sf %s", $destination, $tar_compression_flag, basename($path));
1004  if (!$return) {
1005  return drush_set_error('DRUSH_TARBALL_EXTRACT_ERROR', dt('Unable to untar !filename.', array('!filename' => $path)));
1006  }
1007  if ($listing) {
1008  // We use a separate tar -tf instead of -xvf above because
1009  // the output is not the same in Mac.
1010  drush_shell_cd_and_exec(dirname($path), "$tar -t%sf %s", $tar_compression_flag, basename($path));
1011  $return = drush_shell_exec_output();
1012  }
1013  }
1014  // In windows, do the extraction by its primitive steps.
1015  else {
1016  // 1. copy the source tarball to the destination directory. Rename to a
1017  // temp name in case the destination directory == dirname($path)
1018  $tmpfile = drush_tempnam(basename($path), $destination);
1019  drush_copy_dir($path, $tmpfile, FILE_EXISTS_OVERWRITE);
1020 
1021  // 2. uncompress the tarball, if compressed.
1022  if (($mimetype == 'application/x-gzip') || ($mimetype == 'application/x-bzip2')) {
1023  if ($mimetype == 'application/x-gzip') {
1024  $compressed = $tmpfile . '.gz';
1025  // We used to use gzip --decompress in --stdout > out, but the output
1026  // redirection sometimes failed on Windows for some binary output.
1027  $command = 'gzip --decompress %s';
1028  }
1029  elseif ($mimetype == 'application/x-bzip2') {
1030  $compressed = $tmpfile . '.bz2';
1031  $command = 'bzip2 --decompress %s';
1032  }
1033  drush_op('rename', $tmpfile, $compressed);
1034  $return = drush_shell_cd_and_exec(dirname($compressed), $command, $compressed);
1035  if (!$return || !file_exists($tmpfile)) {
1036  return drush_set_error('DRUSH_TARBALL_EXTRACT_ERROR', dt('Unable to decompress !filename.', array('!filename' => $compressed)));
1037  }
1038  }
1039 
1040  // 3. Untar.
1041  $tar = drush_get_tar_executable();
1042  $return = drush_shell_cd_and_exec(dirname($tmpfile), "$tar {$tar_extra_options} -xvf %s", basename($tmpfile));
1043  if (!$return) {
1044  return drush_set_error('DRUSH_TARBALL_EXTRACT_ERROR', dt('Unable to untar !filename.', array('!filename' => $tmpfile)));
1045  }
1046  if ($listing) {
1047  $return = drush_shell_exec_output();
1048  // Cut off the 'x ' prefix for the each line of the tar output
1050  foreach($return as &$line) {
1051  if(strpos($line, "x ") === 0)
1052  $line = substr($line, 2);
1053  }
1054  }
1055 
1056  // Remove the temporary file so the md5 hash is accurate.
1057  unlink($tmpfile);
1058  }
1059 
1060  return $return;
1061 }
1062 
1063 /**
1064  * @defgroup commandprocessing Command processing functions.
1065  * @{
1066  *
1067  * These functions manage command processing by the
1068  * main function in drush.php.
1069  */
1070 
1071 /**
1072  * Handle any command preprocessing that may need to be done, including
1073  * potentially redispatching the command immediately (e.g. for remote
1074  * commands).
1075  *
1076  * @return
1077  * TRUE if the command was handled remotely.
1078  */
1080  $interactive = drush_get_option('interactive', FALSE);
1081 
1082  // The command will be executed remotely if the --remote-host flag
1083  // is set; note that if a site alias is provided on the command line,
1084  // and the site alias references a remote server, then the --remote-host
1085  // option will be set when the site alias is processed.
1086  // @see drush_sitealias_check_arg
1087  $remote_host = drush_get_option('remote-host');
1088  // Get the command early so that we can allow commands to directly handle remote aliases if they wish
1089  $command = drush_parse_command();
1091 
1092  // If the command sets the 'strict-option-handling' flag, then we will remove
1093  // any cli options that appear after the command name from the 'cli' context.
1094  // The cli options that appear before the command name are stored in the
1095  // 'DRUSH_GLOBAL_CLI_OPTIONS' context, so we will just overwrite the cli context
1096  // with this, after doing the neccessary fixup from short-form to long-form options.
1097  // After we do that, we put back any local drush options identified by $command['options'].
1098  if (is_array($command) && !empty($command['strict-option-handling'])) {
1099  $cli_options = drush_get_context('DRUSH_GLOBAL_CLI_OPTIONS', array());
1100  // Now we are going to sort out any options that exist in $command['options'];
1101  // we will remove these from DRUSH_COMMAND_ARGS and put them back into the
1102  // cli options.
1103  $cli_context = drush_get_context('cli');
1104  $remove_from_command_args = array();
1105  foreach ($command['options'] as $option => $info) {
1106  if (array_key_exists($option, $cli_context)) {
1107  $cli_options[$option] = $cli_context[$option];
1108  $remove_from_command_args[$option] = $option;
1109  }
1110  }
1111  if (!empty($remove_from_command_args)) {
1112  $drush_command_args = array();
1113  foreach (drush_get_context('DRUSH_COMMAND_ARGS') as $arg) {
1114  if (!_drush_should_remove_command_arg($arg, $remove_from_command_args)) {
1115  $drush_command_args[] = $arg;
1116  }
1117  }
1118  drush_set_context('DRUSH_COMMAND_ARGS', $drush_command_args);
1119  }
1120  drush_expand_short_form_options($cli_options);
1121  drush_set_context('cli', $cli_options);
1123  }
1124  // If the command sets the 'handle-remote-commands' flag, then we will short-circuit
1125  // remote command dispatching and site-list command dispatching, and always let
1126  // the command handler run on the local machine.
1127  if (is_array($command) && !empty($command['handle-remote-commands'])) {
1128  return FALSE;
1129  }
1130  if (isset($remote_host)) {
1131  $args = drush_get_arguments();
1132  $command_name = array_shift($args);
1133  $remote_user = drush_get_option('remote-user');
1134 
1135  // Force interactive mode if there is a single remote target. #interactive is added by drush_do_command_redispatch
1136  $user_interactive = drush_get_option('interactive');
1137  drush_set_option('interactive', TRUE);
1138  $values = drush_do_command_redispatch(is_array($command) ? $command : $command_name, $args, $remote_host, $remote_user, $user_interactive);
1139  // In 'interactive' mode, $values is the result code from drush_shell_proc_open.
1140  // @todo: in _drush_backend_invoke, return array('error_status' => $ret) instead for uniformity.
1141  if (!is_array($values) && ($values != 0)) {
1142  // Force an error result code. Note that drush_shutdown() will still run.
1143  drush_set_context('DRUSH_EXECUTION_COMPLETED', TRUE);
1144  exit($values);
1145  }
1146  return TRUE;
1147  }
1148  // If the --site-list flag is set, then we will execute the specified
1149  // command once for every site listed in the site list.
1150  $site_list = drush_get_option('site-list');
1151  if (isset($site_list)) {
1152  if (!is_array($site_list)) {
1153  $site_list = explode(',', $site_list);
1154  }
1155  $site_record = array('site-list' => $site_list);
1156  $args = drush_get_arguments();
1157 
1158  if (!drush_get_context('DRUSH_SIMULATE') && !$interactive && !drush_get_context('DRUSH_AFFIRMATIVE') && !drush_get_context('DRUSH_QUIET')) {
1159  drush_print(dt("You are about to execute '!command' non-interactively (--yes forced) on all of the following targets:", array('!command' => implode(" ", $args))));
1160  foreach ($site_list as $one_destination) {
1161  drush_print(dt(' !target', array('!target' => $one_destination)));
1162  }
1163 
1164  if (drush_confirm('Continue? ') === FALSE) {
1165  drush_user_abort();
1166  return TRUE;
1167  }
1168  }
1169  $command_name = array_shift($args);
1170  $multi_options = drush_get_context('cli');
1171  $backend_options = array();
1172  if (drush_get_option('pipe') || drush_get_option('interactive')) {
1173  $backend_options['interactive'] = TRUE;
1174  }
1175  if (drush_get_option('no-label', FALSE)) {
1176  $backend_options['no-label'] = TRUE;
1177  }
1178  // If the user specified a format, try to look up the
1179  // default list separator for the specified format.
1180  // If the user did not specify a different label separator,
1181  // then pass in the default as an option, so that the
1182  // separator between the items in the list and the site
1183  // name will be consistent.
1184  $format = drush_get_option('format', FALSE);
1185  if ($format && !array_key_exists('label-separator', $multi_options)) {
1186  $formatter = drush_load_engine('outputformat', $format);
1187  if ($formatter) {
1188  $list_separator = $formatter->get_info('list-separator');
1189  if ($list_separator) {
1190  $multi_options['label-separator'] = $list_separator;
1191  }
1192  }
1193  }
1194  $values = drush_invoke_process($site_record, $command_name, $args, $multi_options, $backend_options);
1195  return TRUE;
1196  }
1197  return FALSE;
1198 }
1199 
1200 /**
1201  * Determine whether or not an argument should be removed from the
1202  * DRUSH_COMMAND_ARGS context. This method is used when a Drush
1203  * command has set the 'strict-option-handling' flag indicating
1204  * that it will pass through all commandline arguments and any
1205  * additional options (not known to Drush) to some shell command.
1206  *
1207  * Take as an example the following call to core-rsync:
1208  *
1209  * drush --yes core-rsync -v -az --exclude-paths='.git:.svn' local-files/ @site:%files
1210  *
1211  * In this instance:
1212  *
1213  * --yes is a global Drush option
1214  *
1215  * -v is an rsync option. It will make rsync run in verbose mode,
1216  * but will not make Drush run in verbose mode due to the fact that
1217  * core-rsync sets the 'strict-option-handling' flag.
1218  *
1219  * --exclude-paths is a local Drush option. It will be converted by
1220  * Drush into --exclude='.git' and --exclude='.svn', and then passed
1221  * on to the rsync command.
1222  *
1223  * The parameter $arg passed to this function is one of the elements
1224  * of DRUSH_COMMAND_ARGS. It will have values such as:
1225  * -v
1226  * -az
1227  * --exclude-paths='.git:.svn'
1228  * local-files/
1229  * @site:%files
1230  *
1231  * Our job in this function is to determine if $arg should be removed
1232  * by virtue of appearing in $removal_list. $removal_list is an array
1233  * that will contain values such as 'exclude-paths'. Both the key and
1234  * the value of $removal_list is the same.
1235  */
1236 function _drush_should_remove_command_arg($arg, $removal_list) {
1237  foreach ($removal_list as $candidate) {
1238  if (($arg == "-$candidate") ||
1239  ($arg == "--$candidate") ||
1240  (substr($arg,0,strlen($candidate)+3) == "--$candidate=") ) {
1241  return TRUE;
1242  }
1243  }
1244  return FALSE;
1245 }
1246 
1247 /**
1248  * Used by functions that operate on lists of sites, moving
1249  * information from the source to the destination. Currenlty
1250  * this includes 'drush rsync' and 'drush sql sync'.
1251  */
1252 function drush_do_multiple_command($command, $source_record, $destination_record, $allow_single_source = FALSE) {
1253  $is_multiple_command = FALSE;
1254 
1255  if ((($allow_single_source == TRUE) || array_key_exists('site-list', $source_record)) && array_key_exists('site-list', $destination_record)) {
1256  $is_multiple_command = TRUE;
1257  $source_path = array_key_exists('path-component', $source_record) ? $source_record['path-component'] : '';
1258  $destination_path = array_key_exists('path-component', $destination_record) ? $destination_record['path-component'] : '';
1259 
1260  $target_list = array_values(drush_sitealias_resolve_sitelist($destination_record));
1261  if (array_key_exists('site-list', $source_record)) {
1262  $source_list = array_values(drush_sitealias_resolve_sitelist($source_record));
1263 
1264  if (drush_sitealias_check_lists_alignment($source_list, $target_list) === FALSE) {
1265  if (array_key_exists('unordered-list', $source_record) || array_key_exists('unordered-list', $destination_record)) {
1266  drush_sitelist_align_lists($source_list, $target_list, $aligned_source, $aligned_target);
1267  $source_list = $aligned_source;
1268  $target_list = $aligned_target;
1269  }
1270  }
1271  }
1272  else {
1273  $source_list = array_fill(0, count($target_list), $source_record);
1274  }
1275 
1276  if (!drush_get_context('DRUSH_SIMULATE')) {
1277  drush_print(dt('You are about to !command between all of the following targets:', array('!command' => $command)));
1278  $i = 0;
1279  foreach ($source_list as $one_source) {
1280  $one_target = $target_list[$i];
1281  ++$i;
1282  drush_print(dt(' !source will overwrite !target', array('!source' => drush_sitealias_alias_record_to_spec($one_source) . $source_path, '!target' => drush_sitealias_alias_record_to_spec($one_target) . $destination_path)));
1283  }
1284 
1285  if (drush_confirm('Continue? ') === FALSE) {
1286  return drush_user_abort();
1287  }
1288  }
1289 
1290  $data = drush_redispatch_get_options();
1291  $i = 0;
1292  foreach ($source_list as $one_source) {
1293  $one_target = $target_list[$i];
1294  ++$i;
1295 
1296  $source_spec = drush_sitealias_alias_record_to_spec($one_source);
1297  $target_spec = drush_sitealias_alias_record_to_spec($one_target);
1298 
1299  drush_log(dt('Begin do_multiple !command via backend invoke', array('!command' => $command)));
1300  $values = drush_invoke_process('@self', $command, array($source_spec . $source_path, $target_spec . $destination_path), $data);
1301  drush_log(dt('Backend invoke is complete'));
1302  }
1303  }
1304 
1305  return $is_multiple_command;
1306 }
1307 
1308 /**
1309  * Run a command on the site specified by the provided command record.
1310  *
1311  * The standard function that provides this service is called
1312  * drush_invoke_process. Please call the standard function.
1313  *
1314  * @param backend_options
1315  * TRUE - integrate errors
1316  * FALSE - do not integrate errors
1317  * array - @see drush_backend_invoke_concurrent
1318  *
1319 function drush_do_site_command($site_record, $command, $args = array(), $command_options = array(), $backend_options = FALSE) {
1320  return drush_invoke_process($site_record, $command, $args, $command_options, $backend_options);
1321 }
1322  */
1323 
1324 /**
1325  * Redispatch the specified command using the same
1326  * options that were passed to this invocation of drush.
1327  */
1328 function drush_do_command_redispatch($command, $args = array(), $remote_host = NULL, $remote_user = NULL, $drush_path = NULL, $user_interactive = FALSE) {
1329  $additional_global_options = array();
1330  $command_options = drush_redispatch_get_options();
1331  if (is_array($command)) {
1332  $command_name = $command['command'];
1333  // If we are executing a remote command that uses strict option handling,
1334  // then mark all of the options in the alias context as global, so that they
1335  // will appear before the command name.
1336  if (!empty($command['strict-option-handling'])) {
1337  foreach(drush_get_context('alias') as $alias_key => $alias_value) {
1338  if (array_key_exists($alias_key, $command_options) && !array_key_exists($alias_key, $command['options'])) {
1339  $additional_global_options[$alias_key] = $alias_value;
1340  }
1341  }
1342  }
1343  }
1344  else {
1345  $command_name = $command;
1346  }
1347  // If the path to drush was supplied, then use it to invoke the new command.
1348  if ($drush_path == NULL) {
1349  $drush_path = drush_get_option('drush-script');
1350  if (!isset($drush_path)) {
1351  $drush_folder = drush_get_option('drush');
1352  if (isset($drush)) {
1353  $drush_path = $drush_folder . '/drush';
1354  }
1355  }
1356  }
1357  $backend_options = array('drush-script' => $drush_path, 'remote-host' => $remote_host, 'remote-user' => $remote_user, 'integrate' => TRUE, 'additional-global-options' => $additional_global_options);
1358  // Set the tty if requested, if the command necessitates it,
1359  // or if the user explicitly asks for interactive mode, but
1360  // not if interactive mode is forced. tty implies interactive
1361  if (drush_get_option('tty') || $user_interactive || !empty($command['remote-tty'])) {
1362  $backend_options['#tty'] = TRUE;
1363  $backend_options['interactive'] = TRUE;
1364  }
1365  elseif (drush_get_option('interactive')) {
1366  $backend_options['interactive'] = TRUE;
1367  }
1368 
1369  // Run the command in a new process.
1370  drush_log(dt('Begin redispatch via drush_invoke_process().'));
1371  $values = drush_invoke_process('@self', $command_name, $args, $command_options, $backend_options);
1372  drush_log(dt('End redispatch via drush_invoke_process().'));
1373 
1374  return $values;
1375 }
1376 
1377 
1378 /**
1379  * @} End of "defgroup commandprocessing".
1380  */
1381 
1382 /**
1383  * @defgroup logging Logging information to be provided as output.
1384  * @{
1385  *
1386  * These functions are primarily for diagnostic purposes, but also provide an overview of tasks that were taken
1387  * by drush.
1388  */
1389 
1390 /**
1391  * Add a log message to the log history.
1392  *
1393  * This function calls the callback stored in the 'DRUSH_LOG_CALLBACK' context with
1394  * the resulting entry at the end of execution.
1395  *
1396  * This allows you to replace it with custom logging implementations if needed,
1397  * such as logging to a file or logging to a database (drupal or otherwise).
1398  *
1399  * The default callback is the _drush_print_log() function with prints the messages
1400  * to the shell.
1401  *
1402  * @param message
1403  * String containing the message to be logged.
1404  * @param type
1405  * The type of message to be logged. Common types are 'warning', 'error', 'success' and 'notice'.
1406  * A type of 'failed' can also be supplied to flag as an 'error'.
1407  * A type of 'ok' or 'completed' can also be supplied to flag as a 'success'.
1408  * If you want your log messages to print to screen without the user entering
1409  * a -v or --verbose flag, use type 'ok', this prints log messages out to
1410  * STDERR, which prints to screen (unless you have redirected it). All other
1411  * types of messages will be assumed to be notices.
1412  */
1413 function drush_log($message, $type = 'notice', $error = null) {
1414  $log =& drush_get_context('DRUSH_LOG', array());
1415  $callback = drush_get_context('DRUSH_LOG_CALLBACK', '_drush_print_log');
1416  $entry = array(
1417  'type' => $type,
1418  'message' => $message,
1419  'timestamp' => microtime(TRUE),
1420  'memory' => memory_get_usage(),
1421  );
1422  $entry['error'] = $error;
1423  $log[] = $entry;
1424  drush_backend_packet('log', $entry);
1425 
1426  return $callback($entry);
1427 }
1428 
1429 /**
1430  * Backend command callback. Add a log message to the log history.
1431  *
1432  * @param entry
1433  * The log entry.
1434  */
1435 function drush_backend_packet_log($entry, $backend_options) {
1436  if (!$backend_options['log']) {
1437  return;
1438  }
1439  if (!is_string($entry['message'])) {
1440  $entry['message'] = implode("\n", (array)$entry['message']);
1441  }
1442  $entry['message'] = $entry['message'];
1443  $log =& drush_get_context('DRUSH_LOG', array());
1444  $log[] = $entry;
1445  // Yes, this looks odd, but we might in fact be a backend command
1446  // that ran another backend command.
1447  drush_backend_packet('log', $entry);
1448  if (array_key_exists('#output-label', $backend_options)) {
1449  $entry['message'] = $backend_options['#output-label'] . $entry['message'];
1450  }
1451 
1452  // If integrate is FALSE, then log messages are stored in DRUSH_LOG,
1453  // but are -not- printed to the console.
1454  if ($backend_options['integrate']) {
1455  $callback = drush_get_context('DRUSH_LOG_CALLBACK', '_drush_print_log');
1456  return $callback($entry);
1457  }
1458 }
1459 
1460 /**
1461  * Retrieve the log messages from the log history
1462  *
1463  * @return
1464  * Entire log history
1465  */
1466 function drush_get_log() {
1467  return drush_get_context('DRUSH_LOG', array());
1468 }
1469 
1470 /**
1471  * Run print_r on a variable and log the output.
1472  */
1473 function dlm($object) {
1474  drush_log(print_r($object, TRUE));
1475 }
1476 
1477 /**
1478  * Display the pipe output for the current request.
1479  */
1480 function drush_pipe_output() {
1481  $pipe = drush_get_context('DRUSH_PIPE_BUFFER');
1482  if (!empty($pipe)) {
1483  drush_print_r($pipe, NULL, FALSE);
1484  }
1485 }
1486 
1487 /**
1488  * Display the log message
1489  *
1490  * By default, only warnings and errors will be displayed, if 'verbose' is specified, it will also display notices.
1491  *
1492  * @param
1493  * The associative array for the entry.
1494  *
1495  * @return
1496  * False in case of an error or failed type, True in all other cases.
1497  */
1498 function _drush_print_log($entry) {
1499  if (drush_get_context('DRUSH_NOCOLOR')) {
1500  $red = "[%s]";
1501  $yellow = "[%s]";
1502  $green = "[%s]";
1503  }
1504  else {
1505  $red = "\033[31;40m\033[1m[%s]\033[0m";
1506  $yellow = "\033[1;33;40m\033[1m[%s]\033[0m";
1507  $green = "\033[1;32;40m\033[1m[%s]\033[0m";
1508  }
1509 
1510  $verbose = drush_get_context('DRUSH_VERBOSE');
1511  $debug = drush_get_context('DRUSH_DEBUG');
1512 
1513  $return = TRUE;
1514  switch ($entry['type']) {
1515  case 'warning' :
1516  case 'cancel' :
1517  $type_msg = sprintf($yellow, $entry['type']);
1518  break;
1519  case 'failed' :
1520  case 'error' :
1521  $type_msg = sprintf($red, $entry['type']);
1522  $return = FALSE;
1523  break;
1524  case 'ok' :
1525  case 'completed' :
1526  case 'success' :
1527  case 'status':
1528  // In quiet mode, suppress progress messages
1529  if (drush_get_context('DRUSH_QUIET')) {
1530  return TRUE;
1531  }
1532  $type_msg = sprintf($green, $entry['type']);
1533  break;
1534  case 'notice' :
1535  case 'message' :
1536  case 'info' :
1537  if (!$verbose) {
1538  // print nothing. exit cleanly.
1539  return TRUE;
1540  }
1541  $type_msg = sprintf("[%s]", $entry['type']);
1542  break;
1543  default :
1544  if (!$debug) {
1545  // print nothing. exit cleanly.
1546  return TRUE;
1547  }
1548  $type_msg = sprintf("[%s]", $entry['type']);
1549  break;
1550  }
1551 
1552  // When running in backend mode, log messages are not displayed, as they will
1553  // be returned in the JSON encoded associative array.
1554  if (drush_get_context('DRUSH_BACKEND')) {
1555  return $return;
1556  }
1557 
1558  $columns = drush_get_context('DRUSH_COLUMNS', 80);
1559 
1560  $width[1] = 11;
1561  // Append timer and memory values.
1562  if ($debug) {
1563  $timer = sprintf('[%s sec, %s]', round($entry['timestamp']-DRUSH_REQUEST_TIME, 2), drush_format_size($entry['memory']));
1564  $entry['message'] = $entry['message'] . ' ' . $timer;
1565  }
1566 
1567  $width[0] = ($columns - 11);
1568 
1569  $format = sprintf("%%-%ds%%%ds", $width[0], $width[1]);
1570 
1571  // Place the status message right aligned with the top line of the error message.
1572  $message = wordwrap($entry['message'], $width[0]);
1573  $lines = explode("\n", $message);
1574  $lines[0] = sprintf($format, $lines[0], $type_msg);
1575  $message = implode("\n", $lines);
1576  drush_print($message, 0, STDERR);
1577  return $return;
1578 }
1579 
1580 // Print all timers for the request.
1581 function drush_print_timers() {
1582  global $timers;
1583  $temparray = array();
1584  foreach ((array)$timers as $name => $timerec) {
1585  // We have to use timer_read() for active timers, and check the record for others
1586  if (isset($timerec['start'])) {
1587  $temparray[$name] = timer_read($name);
1588  }
1589  else {
1590  $temparray[$name] = $timerec['time'];
1591  }
1592  }
1593  // Go no farther if there were no timers
1594  if (count($temparray) > 0) {
1595  // Put the highest cumulative times first
1596  arsort($temparray);
1597  $table = array();
1598  $table[] = array('Timer', 'Cum (sec)', 'Count', 'Avg (msec)');
1599  foreach ($temparray as $name => $time) {
1600  $cum = round($time/1000, 3);
1601  $count = $timers[$name]['count'];
1602  if ($count > 0) {
1603  $avg = round($time/$count, 3);
1604  }
1605  else {
1606  $avg = 'N/A';
1607  }
1608  $table[] = array($name, $cum, $count, $avg);
1609  }
1610  drush_print_table($table, TRUE, array(), STDERR);
1611  }
1612 }
1613 
1614 /**
1615 * Turn drupal_set_message errors into drush_log errors
1616 */
1618  if (function_exists('drupal_get_messages')) {
1619 
1620  $messages = drupal_get_messages(NULL, TRUE);
1621 
1622  if (array_key_exists('error', $messages)) {
1623  //Drupal message errors.
1624  foreach ((array) $messages['error'] as $error) {
1625  $error = strip_tags($error);
1626  $header = preg_match('/^warning: Cannot modify header information - headers already sent by /i', $error);
1627  $session = preg_match('/^warning: session_start\(\): Cannot send session /i', $error);
1628  if ($header || $session) {
1629  //These are special cases for an unavoidable warnings
1630  //that are generated by generating output before Drupal is bootstrapped.
1631  //or sending a session cookie (seems to affect d7 only?)
1632  //Simply ignore them.
1633  continue;
1634  }
1635  elseif (preg_match('/^warning:/i', $error)) {
1636  drush_log(preg_replace('/^warning: /i', '', $error), 'warning');
1637  }
1638  elseif (preg_match('/^notice:/i', $error)) {
1639  drush_log(preg_replace('/^notice: /i', '', $error), 'notice');
1640  }
1641  elseif (preg_match('/^user warning:/i', $error)) {
1642  // This is a special case. PHP logs sql errors as 'User Warnings', not errors.
1643  drush_set_error('DRUSH_DRUPAL_ERROR_MESSAGE', preg_replace('/^user warning: /i', '', $error));
1644  }
1645  else {
1646  drush_set_error('DRUSH_DRUPAL_ERROR_MESSAGE', $error);
1647  }
1648  }
1649  }
1650  unset($messages['error']);
1651 
1652  // Log non-error messages.
1653  foreach ($messages as $type => $items) {
1654  foreach ($items as $item) {
1655  drush_log(strip_tags($item), $type);
1656  }
1657  }
1658  }
1659 }
1660 
1661 // Copy of format_size() in Drupal.
1662 function drush_format_size($size, $langcode = NULL) {
1663  if ($size < DRUSH_KILOBYTE) {
1664  // format_plural() not always available.
1665  return dt('@count bytes', array('@count' => $size));
1666  }
1667  else {
1668  $size = $size / DRUSH_KILOBYTE; // Convert bytes to kilobytes.
1669  $units = array(
1670  dt('@size KB', array(), array('langcode' => $langcode)),
1671  dt('@size MB', array(), array('langcode' => $langcode)),
1672  dt('@size GB', array(), array('langcode' => $langcode)),
1673  dt('@size TB', array(), array('langcode' => $langcode)),
1674  dt('@size PB', array(), array('langcode' => $langcode)),
1675  dt('@size EB', array(), array('langcode' => $langcode)),
1676  dt('@size ZB', array(), array('langcode' => $langcode)),
1677  dt('@size YB', array(), array('langcode' => $langcode)),
1678  );
1679  foreach ($units as $unit) {
1680  if (round($size, 2) >= DRUSH_KILOBYTE) {
1681  $size = $size / DRUSH_KILOBYTE;
1682  }
1683  else {
1684  break;
1685  }
1686  }
1687  return str_replace('@size', round($size, 2), $unit);
1688  }
1689 }
1690 
1691 /**
1692  * @} End of "defgroup logging".
1693  */
1694 
1695 /**
1696  * @defgroup errorhandling Managing errors that occur in the Drush framework.
1697  * @{
1698  * Functions that manage the current error status of the Drush framework.
1699  *
1700  * These functions operate by maintaining a static variable that is a equal to the constant DRUSH_FRAMEWORK_ERROR if an
1701  * error has occurred.
1702  * This error code is returned at the end of program execution, and provide the shell or calling application with
1703  * more information on how to diagnose any problems that may have occurred.
1704  */
1705 
1706 /**
1707  * Set an error code for the error handling system.
1708  *
1709  * @param error
1710  * A text string identifying the type of error.
1711  *
1712  * @param message
1713  * Optional. Error message to be logged. If no message is specified, hook_drush_help will be consulted,
1714  * using a key of 'error:MY_ERROR_STRING'.
1715  *
1716  * @param $output_label
1717  * Optional. Label to prepend to the error message.
1718  *
1719  * @return
1720  * Always returns FALSE, to allow you to return with false in the calling functions,
1721  * such as <code>return drush_set_error('DRUSH_FRAMEWORK_ERROR')</code>
1722  */
1723 function drush_set_error($error, $message = null, $output_label = "") {
1724  $error_code =& drush_get_context('DRUSH_ERROR_CODE', DRUSH_SUCCESS);
1725  $error_code = DRUSH_FRAMEWORK_ERROR;
1726 
1727  $error_log =& drush_get_context('DRUSH_ERROR_LOG', array());
1728 
1729  if (is_numeric($error)) {
1730  $error = 'DRUSH_FRAMEWORK_ERROR';
1731  }
1732 
1733  $message = ($message) ? $message : drush_command_invoke_all('drush_help', 'error:' . $error);
1734 
1735  if (is_array($message)) {
1736  $message = implode("\n", $message);
1737  }
1738 
1739  $error_log[$error][] = $message;
1740  if (!drush_backend_packet('set_error', array('error' => $error, 'message' => $message))) {
1741  drush_log(($message) ? $output_label . $message : $output_label . $error, 'error', $error);
1742  }
1743 
1744  return FALSE;
1745 }
1746 
1747 /**
1748  * Return the current error handling status
1749  *
1750  * @return
1751  * The current aggregate error status
1752  */
1753 function drush_get_error() {
1754  return drush_get_context('DRUSH_ERROR_CODE', DRUSH_SUCCESS);
1755 }
1756 
1757 /**
1758  * Return the current list of errors that have occurred.
1759  *
1760  * @return
1761  * An associative array of error messages indexed by the type of message.
1762  */
1764  return drush_get_context('DRUSH_ERROR_LOG', array());
1765 }
1766 
1767 /**
1768  * Check if a specific error status has been set.
1769  *
1770  * @param error
1771  * A text string identifying the error that has occurred.
1772  * @return
1773  * TRUE if the specified error has been set, FALSE if not
1774  */
1775 function drush_cmp_error($error) {
1776  $error_log = drush_get_error_log();
1777 
1778  if (is_numeric($error)) {
1779  $error = 'DRUSH_FRAMEWORK_ERROR';
1780  }
1781 
1782  return array_key_exists($error, $error_log);
1783 }
1784 
1785 /**
1786  * Clear error context.
1787  */
1788 function drush_clear_error() {
1789  drush_set_context('DRUSH_ERROR_CODE', DRUSH_SUCCESS);
1790 }
1791 
1792 /**
1793  * Exit due to user declining a confirmation prompt.
1794  *
1795  * Usage: return drush_user_abort();
1796  */
1797 function drush_user_abort($msg = NULL) {
1798  drush_set_context('DRUSH_USER_ABORT', TRUE);
1799  drush_log($msg ? $msg : dt('Aborting.'), 'cancel');
1800  return FALSE;
1801 }
1802 
1803 /**
1804  * Turn PHP error handling off.
1805  *
1806  * This is commonly used while bootstrapping Drupal for install
1807  * or updates.
1808  *
1809  * This also records the previous error_reporting setting, in
1810  * case it wasn't recorded previously.
1811  *
1812  * @see drush_errors_off()
1813  */
1814 function drush_errors_off() {
1815  drush_get_context('DRUSH_ERROR_REPORTING', error_reporting(0));
1816  ini_set('display_errors', FALSE);
1817 }
1818 
1819 /**
1820  * Turn PHP error handling on.
1821  *
1822  * We default to error_reporting() here just in
1823  * case drush_errors_on() is called before drush_errors_off() and
1824  * the context is not yet set.
1825  *
1826  * @arg $errors string
1827  * The default error level to set in drush. This error level will be
1828  * carried through further drush_errors_on()/off() calls even if not
1829  * provided in later calls.
1830  *
1831  * @see error_reporting()
1832  * @see drush_errors_off()
1833  */
1834 function drush_errors_on($errors = null) {
1835  if (!isset($errors)) {
1836  $errors = error_reporting();
1837  }
1838  else {
1839  drush_set_context('DRUSH_ERROR_REPORTING', $errors);
1840  }
1841  error_reporting(drush_get_context('DRUSH_ERROR_REPORTING', $errors));
1842  ini_set('display_errors', TRUE);
1843 }
1844 
1845 /**
1846  * @} End of "defgroup errorhandling".
1847  */
1848 
1849 /**
1850  * Get the PHP memory_limit value in bytes.
1851  */
1853  $value = trim(ini_get('memory_limit'));
1854  $last = strtolower($value[strlen($value)-1]);
1855  switch ($last) {
1856  case 'g':
1857  $value *= DRUSH_KILOBYTE;
1858  case 'm':
1859  $value *= DRUSH_KILOBYTE;
1860  case 'k':
1861  $value *= DRUSH_KILOBYTE;
1862  }
1863 
1864  return $value;
1865 }
1866 
1867 /**
1868  * Unset the named key anywhere in the provided
1869  * data structure.
1870  */
1871 function drush_unset_recursive(&$data, $unset_key) {
1872  if (!empty($data) && is_array($data)) {
1873  unset($data[$unset_key]);
1874  foreach ($data as $key => $value) {
1875  if (is_array($value)) {
1876  drush_unset_recursive($data[$key], $unset_key);
1877  }
1878  }
1879  }
1880 }
1881 
1882 /**
1883  * Return a list of VCSs reserved files and directories.
1884  */
1886  static $files = FALSE;
1887 
1888  if (!$files) {
1889  // Also support VCSs that are not drush vc engines.
1890  $files = array('.git', '.gitignore', '.hg', '.hgignore', '.hgrags');
1891  $engine_info = drush_get_engines('version_control');
1892  $vcs = array_keys($engine_info['engines']);
1893  foreach ($vcs as $name) {
1894  $version_control = drush_include_engine('version_control', $name);
1895  $files = array_merge($files, $version_control->reserved_files());
1896  }
1897  }
1898 
1899  return $files;
1900 }
1901 
1902 /**
1903  * Generate a random alphanumeric password. Copied from user.module.
1904  */
1905 function drush_generate_password($length = 10) {
1906  // This variable contains the list of allowable characters for the
1907  // password. Note that the number 0 and the letter 'O' have been
1908  // removed to avoid confusion between the two. The same is true
1909  // of 'I', 1, and 'l'.
1910  $allowable_characters = 'abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789';
1911 
1912  // Zero-based count of characters in the allowable list:
1913  $len = strlen($allowable_characters) - 1;
1914 
1915  // Declare the password as a blank string.
1916  $pass = '';
1917 
1918  // Loop the number of times specified by $length.
1919  for ($i = 0; $i < $length; $i++) {
1920 
1921  // Each iteration, pick a random character from the
1922  // allowable string and append it to the password:
1923  $pass .= $allowable_characters[mt_rand(0, $len)];
1924  }
1925 
1926  return $pass;
1927 }
1928 
1929 /**
1930  * Form an associative array from a linear array.
1931  *
1932  * This function walks through the provided array and constructs an associative
1933  * array out of it. The keys of the resulting array will be the values of the
1934  * input array. The values will be the same as the keys unless a function is
1935  * specified, in which case the output of the function is used for the values
1936  * instead.
1937  *
1938  * @param $array
1939  * A linear array.
1940  * @param $function
1941  * A name of a function to apply to all values before output.
1942  *
1943  * @return
1944  * An associative array.
1945  */
1946 function drush_map_assoc($array, $function = NULL) {
1947  // array_combine() fails with empty arrays:
1949  $array = !empty($array) ? array_combine($array, $array) : array();
1950  if (is_callable($function)) {
1951  $array = array_map($function, $array);
1952  }
1953  return $array;
1954 }
1955 /**
1956  * Clears completion caches.
1957  *
1958  * If called with no parameters the entire complete cache will be cleared.
1959  * If called with just the $type parameter the global cache for that type will
1960  * be cleared (in the site context, if any). If called with both $type and
1961  * $command parameters the command cache of that type will be cleared (in the
1962  * site context, if any).
1963  *
1964  * This is included in drush.inc as complete.inc is only loaded conditionally.
1965  *
1966  * @param $type
1967  * The completion type (optional).
1968  * @param $command
1969  * The command name (optional), if command specific cache is to be cleared.
1970  * If specifying a command, $type is not optional.
1971  */
1972 function drush_complete_cache_clear($type = NULL, $command = NULL) {
1973  require_once DRUSH_BASE_PATH . '/includes/complete.inc';
1974  if ($type) {
1975  drush_cache_clear_all(drush_complete_cache_cid($type, $command), 'complete');
1976  return;
1977  }
1978  // No type or command, so clear the entire complete cache.
1979  drush_cache_clear_all('*', 'complete', TRUE);
1980 }

File

doxygen/html/drush_8inc_source.html
View source
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/xhtml;charset=UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=9"/>
<title>Drush: includes/drush.inc Source File</title>
<link href="tabs.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="jquery.js"></script>
<script type="text/javascript" src="dynsections.js"></script>
<link href="search/search.css" rel="stylesheet" type="text/css"/>
<script type="text/javascript" src="search/search.js"></script>
<script type="text/javascript">
  $(document).ready(function() { searchBox.OnSelectItem(0); });
</script>
<link href="doxygen.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="top"><!-- do not remove this div, it is closed by doxygen! -->
<div id="titlearea">
<table cellspacing="0" cellpadding="0">
 <tbody>
 <tr style="height: 56px;">
  <td style="padding-left: 0.5em;">
   <div id="projectname">Drush
   </div>
  </td>
 </tr>
 </tbody>
</table>
</div>
<!-- end header part -->
<!-- Generated by Doxygen 1.8.1.2 -->
<script type="text/javascript">
var searchBox = new SearchBox("searchBox", "search",false,'Search');
</script>
  <div id="navrow1" class="tabs">
    <ul class="tablist">
      <li><a href="index.html"><span>Main&#160;Page</span></a></li>
      <li><a href="pages.html"><span>Related&#160;Pages</span></a></li>
      <li><a href="modules.html"><span>Modules</span></a></li>
      <li><a href="annotated.html"><span>Classes</span></a></li>
      <li class="current"><a href="files.html"><span>Files</span></a></li>
      <li>
        <div id="MSearchBox" class="MSearchBoxInactive">
        <span class="left">
          <img id="MSearchSelect" src="search/mag_sel.png"
               onmouseover="return searchBox.OnSearchSelectShow()"
               onmouseout="return searchBox.OnSearchSelectHide()"
               alt=""/>
          <input type="text" id="MSearchField" value="Search" accesskey="S"
               onfocus="searchBox.OnSearchFieldFocus(true)" 
               onblur="searchBox.OnSearchFieldFocus(false)" 
               onkeyup="searchBox.OnSearchFieldChange(event)"/>
          </span><span class="right">
            <a id="MSearchClose" href="javascript:searchBox.CloseResultsWindow()"><img id="MSearchCloseImg" border="0" src="search/close.png" alt=""/></a>
          </span>
        </div>
      </li>
    </ul>
  </div>
  <div id="navrow2" class="tabs2">
    <ul class="tablist">
      <li><a href="files.html"><span>File&#160;List</span></a></li>
      <li><a href="globals.html"><span>File&#160;Members</span></a></li>
    </ul>
  </div>
<!-- window showing the filter options -->
<div id="MSearchSelectWindow"
     onmouseover="return searchBox.OnSearchSelectShow()"
     onmouseout="return searchBox.OnSearchSelectHide()"
     onkeydown="return searchBox.OnSearchSelectKey(event)">
<a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(0)"><span class="SelectionMark">&#160;</span>All</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(1)"><span class="SelectionMark">&#160;</span>Classes</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(2)"><span class="SelectionMark">&#160;</span>Files</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(3)"><span class="SelectionMark">&#160;</span>Functions</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(4)"><span class="SelectionMark">&#160;</span>Variables</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(5)"><span class="SelectionMark">&#160;</span>Groups</a><a class="SelectItem" href="javascript:void(0)" onclick="searchBox.OnSelectItem(6)"><span class="SelectionMark">&#160;</span>Pages</a></div>

<!-- iframe showing the search results (closed by default) -->
<div id="MSearchResultsWindow">
<iframe src="javascript:void(0)" frameborder="0" 
        name="MSearchResults" id="MSearchResults">
</iframe>
</div>

<div id="nav-path" class="navpath">
  <ul>
<li class="navelem"><a class="el" href="dir_09e761304027c904456130627fd4dcf5.html">includes</a></li>  </ul>
</div>
</div><!-- top -->
<div class="header">
  <div class="headertitle">
<div class="title">drush.inc</div>  </div>
</div><!--header-->
<div class="contents">
<a href="drush_8inc.html">Go to the documentation of this file.</a><div class="fragment"><div class="line"><a name="l00001"></a><span class="lineno">    1</span>&#160;&lt;?php</div>
<div class="line"><a name="l00002"></a><span class="lineno">    2</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00003"></a><span class="lineno">    3</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00004"></a><span class="lineno">    4</span>&#160;<span class="comment"> * @file</span></div>
<div class="line"><a name="l00005"></a><span class="lineno">    5</span>&#160;<span class="comment"> * The drush API implementation and helpers.</span></div>
<div class="line"><a name="l00006"></a><span class="lineno">    6</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00007"></a><span class="lineno">    7</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00008"></a><span class="lineno">    8</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00009"></a><span class="lineno">    9</span>&#160;<span class="comment">* @name Error status definitions</span></div>
<div class="line"><a name="l00010"></a><span class="lineno">   10</span>&#160;<span class="comment">* @{</span></div>
<div class="line"><a name="l00011"></a><span class="lineno">   11</span>&#160;<span class="comment">* Error code definitions for interpreting the current error status.</span></div>
<div class="line"><a name="l00012"></a><span class="lineno">   12</span>&#160;<span class="comment">* @see drush_set_error(), drush_get_error(), drush_get_error_log(), drush_cmp_error()</span></div>
<div class="line"><a name="l00013"></a><span class="lineno">   13</span>&#160;<span class="comment">*/</span></div>
<div class="line"><a name="l00014"></a><span class="lineno">   14</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00015"></a><span class="lineno">   15</span>&#160;<span class="comment">/** The command completed successfully. */</span></div>
<div class="line"><a name="l00016"></a><span class="lineno"><a class="code" href="drush_8inc.html#af1fd588cf6b6a3d51e8055408ee86635">   16</a></span>&#160;define(<span class="stringliteral">&#39;DRUSH_SUCCESS&#39;</span>, 0);<span class="comment"></span></div>
<div class="line"><a name="l00017"></a><span class="lineno">   17</span>&#160;<span class="comment">/** The command could not be completed because the framework has specified errors that have occured. */</span></div>
<div class="line"><a name="l00018"></a><span class="lineno"><a class="code" href="drush_8inc.html#a7959436c0614636c05192a563bd6cfb5">   18</a></span>&#160;define(<span class="stringliteral">&#39;DRUSH_FRAMEWORK_ERROR&#39;</span>, 1);<span class="comment"></span></div>
<div class="line"><a name="l00019"></a><span class="lineno">   19</span>&#160;<span class="comment">/** The command that was executed resulted in an application error,</span></div>
<div class="line"><a name="l00020"></a><span class="lineno">   20</span>&#160;<span class="comment">  The most commom causes for this is invalid PHP or a broken SSH</span></div>
<div class="line"><a name="l00021"></a><span class="lineno">   21</span>&#160;<span class="comment">  pipe when using drush_backend_invoke in a distributed manner. */</span></div>
<div class="line"><a name="l00022"></a><span class="lineno"><a class="code" href="drush_8inc.html#ad2cac2311a09943e8f911c2d13167c4a">   22</a></span>&#160;define(<span class="stringliteral">&#39;DRUSH_APPLICATION_ERROR&#39;</span>, 255);</div>
<div class="line"><a name="l00023"></a><span class="lineno">   23</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00024"></a><span class="lineno">   24</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00025"></a><span class="lineno">   25</span>&#160;<span class="comment"> * @} End of &quot;name Error status defintions&quot;.</span></div>
<div class="line"><a name="l00026"></a><span class="lineno">   26</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00027"></a><span class="lineno">   27</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00028"></a><span class="lineno">   28</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00029"></a><span class="lineno">   29</span>&#160;<span class="comment"> * The number of bytes in a kilobyte. Copied from Drupal.</span></div>
<div class="line"><a name="l00030"></a><span class="lineno">   30</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00031"></a><span class="lineno"><a class="code" href="drush_8inc.html#a0a75d4291b848dda33fab74050e0ab14">   31</a></span>&#160;define(<span class="stringliteral">&#39;DRUSH_KILOBYTE&#39;</span>, 1024);</div>
<div class="line"><a name="l00032"></a><span class="lineno">   32</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00033"></a><span class="lineno">   33</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00034"></a><span class="lineno">   34</span>&#160;<span class="comment"> * Default amount of time, in seconds, to cache downloads via</span></div>
<div class="line"><a name="l00035"></a><span class="lineno">   35</span>&#160;<span class="comment"> * drush_download_file(). One day is 86400 seconds.</span></div>
<div class="line"><a name="l00036"></a><span class="lineno">   36</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00037"></a><span class="lineno"><a class="code" href="drush_8inc.html#aa7401f966d8f78e341094bc304d56162">   37</a></span>&#160;define(<span class="stringliteral">&#39;DRUSH_CACHE_LIFETIME_DEFAULT&#39;</span>, 86400);</div>
<div class="line"><a name="l00038"></a><span class="lineno">   38</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00039"></a><span class="lineno">   39</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00040"></a><span class="lineno">   40</span>&#160;<span class="comment"> * Include a file, selecting a version specific file if available.</span></div>
<div class="line"><a name="l00041"></a><span class="lineno">   41</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00042"></a><span class="lineno">   42</span>&#160;<span class="comment"> * For example, if you pass the path &quot;/var/drush&quot; and the name</span></div>
<div class="line"><a name="l00043"></a><span class="lineno">   43</span>&#160;<span class="comment"> * &quot;update&quot; when bootstrapped on a Drupal 6 site it will first check for</span></div>
<div class="line"><a name="l00044"></a><span class="lineno">   44</span>&#160;<span class="comment"> * the presence of &quot;/var/drush/update_6.inc&quot; in include it if exists. If this</span></div>
<div class="line"><a name="l00045"></a><span class="lineno">   45</span>&#160;<span class="comment"> * file does NOT exist it will proceed and check for &quot;/var/drush/update.inc&quot;.</span></div>
<div class="line"><a name="l00046"></a><span class="lineno">   46</span>&#160;<span class="comment"> * If neither file exists, it will return FALSE.</span></div>
<div class="line"><a name="l00047"></a><span class="lineno">   47</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00048"></a><span class="lineno">   48</span>&#160;<span class="comment"> * @param $path</span></div>
<div class="line"><a name="l00049"></a><span class="lineno">   49</span>&#160;<span class="comment"> *   The path you want to search.</span></div>
<div class="line"><a name="l00050"></a><span class="lineno">   50</span>&#160;<span class="comment"> * @param $name</span></div>
<div class="line"><a name="l00051"></a><span class="lineno">   51</span>&#160;<span class="comment"> *   The file base name you want to include (not including a version suffix</span></div>
<div class="line"><a name="l00052"></a><span class="lineno">   52</span>&#160;<span class="comment"> *   or extension).</span></div>
<div class="line"><a name="l00053"></a><span class="lineno">   53</span>&#160;<span class="comment"> * @param $version</span></div>
<div class="line"><a name="l00054"></a><span class="lineno">   54</span>&#160;<span class="comment"> *   The version suffix you want to include (could be specific to the software</span></div>
<div class="line"><a name="l00055"></a><span class="lineno">   55</span>&#160;<span class="comment"> *   or platform your are connecting to) - defaults to the current Drupal core</span></div>
<div class="line"><a name="l00056"></a><span class="lineno">   56</span>&#160;<span class="comment"> *   major version.</span></div>
<div class="line"><a name="l00057"></a><span class="lineno">   57</span>&#160;<span class="comment"> * @param $extension</span></div>
<div class="line"><a name="l00058"></a><span class="lineno">   58</span>&#160;<span class="comment"> *   The extension - defaults to &quot;.inc&quot;.</span></div>
<div class="line"><a name="l00059"></a><span class="lineno">   59</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00060"></a><span class="lineno">   60</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00061"></a><span class="lineno">   61</span>&#160;<span class="comment"> *   TRUE if the file was found and included.</span></div>
<div class="line"><a name="l00062"></a><span class="lineno">   62</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00063"></a><span class="lineno"><a class="code" href="drush_8inc.html#a80ce43b30f833522f72180811dab5a3e">   63</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a80ce43b30f833522f72180811dab5a3e">drush_include</a>($path, $name, $version = NULL, $extension = <span class="stringliteral">&#39;inc&#39;</span>) {</div>
<div class="line"><a name="l00064"></a><span class="lineno">   64</span>&#160;  $version = ($version) ? $version : <a class="code" href="includes_2drupal_8inc.html#ad2ccab77d4bc8e7355186f26cd328ac0">drush_drupal_major_version</a>();</div>
<div class="line"><a name="l00065"></a><span class="lineno">   65</span>&#160;  $file = sprintf(<span class="stringliteral">&quot;%s/%s_%s.%s&quot;</span>, $path, str_replace(<span class="charliteral">&#39;-&#39;</span>, <span class="charliteral">&#39;_&#39;</span>, $name), $version, $extension);</div>
<div class="line"><a name="l00066"></a><span class="lineno">   66</span>&#160;  <span class="keywordflow">if</span> (file_exists($file)) {</div>
<div class="line"><a name="l00067"></a><span class="lineno">   67</span>&#160;    <span class="comment">//drush_log(dt(&#39;Including version specific file : @file&#39;, array(&#39;@file&#39; =&gt; $file)));</span></div>
<div class="line"><a name="l00068"></a><span class="lineno">   68</span>&#160;    include_once($file);</div>
<div class="line"><a name="l00069"></a><span class="lineno">   69</span>&#160;    <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00070"></a><span class="lineno">   70</span>&#160;  }</div>
<div class="line"><a name="l00071"></a><span class="lineno">   71</span>&#160;  $file = sprintf(<span class="stringliteral">&quot;%s/%s.%s&quot;</span>, $path, str_replace(<span class="charliteral">&#39;-&#39;</span>, <span class="charliteral">&#39;_&#39;</span>, $name), $extension);</div>
<div class="line"><a name="l00072"></a><span class="lineno">   72</span>&#160;  <span class="keywordflow">if</span> (file_exists($file)) {</div>
<div class="line"><a name="l00073"></a><span class="lineno">   73</span>&#160;    <span class="comment">//drush_log(dt(&#39;Including non-version specific file : @file&#39;, array(&#39;@file&#39; =&gt; $file)));</span></div>
<div class="line"><a name="l00074"></a><span class="lineno">   74</span>&#160;    include_once($file);</div>
<div class="line"><a name="l00075"></a><span class="lineno">   75</span>&#160;    <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00076"></a><span class="lineno">   76</span>&#160;  }</div>
<div class="line"><a name="l00077"></a><span class="lineno">   77</span>&#160;}</div>
<div class="line"><a name="l00078"></a><span class="lineno">   78</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00079"></a><span class="lineno">   79</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00080"></a><span class="lineno">   80</span>&#160;<span class="comment"> * Provide a version-specific class instance.</span></div>
<div class="line"><a name="l00081"></a><span class="lineno">   81</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00082"></a><span class="lineno">   82</span>&#160;<span class="comment"> * @param $class_name</span></div>
<div class="line"><a name="l00083"></a><span class="lineno">   83</span>&#160;<span class="comment"> *   The name of the class to instantiate.  Appends the Drupal</span></div>
<div class="line"><a name="l00084"></a><span class="lineno">   84</span>&#160;<span class="comment"> *   major version number to the end of the class name before instantiation.</span></div>
<div class="line"><a name="l00085"></a><span class="lineno">   85</span>&#160;<span class="comment"> * @param $constructor_args</span></div>
<div class="line"><a name="l00086"></a><span class="lineno">   86</span>&#160;<span class="comment"> *   An array of arguments to pass to the class constructor.</span></div>
<div class="line"><a name="l00087"></a><span class="lineno">   87</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00088"></a><span class="lineno">   88</span>&#160;<span class="comment"> * Example wrapper class to instantiate a widget, called with the</span></div>
<div class="line"><a name="l00089"></a><span class="lineno">   89</span>&#160;<span class="comment"> * arguments for the WIDGET_CLASS constructor:</span></div>
<div class="line"><a name="l00090"></a><span class="lineno">   90</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00091"></a><span class="lineno">   91</span>&#160;<span class="comment"> *  function drush_WIDGET_CLASS_get_class($widgetName, $widgetStyle) {</span></div>
<div class="line"><a name="l00092"></a><span class="lineno">   92</span>&#160;<span class="comment"> *    retrun drush_get_class(&#39;Widget_Class&#39;, func_get_args()));</span></div>
<div class="line"><a name="l00093"></a><span class="lineno">   93</span>&#160;<span class="comment"> *  }</span></div>
<div class="line"><a name="l00094"></a><span class="lineno">   94</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00095"></a><span class="lineno">   95</span>&#160;</div>
<div class="line"><a name="l00096"></a><span class="lineno"><a class="code" href="drush_8inc.html#ac0c5cc8dc02832fb068ca98efd0712c4">   96</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#ac0c5cc8dc02832fb068ca98efd0712c4">drush_get_class</a>($class_name, $constructor_args = array(), $variations = array()) {</div>
<div class="line"><a name="l00097"></a><span class="lineno">   97</span>&#160;  <span class="keywordflow">if</span> (empty($variations)) {</div>
<div class="line"><a name="l00098"></a><span class="lineno">   98</span>&#160;    $variations[] = <a class="code" href="includes_2drupal_8inc.html#ad2ccab77d4bc8e7355186f26cd328ac0">drush_drupal_major_version</a>();</div>
<div class="line"><a name="l00099"></a><span class="lineno">   99</span>&#160;  }</div>
<div class="line"><a name="l00100"></a><span class="lineno">  100</span>&#160;  <span class="keywordflow">for</span> ($i=count($variations); $i &gt; 0; $i--) {</div>
<div class="line"><a name="l00101"></a><span class="lineno">  101</span>&#160;    $variant_class_name = $class_name . implode(<span class="stringliteral">&#39;&#39;</span>, array_slice($variations, 0, $i));</div>
<div class="line"><a name="l00102"></a><span class="lineno">  102</span>&#160;    <span class="keywordflow">if</span> (class_exists($variant_class_name)) {</div>
<div class="line"><a name="l00103"></a><span class="lineno">  103</span>&#160;      $reflectionClass = <span class="keyword">new</span> ReflectionClass($variant_class_name);</div>
<div class="line"><a name="l00104"></a><span class="lineno">  104</span>&#160;      <span class="keywordflow">return</span> $reflectionClass-&gt;newInstanceArgs($constructor_args);</div>
<div class="line"><a name="l00105"></a><span class="lineno">  105</span>&#160;    }</div>
<div class="line"><a name="l00106"></a><span class="lineno">  106</span>&#160;  }</div>
<div class="line"><a name="l00107"></a><span class="lineno">  107</span>&#160;  <span class="comment">// Something bad happenned. Exception?</span></div>
<div class="line"><a name="l00108"></a><span class="lineno">  108</span>&#160;  <span class="comment">// drush_set_error(&#39;DRUSH_GET_CLASS_ERROR&#39;, dt(&#39;Unable to load class - %s&#39;, $class_name));</span></div>
<div class="line"><a name="l00109"></a><span class="lineno">  109</span>&#160;}</div>
<div class="line"><a name="l00110"></a><span class="lineno">  110</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00111"></a><span class="lineno">  111</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00112"></a><span class="lineno">  112</span>&#160;<span class="comment"> * Generate an .ini file. used by archive-dump.&quot;</span></div>
<div class="line"><a name="l00113"></a><span class="lineno">  113</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00114"></a><span class="lineno">  114</span>&#160;<span class="comment"> * @param array $ini</span></div>
<div class="line"><a name="l00115"></a><span class="lineno">  115</span>&#160;<span class="comment"> *   A two dimensional associative array where top level are sections and</span></div>
<div class="line"><a name="l00116"></a><span class="lineno">  116</span>&#160;<span class="comment"> *   second level are key =&gt; value pairs.</span></div>
<div class="line"><a name="l00117"></a><span class="lineno">  117</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00118"></a><span class="lineno">  118</span>&#160;<span class="comment"> * @return string</span></div>
<div class="line"><a name="l00119"></a><span class="lineno">  119</span>&#160;<span class="comment"> *   .ini formatted text.</span></div>
<div class="line"><a name="l00120"></a><span class="lineno">  120</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00121"></a><span class="lineno"><a class="code" href="drush_8inc.html#adf7f9343eeb27ca1be960ebb3a948b13">  121</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#adf7f9343eeb27ca1be960ebb3a948b13">drush_export_ini</a>($ini) {</div>
<div class="line"><a name="l00122"></a><span class="lineno">  122</span>&#160;  $output = <span class="stringliteral">&#39;&#39;</span>;</div>
<div class="line"><a name="l00123"></a><span class="lineno">  123</span>&#160;  <span class="keywordflow">foreach</span> ($ini as $section =&gt; $pairs) {</div>
<div class="line"><a name="l00124"></a><span class="lineno">  124</span>&#160;    <span class="keywordflow">if</span> ($section) {</div>
<div class="line"><a name="l00125"></a><span class="lineno">  125</span>&#160;      $output .= <span class="stringliteral">&quot;[$section]\n&quot;</span>;</div>
<div class="line"><a name="l00126"></a><span class="lineno">  126</span>&#160;    }</div>
<div class="line"><a name="l00127"></a><span class="lineno">  127</span>&#160;</div>
<div class="line"><a name="l00128"></a><span class="lineno">  128</span>&#160;    <span class="keywordflow">foreach</span> ($pairs as $k =&gt; $v) {</div>
<div class="line"><a name="l00129"></a><span class="lineno">  129</span>&#160;      <span class="keywordflow">if</span> ($v) {</div>
<div class="line"><a name="l00130"></a><span class="lineno">  130</span>&#160;        $output .= <span class="stringliteral">&quot;$k = \&quot;$v\&quot;\n&quot;</span>;</div>
<div class="line"><a name="l00131"></a><span class="lineno">  131</span>&#160;      }</div>
<div class="line"><a name="l00132"></a><span class="lineno">  132</span>&#160;    }</div>
<div class="line"><a name="l00133"></a><span class="lineno">  133</span>&#160;  }</div>
<div class="line"><a name="l00134"></a><span class="lineno">  134</span>&#160;  <span class="keywordflow">return</span> $output;</div>
<div class="line"><a name="l00135"></a><span class="lineno">  135</span>&#160;}</div>
<div class="line"><a name="l00136"></a><span class="lineno">  136</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00137"></a><span class="lineno">  137</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00138"></a><span class="lineno">  138</span>&#160;<span class="comment"> * Generate code friendly to the Drupal .info format from a structured array.</span></div>
<div class="line"><a name="l00139"></a><span class="lineno">  139</span>&#160;<span class="comment"> * Mostly copied from http://drupalcode.org/viewvc/drupal/contributions/modules/features/features.export.inc.</span></div>
<div class="line"><a name="l00140"></a><span class="lineno">  140</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00141"></a><span class="lineno">  141</span>&#160;<span class="comment"> * @param $info</span></div>
<div class="line"><a name="l00142"></a><span class="lineno">  142</span>&#160;<span class="comment"> *   An array or single value to put in a module&#39;s .info file.</span></div>
<div class="line"><a name="l00143"></a><span class="lineno">  143</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00144"></a><span class="lineno">  144</span>&#160;<span class="comment"> * @param boolean $integer_keys</span></div>
<div class="line"><a name="l00145"></a><span class="lineno">  145</span>&#160;<span class="comment"> *   Use integer in keys.</span></div>
<div class="line"><a name="l00146"></a><span class="lineno">  146</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00147"></a><span class="lineno">  147</span>&#160;<span class="comment"> * @param $parents</span></div>
<div class="line"><a name="l00148"></a><span class="lineno">  148</span>&#160;<span class="comment"> *   Array of parent keys (internal use only).</span></div>
<div class="line"><a name="l00149"></a><span class="lineno">  149</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00150"></a><span class="lineno">  150</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00151"></a><span class="lineno">  151</span>&#160;<span class="comment"> *   A code string ready to be written to a module&#39;s .info file.</span></div>
<div class="line"><a name="l00152"></a><span class="lineno">  152</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00153"></a><span class="lineno"><a class="code" href="drush_8inc.html#ad0f3e2c7a99906109aedd3e38089c9ac">  153</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#ad0f3e2c7a99906109aedd3e38089c9ac">drush_export_info</a>($info, $integer_keys = FALSE, $parents = array()) {</div>
<div class="line"><a name="l00154"></a><span class="lineno">  154</span>&#160;  $output = <span class="stringliteral">&#39;&#39;</span>;</div>
<div class="line"><a name="l00155"></a><span class="lineno">  155</span>&#160;  <span class="keywordflow">if</span> (is_array($info)) {</div>
<div class="line"><a name="l00156"></a><span class="lineno">  156</span>&#160;    <span class="keywordflow">foreach</span> ($info as $k =&gt; $v) {</div>
<div class="line"><a name="l00157"></a><span class="lineno">  157</span>&#160;      $child = $parents;</div>
<div class="line"><a name="l00158"></a><span class="lineno">  158</span>&#160;      $child[] = $k;</div>
<div class="line"><a name="l00159"></a><span class="lineno">  159</span>&#160;      $output .= <a class="code" href="drush_8inc.html#ad0f3e2c7a99906109aedd3e38089c9ac">drush_export_info</a>($v, $integer_keys, $child);</div>
<div class="line"><a name="l00160"></a><span class="lineno">  160</span>&#160;    }</div>
<div class="line"><a name="l00161"></a><span class="lineno">  161</span>&#160;  }</div>
<div class="line"><a name="l00162"></a><span class="lineno">  162</span>&#160;  <span class="keywordflow">else</span> <span class="keywordflow">if</span> (!empty($info) &amp;&amp; count($parents)) {</div>
<div class="line"><a name="l00163"></a><span class="lineno">  163</span>&#160;    $line = array_shift($parents);</div>
<div class="line"><a name="l00164"></a><span class="lineno">  164</span>&#160;    <span class="keywordflow">foreach</span> ($parents as $key) {</div>
<div class="line"><a name="l00165"></a><span class="lineno">  165</span>&#160;      $line .= (!$integer_keys &amp;&amp; is_numeric($key)) ? <span class="stringliteral">&quot;[]&quot;</span> : <span class="stringliteral">&quot;[{$key}]&quot;</span>;</div>
<div class="line"><a name="l00166"></a><span class="lineno">  166</span>&#160;    }</div>
<div class="line"><a name="l00167"></a><span class="lineno">  167</span>&#160;    $line .=  <span class="stringliteral">&quot; = \&quot;{$info}\&quot;\n&quot;</span>;</div>
<div class="line"><a name="l00168"></a><span class="lineno">  168</span>&#160;    <span class="keywordflow">return</span> $line;</div>
<div class="line"><a name="l00169"></a><span class="lineno">  169</span>&#160;  }</div>
<div class="line"><a name="l00170"></a><span class="lineno">  170</span>&#160;  <span class="keywordflow">return</span> $output;</div>
<div class="line"><a name="l00171"></a><span class="lineno">  171</span>&#160;}</div>
<div class="line"><a name="l00172"></a><span class="lineno">  172</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00173"></a><span class="lineno">  173</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00174"></a><span class="lineno">  174</span>&#160;<span class="comment"> * Convert a csv string, or an array of items which</span></div>
<div class="line"><a name="l00175"></a><span class="lineno">  175</span>&#160;<span class="comment"> * may contain csv strings, into an array of items.</span></div>
<div class="line"><a name="l00176"></a><span class="lineno">  176</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00177"></a><span class="lineno">  177</span>&#160;<span class="comment"> * @param $args</span></div>
<div class="line"><a name="l00178"></a><span class="lineno">  178</span>&#160;<span class="comment"> *   A simple csv string; e.g. &#39;a,b,c&#39;</span></div>
<div class="line"><a name="l00179"></a><span class="lineno">  179</span>&#160;<span class="comment"> *   or a simple list of items; e.g. array(&#39;a&#39;,&#39;b&#39;,&#39;c&#39;)</span></div>
<div class="line"><a name="l00180"></a><span class="lineno">  180</span>&#160;<span class="comment"> *   or some combination; e.g. array(&#39;a,b&#39;,&#39;c&#39;) or array(&#39;a,&#39;,&#39;b,&#39;,&#39;c,&#39;)</span></div>
<div class="line"><a name="l00181"></a><span class="lineno">  181</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00182"></a><span class="lineno">  182</span>&#160;<span class="comment"> * @returns array</span></div>
<div class="line"><a name="l00183"></a><span class="lineno">  183</span>&#160;<span class="comment"> *   A simple list of items (e.g. array(&#39;a&#39;,&#39;b&#39;,&#39;c&#39;)</span></div>
<div class="line"><a name="l00184"></a><span class="lineno">  184</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00185"></a><span class="lineno"><a class="code" href="drush_8inc.html#a6007ce294242d1f6e48cda703fbb8d3f">  185</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a6007ce294242d1f6e48cda703fbb8d3f">_convert_csv_to_array</a>($args) {</div>
<div class="line"><a name="l00186"></a><span class="lineno">  186</span>&#160;  <span class="comment">//</span></div>
<div class="line"><a name="l00187"></a><span class="lineno">  187</span>&#160;  <span class="comment">// Step 1: implode(&#39;,&#39;,$args) converts from, say, array(&#39;a,&#39;,&#39;b,&#39;,&#39;c,&#39;) to &#39;a,,b,,c,&#39;</span></div>
<div class="line"><a name="l00188"></a><span class="lineno">  188</span>&#160;  <span class="comment">// Step 2: explode(&#39;,&#39;, ...) converts to array(&#39;a&#39;,&#39;&#39;,&#39;b&#39;,&#39;&#39;,&#39;c&#39;,&#39;&#39;)</span></div>
<div class="line"><a name="l00189"></a><span class="lineno">  189</span>&#160;  <span class="comment">// Step 3: array_filter(...) removes the empty items</span></div>
<div class="line"><a name="l00190"></a><span class="lineno">  190</span>&#160;  <span class="comment">// Step 4: array_map(...) trims extra whitespace from each item</span></div>
<div class="line"><a name="l00191"></a><span class="lineno">  191</span>&#160;  <span class="comment">// (handles csv strings with extra whitespace, e.g. &#39;a, b, c&#39;)</span></div>
<div class="line"><a name="l00192"></a><span class="lineno">  192</span>&#160;  <span class="comment">//</span></div>
<div class="line"><a name="l00193"></a><span class="lineno">  193</span>&#160;  <span class="keywordflow">return</span> array_map(<span class="stringliteral">&#39;trim&#39;</span>, array_filter(explode(<span class="charliteral">&#39;,&#39;</span>, is_array($args) ? implode(<span class="charliteral">&#39;,&#39;</span>,$args) : $args)));</div>
<div class="line"><a name="l00194"></a><span class="lineno">  194</span>&#160;}</div>
<div class="line"><a name="l00195"></a><span class="lineno">  195</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00196"></a><span class="lineno">  196</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00197"></a><span class="lineno">  197</span>&#160;<span class="comment"> * Convert a nested array into a flat array.  Thows away</span></div>
<div class="line"><a name="l00198"></a><span class="lineno">  198</span>&#160;<span class="comment"> * the array keys, returning only the values.</span></div>
<div class="line"><a name="l00199"></a><span class="lineno">  199</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00200"></a><span class="lineno">  200</span>&#160;<span class="comment"> * @param $args</span></div>
<div class="line"><a name="l00201"></a><span class="lineno">  201</span>&#160;<span class="comment"> *   An array that may potentially be nested.</span></div>
<div class="line"><a name="l00202"></a><span class="lineno">  202</span>&#160;<span class="comment"> *   e.g. array(&#39;a&#39;, array(&#39;b&#39;, &#39;c&#39;))</span></div>
<div class="line"><a name="l00203"></a><span class="lineno">  203</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00204"></a><span class="lineno">  204</span>&#160;<span class="comment"> * @returns array</span></div>
<div class="line"><a name="l00205"></a><span class="lineno">  205</span>&#160;<span class="comment"> *   A simple list of items (e.g. array(&#39;a&#39;,&#39;b&#39;,&#39;c&#39;)</span></div>
<div class="line"><a name="l00206"></a><span class="lineno">  206</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00207"></a><span class="lineno"><a class="code" href="drush_8inc.html#ad5c64f6b9992f47ec358e1ad820c36f9">  207</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#ad5c64f6b9992f47ec358e1ad820c36f9">drush_flatten_array</a>($a) {</div>
<div class="line"><a name="l00208"></a><span class="lineno">  208</span>&#160;  $result = array();</div>
<div class="line"><a name="l00209"></a><span class="lineno">  209</span>&#160;  <span class="keywordflow">if</span> (!is_array($a)) {</div>
<div class="line"><a name="l00210"></a><span class="lineno">  210</span>&#160;    <span class="keywordflow">return</span> array($a);</div>
<div class="line"><a name="l00211"></a><span class="lineno">  211</span>&#160;  }</div>
<div class="line"><a name="l00212"></a><span class="lineno">  212</span>&#160;  <span class="keywordflow">foreach</span> ($a as $value) {</div>
<div class="line"><a name="l00213"></a><span class="lineno">  213</span>&#160;    $result = array_merge($result, <a class="code" href="drush_8inc.html#ad5c64f6b9992f47ec358e1ad820c36f9">drush_flatten_array</a>($value));</div>
<div class="line"><a name="l00214"></a><span class="lineno">  214</span>&#160;  }</div>
<div class="line"><a name="l00215"></a><span class="lineno">  215</span>&#160;  <span class="keywordflow">return</span> $result;</div>
<div class="line"><a name="l00216"></a><span class="lineno">  216</span>&#160;}</div>
<div class="line"><a name="l00217"></a><span class="lineno">  217</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00218"></a><span class="lineno">  218</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00219"></a><span class="lineno">  219</span>&#160;<span class="comment"> * Get the available global options. Used by help command. Command files may</span></div>
<div class="line"><a name="l00220"></a><span class="lineno">  220</span>&#160;<span class="comment"> * modify this list using hook_drush_help_alter().</span></div>
<div class="line"><a name="l00221"></a><span class="lineno">  221</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00222"></a><span class="lineno">  222</span>&#160;<span class="comment"> * @param boolean $brief</span></div>
<div class="line"><a name="l00223"></a><span class="lineno">  223</span>&#160;<span class="comment"> *   Return a reduced set of important options. Used by help command.</span></div>
<div class="line"><a name="l00224"></a><span class="lineno">  224</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00225"></a><span class="lineno">  225</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00226"></a><span class="lineno">  226</span>&#160;<span class="comment"> *   An associative array containing the option definition as the key,</span></div>
<div class="line"><a name="l00227"></a><span class="lineno">  227</span>&#160;<span class="comment"> *   and a descriptive array for each of the available options.  The array</span></div>
<div class="line"><a name="l00228"></a><span class="lineno">  228</span>&#160;<span class="comment"> *   elements for each item are:</span></div>
<div class="line"><a name="l00229"></a><span class="lineno">  229</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00230"></a><span class="lineno">  230</span>&#160;<span class="comment"> *     - short-form: The shortcut form for specifying the key on the commandline.</span></div>
<div class="line"><a name="l00231"></a><span class="lineno">  231</span>&#160;<span class="comment"> *     - context: The drush context where the value of this item is cached.  Used</span></div>
<div class="line"><a name="l00232"></a><span class="lineno">  232</span>&#160;<span class="comment"> *       by backend invoke to propagate values set in code.</span></div>
<div class="line"><a name="l00233"></a><span class="lineno">  233</span>&#160;<span class="comment"> *     - never-post: If TRUE, backend invoke will never POST this item&#39;s value</span></div>
<div class="line"><a name="l00234"></a><span class="lineno">  234</span>&#160;<span class="comment"> *       on STDIN; it will always be sent as a commandline option.</span></div>
<div class="line"><a name="l00235"></a><span class="lineno">  235</span>&#160;<span class="comment"> *     - never-propagate: If TRUE, backend invoke will never pass this item on</span></div>
<div class="line"><a name="l00236"></a><span class="lineno">  236</span>&#160;<span class="comment"> *       to the subcommand being executed.</span></div>
<div class="line"><a name="l00237"></a><span class="lineno">  237</span>&#160;<span class="comment"> *     - local-context-only: Backend invoke will only pass this value on for local calls.</span></div>
<div class="line"><a name="l00238"></a><span class="lineno">  238</span>&#160;<span class="comment"> *     - merge: For options such as $options[&#39;shell-aliases&#39;] that consist of an array</span></div>
<div class="line"><a name="l00239"></a><span class="lineno">  239</span>&#160;<span class="comment"> *       of items, make a merged array that contains all of the values specified for</span></div>
<div class="line"><a name="l00240"></a><span class="lineno">  240</span>&#160;<span class="comment"> *       all of the contexts (config files) where the option is defined.  The value is stored in</span></div>
<div class="line"><a name="l00241"></a><span class="lineno">  241</span>&#160;<span class="comment"> *       the specified &#39;context&#39;, or in a context named after the option itself if the</span></div>
<div class="line"><a name="l00242"></a><span class="lineno">  242</span>&#160;<span class="comment"> *       context flag is not specified.</span></div>
<div class="line"><a name="l00243"></a><span class="lineno">  243</span>&#160;<span class="comment"> *       IMPORTANT: When the merge flag is used, the option value must be obtained via</span></div>
<div class="line"><a name="l00244"></a><span class="lineno">  244</span>&#160;<span class="comment"> *       drush_get_context(&#39;option&#39;) rather than drush_get_option(&#39;option&#39;).</span></div>
<div class="line"><a name="l00245"></a><span class="lineno">  245</span>&#160;<span class="comment"> *     - merge-pathlist: For options such as --include and --config, make a merged list</span></div>
<div class="line"><a name="l00246"></a><span class="lineno">  246</span>&#160;<span class="comment"> *       of options from all contexts; works like the &#39;merge&#39; flag, but also handles string</span></div>
<div class="line"><a name="l00247"></a><span class="lineno">  247</span>&#160;<span class="comment"> *       values separated by the PATH_SEPARATOR.</span></div>
<div class="line"><a name="l00248"></a><span class="lineno">  248</span>&#160;<span class="comment"> *     - merge-associative: Like &#39;merge-pathlist&#39;, but key values are preserved.</span></div>
<div class="line"><a name="l00249"></a><span class="lineno">  249</span>&#160;<span class="comment"> *     - propagate-cli-value: Used to tell backend invoke to include the value for</span></div>
<div class="line"><a name="l00250"></a><span class="lineno">  250</span>&#160;<span class="comment"> *       this item as specified on the cli.  This can either override &#39;context&#39;</span></div>
<div class="line"><a name="l00251"></a><span class="lineno">  251</span>&#160;<span class="comment"> *       (e.g., propagate --include from cli value instead of DRUSH_INCLUDE context),</span></div>
<div class="line"><a name="l00252"></a><span class="lineno">  252</span>&#160;<span class="comment"> *       or for an independent global setting (e.g. --user)</span></div>
<div class="line"><a name="l00253"></a><span class="lineno">  253</span>&#160;<span class="comment"> *     - description: The help text for this item. displayed by `drush help`.</span></div>
<div class="line"><a name="l00254"></a><span class="lineno">  254</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00255"></a><span class="lineno"><a class="code" href="drush_8inc.html#acb0a26e79bcbdd1152d59a6916a35aae">  255</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#acb0a26e79bcbdd1152d59a6916a35aae">drush_get_global_options</a>($brief = FALSE) {</div>
<div class="line"><a name="l00256"></a><span class="lineno">  256</span>&#160;  $options[<span class="stringliteral">&#39;root&#39;</span>]               = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;r&#39;</span>, <span class="stringliteral">&#39;short-has-arg&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;never-post&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Drupal root directory to use (default: current directory).&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;path&#39;</span>);</div>
<div class="line"><a name="l00257"></a><span class="lineno">  257</span>&#160;  $options[<span class="stringliteral">&#39;uri&#39;</span>]                = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;l&#39;</span>, <span class="stringliteral">&#39;short-has-arg&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;never-post&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;URI of the drupal site to use (only needed in multisite environments or when running on an alternate port).&#39;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;http://example.com:8888&#39;</span>);</div>
<div class="line"><a name="l00258"></a><span class="lineno">  258</span>&#160;  $options[<span class="stringliteral">&#39;verbose&#39;</span>]            = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;v&#39;</span>, <span class="stringliteral">&#39;context&#39;</span> =&gt; <span class="stringliteral">&#39;DRUSH_VERBOSE&#39;</span>, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Display extra information about the command.&#39;</span>);</div>
<div class="line"><a name="l00259"></a><span class="lineno">  259</span>&#160;  $options[<span class="stringliteral">&#39;debug&#39;</span>]              = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;d&#39;</span>, <span class="stringliteral">&#39;context&#39;</span> =&gt; <span class="stringliteral">&#39;DRUSH_DEBUG&#39;</span>, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Display even more information, including internal messages.&#39;</span>);</div>
<div class="line"><a name="l00260"></a><span class="lineno">  260</span>&#160;  $options[<span class="stringliteral">&#39;yes&#39;</span>]                = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;y&#39;</span>, <span class="stringliteral">&#39;context&#39;</span> =&gt; <span class="stringliteral">&#39;DRUSH_AFFIRMATIVE&#39;</span>, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Assume &#39;yes&#39; as answer to all prompts.&quot;</span>);</div>
<div class="line"><a name="l00261"></a><span class="lineno">  261</span>&#160;  $options[<span class="stringliteral">&#39;no&#39;</span>]                 = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;n&#39;</span>, <span class="stringliteral">&#39;context&#39;</span> =&gt; <span class="stringliteral">&#39;DRUSH_NEGATIVE&#39;</span>, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Assume &#39;no&#39; as answer to all prompts.&quot;</span>);</div>
<div class="line"><a name="l00262"></a><span class="lineno">  262</span>&#160;  $options[<span class="stringliteral">&#39;simulate&#39;</span>]           = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;s&#39;</span>, <span class="stringliteral">&#39;context&#39;</span> =&gt; <span class="stringliteral">&#39;DRUSH_SIMULATE&#39;</span>, <span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Simulate all relevant actions (don&#39;t actually change the system).&quot;</span>);</div>
<div class="line"><a name="l00263"></a><span class="lineno">  263</span>&#160;  $options[<span class="stringliteral">&#39;pipe&#39;</span>]               = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;p&#39;</span>, <span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Emit a compact representation of the command for scripting.&quot;</span>);</div>
<div class="line"><a name="l00264"></a><span class="lineno">  264</span>&#160;  $options[<span class="stringliteral">&#39;help&#39;</span>]               = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;h&#39;</span>, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;This help system.&quot;</span>);</div>
<div class="line"><a name="l00265"></a><span class="lineno">  265</span>&#160;</div>
<div class="line"><a name="l00266"></a><span class="lineno">  266</span>&#160;  <span class="keywordflow">if</span> (!$brief) {</div>
<div class="line"><a name="l00267"></a><span class="lineno">  267</span>&#160;    $options[<span class="stringliteral">&#39;version&#39;</span>]            = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Show drush version.&quot;</span>);</div>
<div class="line"><a name="l00268"></a><span class="lineno">  268</span>&#160;    $options[<span class="stringliteral">&#39;php&#39;</span>]                = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;The absolute path to your PHP intepreter, if not &#39;php&#39; in the path.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;/path/to/file&#39;</span>, <span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE);</div>
<div class="line"><a name="l00269"></a><span class="lineno">  269</span>&#160;    $options[<span class="stringliteral">&#39;interactive&#39;</span>]        = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="stringliteral">&#39;ia&#39;</span>, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Force interactive mode for commands run on multiple targets (e.g. `drush @site1,@site2 cc --ia`).&quot;</span>, <span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE);</div>
<div class="line"><a name="l00270"></a><span class="lineno">  270</span>&#160;    $options[<span class="stringliteral">&#39;tty&#39;</span>]                = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Force allocation of tty for remote commands&quot;</span>, <span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE);</div>
<div class="line"><a name="l00271"></a><span class="lineno">  271</span>&#160;    $options[<span class="stringliteral">&#39;quiet&#39;</span>]               = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;q&#39;</span>, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Suppress non-error messages.&#39;</span>);</div>
<div class="line"><a name="l00272"></a><span class="lineno">  272</span>&#160;    $options[<span class="stringliteral">&#39;include&#39;</span>]             = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;i&#39;</span>, <span class="stringliteral">&#39;short-has-arg&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;context&#39;</span> =&gt; <span class="stringliteral">&#39;DRUSH_INCLUDE&#39;</span>, <span class="stringliteral">&#39;never-post&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;propagate-cli-value&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;merge-pathlist&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;A list of additional directory paths to search for drush commands.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;/path/dir&#39;</span>);</div>
<div class="line"><a name="l00273"></a><span class="lineno">  273</span>&#160;    $options[<span class="stringliteral">&#39;exclude&#39;</span>]             = array(<span class="stringliteral">&#39;propagate-cli-value&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;never-post&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;merge-pathlist&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;A list of files and directory paths to exclude from consideration when searching for drush commandfiles.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;/path/dir&#39;</span>);</div>
<div class="line"><a name="l00274"></a><span class="lineno">  274</span>&#160;    $options[<span class="stringliteral">&#39;config&#39;</span>]              = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;c&#39;</span>, <span class="stringliteral">&#39;short-has-arg&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;context&#39;</span> =&gt; <span class="stringliteral">&#39;DRUSH_CONFIG&#39;</span>, <span class="stringliteral">&#39;local-context-only&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;merge-pathlist&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Specify an additional config file to load. See example.drushrc.php.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;/path/file&#39;</span>);</div>
<div class="line"><a name="l00275"></a><span class="lineno">  275</span>&#160;    $options[<span class="stringliteral">&#39;user&#39;</span>]                = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;u&#39;</span>, <span class="stringliteral">&#39;short-has-arg&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;propagate-cli-value&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Specify a Drupal user to login with. May be a name or a number.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;name_or_number&#39;</span>);</div>
<div class="line"><a name="l00276"></a><span class="lineno">  276</span>&#160;    $options[<span class="stringliteral">&#39;backend&#39;</span>]             = array(<span class="stringliteral">&#39;short-form&#39;</span> =&gt; <span class="charliteral">&#39;b&#39;</span>, <span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Hide all output and return structured data.&quot;</span>);</div>
<div class="line"><a name="l00277"></a><span class="lineno">  277</span>&#160;    $options[<span class="stringliteral">&#39;choice&#39;</span>]              = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Provide an answer to a multiple-choice prompt.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;number&#39;</span>);</div>
<div class="line"><a name="l00278"></a><span class="lineno">  278</span>&#160;    $options[<span class="stringliteral">&#39;variables&#39;</span>]           = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Comma delimited list of name=value pairs. These values take precedence even over settings.php variable overrides.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;foo=bar,baz=yaz&#39;</span>);</div>
<div class="line"><a name="l00279"></a><span class="lineno">  279</span>&#160;    $options[<span class="stringliteral">&#39;search-depth&#39;</span>]        = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Control the depth that drush will search for alias files.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;number&#39;</span>);</div>
<div class="line"><a name="l00280"></a><span class="lineno">  280</span>&#160;    $options[<span class="stringliteral">&#39;ignored-modules&#39;</span>]     = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Exclude some modules from consideration when searching for drush command files.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;token,views&#39;</span>);</div>
<div class="line"><a name="l00281"></a><span class="lineno">  281</span>&#160;    $options[<span class="stringliteral">&#39;no-label&#39;</span>]            = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Remove the site label that drush includes in multi-site command output (e.g. `drush @site1,@site2 status`).&quot;</span>);</div>
<div class="line"><a name="l00282"></a><span class="lineno">  282</span>&#160;    $options[<span class="stringliteral">&#39;label-separator&#39;</span>]     = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Specify the separator to use in multi-site command output (e.g. `drush @sites pm-list --label-separator=&#39;,&#39; --format=csv`).&quot;</span>);</div>
<div class="line"><a name="l00283"></a><span class="lineno">  283</span>&#160;    $options[<span class="stringliteral">&#39;nocolor&#39;</span>]             = array(<span class="stringliteral">&#39;context&#39;</span> =&gt; <span class="stringliteral">&#39;DRUSH_NOCOLOR&#39;</span>, <span class="stringliteral">&#39;propagate-cli-value&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Suppress color highlighting on log messages.&quot;</span>);</div>
<div class="line"><a name="l00284"></a><span class="lineno">  284</span>&#160;    $options[<span class="stringliteral">&#39;show-passwords&#39;</span>]      = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Show database passwords in commands that display connection information.&quot;</span>);</div>
<div class="line"><a name="l00285"></a><span class="lineno">  285</span>&#160;    $options[<span class="stringliteral">&#39;show-invoke&#39;</span>]         = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Show all function names which could have been called for the current command. See drush_invoke().&quot;</span>);</div>
<div class="line"><a name="l00286"></a><span class="lineno">  286</span>&#160;    $options[<span class="stringliteral">&#39;watchdog&#39;</span>]            = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Control logging of Drupal&#39;s watchdog() to drush log. Recognized values are &#39;log&#39;, &#39;print&#39;, &#39;disabled&#39;. Defaults to log. &#39;print&#39; shows calls to admin but does not add them to the log.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;print&#39;</span>);</div>
<div class="line"><a name="l00287"></a><span class="lineno">  287</span>&#160;    $options[<span class="stringliteral">&#39;cache-default-class&#39;</span>] = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;A cache backend class that implements CacheInterface. Defaults to JSONCache.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;JSONCache&#39;</span>);</div>
<div class="line"><a name="l00288"></a><span class="lineno">  288</span>&#160;    $options[<span class="stringliteral">&#39;cache-class-&lt;bin&gt;&#39;</span>]   = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;A cache backend class that implements CacheInterface to use for a specific cache bin.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;className&#39;</span>);</div>
<div class="line"><a name="l00289"></a><span class="lineno">  289</span>&#160;    $options[<span class="stringliteral">&#39;early&#39;</span>]               = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Include a file (with relative or full path) and call the drush_early_hook() function (where &#39;hook&#39; is the filename). The function is called pre-bootstrap and offers an opportunity to alter the drush bootstrap environment or process (returning FALSE from the function will continue the bootstrap), or return output very rapidly (e.g. from caches). See includes/complete.inc for an example.&quot;</span>);</div>
<div class="line"><a name="l00290"></a><span class="lineno">  290</span>&#160;    $options[<span class="stringliteral">&#39;alias-path&#39;</span>]          = array(<span class="stringliteral">&#39;context&#39;</span> =&gt; <span class="stringliteral">&#39;ALIAS_PATH&#39;</span>, <span class="stringliteral">&#39;local-context-only&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;merge-pathlist&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;propagate-cli-value&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Specifies the list of paths where drush will search for alias files.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;/path/alias1:/path/alias2&#39;</span>);</div>
<div class="line"><a name="l00291"></a><span class="lineno">  291</span>&#160;    $options[<span class="stringliteral">&#39;backup-location&#39;</span>]     = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Specifies the directory where drush will store backups.&quot;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;/path/to/dir&#39;</span>);</div>
<div class="line"><a name="l00292"></a><span class="lineno">  292</span>&#160;    $options[<span class="stringliteral">&#39;confirm-rollback&#39;</span>]    = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Wait for confirmation before doing a rollback when something goes wrong.&#39;</span>);</div>
<div class="line"><a name="l00293"></a><span class="lineno">  293</span>&#160;    $options[<span class="stringliteral">&#39;complete-debug&#39;</span>]      = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Turn on debug mode forf completion code&quot;</span>);</div>
<div class="line"><a name="l00294"></a><span class="lineno">  294</span>&#160;    $options[<span class="stringliteral">&#39;php-options&#39;</span>]         = array(<span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Options to pass to `php` when running drush.  Only effective when using the `drush` script.&quot;</span>, <span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;-d error_reporting=&quot;E_ALL&quot;&#39;</span>);</div>
<div class="line"><a name="l00295"></a><span class="lineno">  295</span>&#160;    $options[<span class="stringliteral">&#39;deferred-sanitization&#39;</span>] = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&quot;Defer calculating the sanitization operations until after the database has been copied. This is done automatically if the source database is remote.&quot;</span>);</div>
<div class="line"><a name="l00296"></a><span class="lineno">  296</span>&#160;    $options[<span class="stringliteral">&#39;remote-host&#39;</span>]         = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Remote site to execute drush command on. Managed by site alias.&#39;</span>);</div>
<div class="line"><a name="l00297"></a><span class="lineno">  297</span>&#160;    $options[<span class="stringliteral">&#39;remote-user&#39;</span>]         = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;User account to use with a remote drush command. Managed by site alias.&#39;</span>);</div>
<div class="line"><a name="l00298"></a><span class="lineno">  298</span>&#160;    $options[<span class="stringliteral">&#39;remote-os&#39;</span>]           = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;The operating system used on the remote host. Managed by site alias.&#39;</span>);</div>
<div class="line"><a name="l00299"></a><span class="lineno">  299</span>&#160;    $options[<span class="stringliteral">&#39;site-list&#39;</span>]           = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;List of sites to run commands on. Managed by site alias.&#39;</span>);</div>
<div class="line"><a name="l00300"></a><span class="lineno">  300</span>&#160;    $options[<span class="stringliteral">&#39;reserve-margin&#39;</span>]      = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Remove columns from formatted opions. Managed by multi-site command handling.&#39;</span>);</div>
<div class="line"><a name="l00301"></a><span class="lineno">  301</span>&#160;    $options[<span class="stringliteral">&#39;strict&#39;</span>]              = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Check requirements more strictly / remove backwards-compatibility features for unit tests.&#39;</span>);</div>
<div class="line"><a name="l00302"></a><span class="lineno">  302</span>&#160;    $options[<span class="stringliteral">&#39;command-specific&#39;</span>]    = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;merge-associative&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Command-specific options.&#39;</span>);</div>
<div class="line"><a name="l00303"></a><span class="lineno">  303</span>&#160;    $options[<span class="stringliteral">&#39;site-aliases&#39;</span>]        = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;merge-associative&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;List of site aliases.&#39;</span>);</div>
<div class="line"><a name="l00304"></a><span class="lineno">  304</span>&#160;    $options[<span class="stringliteral">&#39;shell-aliases&#39;</span>]       = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;merge&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;List of shell aliases.&#39;</span>);</div>
<div class="line"><a name="l00305"></a><span class="lineno">  305</span>&#160;    $options[<span class="stringliteral">&#39;path-aliases&#39;</span>]        = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Path aliases from site alias.&#39;</span>);</div>
<div class="line"><a name="l00306"></a><span class="lineno">  306</span>&#160;    $options[<span class="stringliteral">&#39;ssh-options&#39;</span>]         = array(<span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;A string of extra options that will be passed to the ssh command&#39;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;-p 100&#39;</span>);</div>
<div class="line"><a name="l00307"></a><span class="lineno">  307</span>&#160;    $options[<span class="stringliteral">&#39;editor&#39;</span>]              = array(<span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;A string of bash which launches user\&#39;s preferred text editor. Defaults to ${VISUAL-${EDITOR-vi}}.&#39;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;vi&#39;</span>);</div>
<div class="line"><a name="l00308"></a><span class="lineno">  308</span>&#160;    $options[<span class="stringliteral">&#39;db-url&#39;</span>]              = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;A Drupal 6 style database URL. Used by various commands.&#39;</span>, <span class="stringliteral">&#39;example-value&#39;</span> =&gt; <span class="stringliteral">&#39;mysql://root:pass@127.0.0.1/db&#39;</span>);</div>
<div class="line"><a name="l00309"></a><span class="lineno">  309</span>&#160;    $options[<span class="stringliteral">&#39;drush-coverage&#39;</span>]      = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;never-post&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;propagate-cli-value&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;File to save code coverage data into.&#39;</span>);</div>
<div class="line"><a name="l00310"></a><span class="lineno">  310</span>&#160;    $options[<span class="stringliteral">&#39;redirect-port&#39;</span>]       = array(<span class="stringliteral">&#39;hidden&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;never-propagate&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;description&#39;</span> =&gt; <span class="stringliteral">&#39;Used by the user-login command to specify the redirect port on the local machine; it therefore would not do to pass this to the remote machines.&#39;</span>);</div>
<div class="line"><a name="l00311"></a><span class="lineno">  311</span>&#160;</div>
<div class="line"><a name="l00312"></a><span class="lineno">  312</span>&#160;    $command = array(</div>
<div class="line"><a name="l00313"></a><span class="lineno">  313</span>&#160;      <span class="stringliteral">&#39;options&#39;</span> =&gt; $options,</div>
<div class="line"><a name="l00314"></a><span class="lineno">  314</span>&#160;      <span class="stringliteral">&#39;#brief&#39;</span> =&gt; FALSE,</div>
<div class="line"><a name="l00315"></a><span class="lineno">  315</span>&#160;    ) + drush_command_defaults(<span class="stringliteral">&#39;global-options&#39;</span>, <span class="stringliteral">&#39;global_options&#39;</span>, __FILE__);</div>
<div class="line"><a name="l00316"></a><span class="lineno">  316</span>&#160;    <a class="code" href="includes_2command_8inc.html#a74995cc76034e90a39baee51111b20be">drush_command_invoke_all_ref</a>(<span class="stringliteral">&#39;drush_help_alter&#39;</span>, $command);</div>
<div class="line"><a name="l00317"></a><span class="lineno">  317</span>&#160;</div>
<div class="line"><a name="l00318"></a><span class="lineno">  318</span>&#160;    $options = $command[<span class="stringliteral">&#39;options&#39;</span>];</div>
<div class="line"><a name="l00319"></a><span class="lineno">  319</span>&#160;  }</div>
<div class="line"><a name="l00320"></a><span class="lineno">  320</span>&#160;  <span class="keywordflow">return</span> $options;</div>
<div class="line"><a name="l00321"></a><span class="lineno">  321</span>&#160;}</div>
<div class="line"><a name="l00322"></a><span class="lineno">  322</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00323"></a><span class="lineno">  323</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00324"></a><span class="lineno">  324</span>&#160;<span class="comment"> * Exits with a message. In general, you should use drush_set_error() instead of</span></div>
<div class="line"><a name="l00325"></a><span class="lineno">  325</span>&#160;<span class="comment"> * this function. That lets drush proceed with other tasks.</span></div>
<div class="line"><a name="l00326"></a><span class="lineno">  326</span>&#160;<span class="comment"> * TODO: Exit with a correct status code.</span></div>
<div class="line"><a name="l00327"></a><span class="lineno">  327</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00328"></a><span class="lineno"><a class="code" href="drush_8inc.html#ac40c0a915153d396ef15c1c9f4e809a6">  328</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#ac40c0a915153d396ef15c1c9f4e809a6">drush_die</a>($msg = NULL, $status = NULL) {</div>
<div class="line"><a name="l00329"></a><span class="lineno">  329</span>&#160;  die($msg ? <span class="stringliteral">&quot;drush: $msg\n&quot;</span> : <span class="stringliteral">&#39;&#39;</span>);</div>
<div class="line"><a name="l00330"></a><span class="lineno">  330</span>&#160;}</div>
<div class="line"><a name="l00331"></a><span class="lineno">  331</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00332"></a><span class="lineno">  332</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00333"></a><span class="lineno">  333</span>&#160;<span class="comment"> * Check to see if the provided line is a &quot;#!/usr/bin/env drush&quot;</span></div>
<div class="line"><a name="l00334"></a><span class="lineno">  334</span>&#160;<span class="comment"> * &quot;shebang&quot; script line.</span></div>
<div class="line"><a name="l00335"></a><span class="lineno">  335</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00336"></a><span class="lineno"><a class="code" href="drush_8inc.html#a997323f1acad3b9f003118bdcf3540c9">  336</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a997323f1acad3b9f003118bdcf3540c9">_drush_is_drush_shebang_line</a>($line) {</div>
<div class="line"><a name="l00337"></a><span class="lineno">  337</span>&#160;   <span class="keywordflow">return</span> ((substr($line,0,2) == <span class="stringliteral">&#39;#!&#39;</span>) &amp;&amp; (strstr($line, <span class="stringliteral">&#39;drush&#39;</span>) !== FALSE));</div>
<div class="line"><a name="l00338"></a><span class="lineno">  338</span>&#160;}</div>
<div class="line"><a name="l00339"></a><span class="lineno">  339</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00340"></a><span class="lineno">  340</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00341"></a><span class="lineno">  341</span>&#160;<span class="comment"> * Check to see if the provided script file is a &quot;#!/usr/bin/env drush&quot;</span></div>
<div class="line"><a name="l00342"></a><span class="lineno">  342</span>&#160;<span class="comment"> * &quot;shebang&quot; script line.</span></div>
<div class="line"><a name="l00343"></a><span class="lineno">  343</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00344"></a><span class="lineno"><a class="code" href="drush_8inc.html#a8f5d18c322518e0f31f3fce0f024f2ef">  344</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a8f5d18c322518e0f31f3fce0f024f2ef">_drush_is_drush_shebang_script</a>($script_filename) {</div>
<div class="line"><a name="l00345"></a><span class="lineno">  345</span>&#160;  $result = FALSE;</div>
<div class="line"><a name="l00346"></a><span class="lineno">  346</span>&#160;</div>
<div class="line"><a name="l00347"></a><span class="lineno">  347</span>&#160;  <span class="keywordflow">if</span> (file_exists($script_filename)) {</div>
<div class="line"><a name="l00348"></a><span class="lineno">  348</span>&#160;    $fp = fopen($script_filename, <span class="stringliteral">&quot;r&quot;</span>);</div>
<div class="line"><a name="l00349"></a><span class="lineno">  349</span>&#160;    <span class="keywordflow">if</span> ($fp !== FALSE) {</div>
<div class="line"><a name="l00350"></a><span class="lineno">  350</span>&#160;      $line = fgets($fp);</div>
<div class="line"><a name="l00351"></a><span class="lineno">  351</span>&#160;      $result = <a class="code" href="drush_8inc.html#a997323f1acad3b9f003118bdcf3540c9">_drush_is_drush_shebang_line</a>($line);</div>
<div class="line"><a name="l00352"></a><span class="lineno">  352</span>&#160;      fclose($fp);</div>
<div class="line"><a name="l00353"></a><span class="lineno">  353</span>&#160;    }</div>
<div class="line"><a name="l00354"></a><span class="lineno">  354</span>&#160;  }</div>
<div class="line"><a name="l00355"></a><span class="lineno">  355</span>&#160;</div>
<div class="line"><a name="l00356"></a><span class="lineno">  356</span>&#160;  <span class="keywordflow">return</span> $result;</div>
<div class="line"><a name="l00357"></a><span class="lineno">  357</span>&#160;}</div>
<div class="line"><a name="l00358"></a><span class="lineno">  358</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00359"></a><span class="lineno">  359</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00360"></a><span class="lineno">  360</span>&#160;<span class="comment"> * @defgroup userinput Get input from the user.</span></div>
<div class="line"><a name="l00361"></a><span class="lineno">  361</span>&#160;<span class="comment"> * @{</span></div>
<div class="line"><a name="l00362"></a><span class="lineno">  362</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00363"></a><span class="lineno">  363</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00364"></a><span class="lineno">  364</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00365"></a><span class="lineno">  365</span>&#160;<span class="comment"> * Asks the user a basic yes/no question.</span></div>
<div class="line"><a name="l00366"></a><span class="lineno">  366</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00367"></a><span class="lineno">  367</span>&#160;<span class="comment"> * @param string $msg</span></div>
<div class="line"><a name="l00368"></a><span class="lineno">  368</span>&#160;<span class="comment"> *   The question to ask.</span></div>
<div class="line"><a name="l00369"></a><span class="lineno">  369</span>&#160;<span class="comment"> * @param int $indent</span></div>
<div class="line"><a name="l00370"></a><span class="lineno">  370</span>&#160;<span class="comment"> *   The number of spaces to indent the message.</span></div>
<div class="line"><a name="l00371"></a><span class="lineno">  371</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00372"></a><span class="lineno">  372</span>&#160;<span class="comment"> * @return bool</span></div>
<div class="line"><a name="l00373"></a><span class="lineno">  373</span>&#160;<span class="comment"> *   TRUE if the user enters &quot;y&quot; or FALSE if &quot;n&quot;.</span></div>
<div class="line"><a name="l00374"></a><span class="lineno">  374</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00375"></a><span class="lineno"><a class="code" href="group__userinput.html#gaa4169b83ff9dc4222af95d376b21268b">  375</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__userinput.html#gaa4169b83ff9dc4222af95d376b21268b">drush_confirm</a>($msg, $indent = 0) {</div>
<div class="line"><a name="l00376"></a><span class="lineno">  376</span>&#160;  <a class="code" href="group__outputfunctions.html#ga6dc4aa94bd0a854c564a2538e166c749">drush_print_prompt</a>((<span class="keywordtype">string</span>)$msg . <span class="stringliteral">&quot; (y/n): &quot;</span>, $indent);</div>
<div class="line"><a name="l00377"></a><span class="lineno">  377</span>&#160;</div>
<div class="line"><a name="l00378"></a><span class="lineno">  378</span>&#160;  <span class="comment">// Automatically accept confirmations if the --yes argument was supplied.</span></div>
<div class="line"><a name="l00379"></a><span class="lineno">  379</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_AFFIRMATIVE&#39;</span>)) {</div>
<div class="line"><a name="l00380"></a><span class="lineno">  380</span>&#160;    <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<span class="stringliteral">&quot;y&quot;</span>);</div>
<div class="line"><a name="l00381"></a><span class="lineno">  381</span>&#160;    <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00382"></a><span class="lineno">  382</span>&#160;  }</div>
<div class="line"><a name="l00383"></a><span class="lineno">  383</span>&#160;  <span class="comment">// Automatically cancel confirmations if the --no argument was supplied.</span></div>
<div class="line"><a name="l00384"></a><span class="lineno">  384</span>&#160;  elseif (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_NEGATIVE&#39;</span>)) {</div>
<div class="line"><a name="l00385"></a><span class="lineno">  385</span>&#160;    <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<span class="stringliteral">&quot;n&quot;</span>);</div>
<div class="line"><a name="l00386"></a><span class="lineno">  386</span>&#160;    <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00387"></a><span class="lineno">  387</span>&#160;  }</div>
<div class="line"><a name="l00388"></a><span class="lineno">  388</span>&#160;  <span class="comment">// See http://drupal.org/node/499758 before changing this.</span></div>
<div class="line"><a name="l00389"></a><span class="lineno">  389</span>&#160;  $stdin = fopen(<span class="stringliteral">&quot;php://stdin&quot;</span>,<span class="stringliteral">&quot;r&quot;</span>);</div>
<div class="line"><a name="l00390"></a><span class="lineno">  390</span>&#160;</div>
<div class="line"><a name="l00391"></a><span class="lineno">  391</span>&#160;  <span class="keywordflow">while</span> ($line = fgets($stdin)) {</div>
<div class="line"><a name="l00392"></a><span class="lineno">  392</span>&#160;  $line = trim($line);</div>
<div class="line"><a name="l00393"></a><span class="lineno">  393</span>&#160;    <span class="keywordflow">if</span> ($line == <span class="charliteral">&#39;y&#39;</span>) {</div>
<div class="line"><a name="l00394"></a><span class="lineno">  394</span>&#160;      <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00395"></a><span class="lineno">  395</span>&#160;    }</div>
<div class="line"><a name="l00396"></a><span class="lineno">  396</span>&#160;    <span class="keywordflow">if</span> ($line == <span class="charliteral">&#39;n&#39;</span>) {</div>
<div class="line"><a name="l00397"></a><span class="lineno">  397</span>&#160;      <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00398"></a><span class="lineno">  398</span>&#160;    }</div>
<div class="line"><a name="l00399"></a><span class="lineno">  399</span>&#160;    <a class="code" href="group__outputfunctions.html#ga6dc4aa94bd0a854c564a2538e166c749">drush_print_prompt</a>((<span class="keywordtype">string</span>)$msg . <span class="stringliteral">&quot; (y/n): &quot;</span>, $indent);</div>
<div class="line"><a name="l00400"></a><span class="lineno">  400</span>&#160;  }</div>
<div class="line"><a name="l00401"></a><span class="lineno">  401</span>&#160;}</div>
<div class="line"><a name="l00402"></a><span class="lineno">  402</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00403"></a><span class="lineno">  403</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00404"></a><span class="lineno">  404</span>&#160;<span class="comment"> * Ask the user to select an item from a list.</span></div>
<div class="line"><a name="l00405"></a><span class="lineno">  405</span>&#160;<span class="comment"> * From a provided associative array, drush_choice will</span></div>
<div class="line"><a name="l00406"></a><span class="lineno">  406</span>&#160;<span class="comment"> * display all of the questions, numbered from 1 to N,</span></div>
<div class="line"><a name="l00407"></a><span class="lineno">  407</span>&#160;<span class="comment"> * and return the item the user selected. &quot;0&quot; is always</span></div>
<div class="line"><a name="l00408"></a><span class="lineno">  408</span>&#160;<span class="comment"> * cancel; entering a blank line is also interpreted</span></div>
<div class="line"><a name="l00409"></a><span class="lineno">  409</span>&#160;<span class="comment"> * as cancelling.</span></div>
<div class="line"><a name="l00410"></a><span class="lineno">  410</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00411"></a><span class="lineno">  411</span>&#160;<span class="comment"> * @param $options</span></div>
<div class="line"><a name="l00412"></a><span class="lineno">  412</span>&#160;<span class="comment"> *   A list of questions to display to the user.  The</span></div>
<div class="line"><a name="l00413"></a><span class="lineno">  413</span>&#160;<span class="comment"> *   KEYS of the array are the result codes to return to the</span></div>
<div class="line"><a name="l00414"></a><span class="lineno">  414</span>&#160;<span class="comment"> *   caller; the VALUES are the messages to display on</span></div>
<div class="line"><a name="l00415"></a><span class="lineno">  415</span>&#160;<span class="comment"> *   each line. Special keys of the form &#39;-- something --&#39; can be</span></div>
<div class="line"><a name="l00416"></a><span class="lineno">  416</span>&#160;<span class="comment"> *   provided as separator between choices groups. Separator keys</span></div>
<div class="line"><a name="l00417"></a><span class="lineno">  417</span>&#160;<span class="comment"> *    don&#39;t alter the numbering.</span></div>
<div class="line"><a name="l00418"></a><span class="lineno">  418</span>&#160;<span class="comment"> * @param $prompt</span></div>
<div class="line"><a name="l00419"></a><span class="lineno">  419</span>&#160;<span class="comment"> *   The message to display to the user prompting for input.</span></div>
<div class="line"><a name="l00420"></a><span class="lineno">  420</span>&#160;<span class="comment"> * @param $label</span></div>
<div class="line"><a name="l00421"></a><span class="lineno">  421</span>&#160;<span class="comment"> *   Controls the display of each line.  Defaults to</span></div>
<div class="line"><a name="l00422"></a><span class="lineno">  422</span>&#160;<span class="comment"> *   &#39;!value&#39;, which displays the value of each item</span></div>
<div class="line"><a name="l00423"></a><span class="lineno">  423</span>&#160;<span class="comment"> *   in the $options array to the user.  Use &#39;!key&#39; to</span></div>
<div class="line"><a name="l00424"></a><span class="lineno">  424</span>&#160;<span class="comment"> *   display the key instead.  In some instances, it may</span></div>
<div class="line"><a name="l00425"></a><span class="lineno">  425</span>&#160;<span class="comment"> *   be useful to display both the key and the value; for</span></div>
<div class="line"><a name="l00426"></a><span class="lineno">  426</span>&#160;<span class="comment"> *   example, if the key is a user id and the value is the</span></div>
<div class="line"><a name="l00427"></a><span class="lineno">  427</span>&#160;<span class="comment"> *   user name, use &#39;!value (uid=!key)&#39;.</span></div>
<div class="line"><a name="l00428"></a><span class="lineno">  428</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00429"></a><span class="lineno"><a class="code" href="group__userinput.html#ga7e823bcd58051b17e6e5601340f0c784">  429</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__userinput.html#ga7e823bcd58051b17e6e5601340f0c784">drush_choice</a>($options, $prompt = <span class="stringliteral">&#39;Enter a number.&#39;</span>, $label = <span class="stringliteral">&#39;!value&#39;</span>, $widths = array()) {</div>
<div class="line"><a name="l00430"></a><span class="lineno">  430</span>&#160;  <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>($prompt));</div>
<div class="line"><a name="l00431"></a><span class="lineno">  431</span>&#160;</div>
<div class="line"><a name="l00432"></a><span class="lineno">  432</span>&#160;  <span class="comment">// Preflight so that all rows will be padded out to the same number of columns</span></div>
<div class="line"><a name="l00433"></a><span class="lineno">  433</span>&#160;  $array_pad = 0;</div>
<div class="line"><a name="l00434"></a><span class="lineno">  434</span>&#160;  <span class="keywordflow">foreach</span> ($options as $key =&gt; $option) {</div>
<div class="line"><a name="l00435"></a><span class="lineno">  435</span>&#160;    <span class="keywordflow">if</span> (is_array($option) &amp;&amp; (count($option) &gt; $array_pad)) {</div>
<div class="line"><a name="l00436"></a><span class="lineno">  436</span>&#160;      $array_pad = count($option);</div>
<div class="line"><a name="l00437"></a><span class="lineno">  437</span>&#160;    }</div>
<div class="line"><a name="l00438"></a><span class="lineno">  438</span>&#160;  }</div>
<div class="line"><a name="l00439"></a><span class="lineno">  439</span>&#160;</div>
<div class="line"><a name="l00440"></a><span class="lineno">  440</span>&#160;  $rows[] = array_pad(array(<span class="stringliteral">&#39;[0]&#39;</span>, <span class="charliteral">&#39;:&#39;</span>, <span class="stringliteral">&#39;Cancel&#39;</span>), $array_pad + 2, <span class="stringliteral">&#39;&#39;</span>);</div>
<div class="line"><a name="l00441"></a><span class="lineno">  441</span>&#160;  $selection_number = 0;</div>
<div class="line"><a name="l00442"></a><span class="lineno">  442</span>&#160;  <span class="keywordflow">foreach</span> ($options as $key =&gt; $option) {</div>
<div class="line"><a name="l00443"></a><span class="lineno">  443</span>&#160;    <span class="keywordflow">if</span> ((substr($key, 0, 3) == <span class="stringliteral">&#39;-- &#39;</span>) &amp;&amp; (substr($key, -3) == <span class="stringliteral">&#39; --&#39;</span>)) {</div>
<div class="line"><a name="l00444"></a><span class="lineno">  444</span>&#160;      $rows[] = array_pad(array(<span class="stringliteral">&#39;&#39;</span>, <span class="stringliteral">&#39;&#39;</span>, $option), $array_pad + 2, <span class="stringliteral">&#39;&#39;</span>);</div>
<div class="line"><a name="l00445"></a><span class="lineno">  445</span>&#160;    }</div>
<div class="line"><a name="l00446"></a><span class="lineno">  446</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00447"></a><span class="lineno">  447</span>&#160;      $selection_number++;</div>
<div class="line"><a name="l00448"></a><span class="lineno">  448</span>&#160;      $row = array(<span class="stringliteral">&quot;[$selection_number]&quot;</span>, <span class="charliteral">&#39;:&#39;</span>);</div>
<div class="line"><a name="l00449"></a><span class="lineno">  449</span>&#160;      <span class="keywordflow">if</span> (is_array($option)) {</div>
<div class="line"><a name="l00450"></a><span class="lineno">  450</span>&#160;        $row = array_merge($row, $option);</div>
<div class="line"><a name="l00451"></a><span class="lineno">  451</span>&#160;      }</div>
<div class="line"><a name="l00452"></a><span class="lineno">  452</span>&#160;      <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00453"></a><span class="lineno">  453</span>&#160;        $row[] = <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>($label, array(<span class="stringliteral">&#39;!number&#39;</span> =&gt; $selection_number, <span class="stringliteral">&#39;!key&#39;</span> =&gt; $key, <span class="stringliteral">&#39;!value&#39;</span> =&gt; $option));</div>
<div class="line"><a name="l00454"></a><span class="lineno">  454</span>&#160;      }</div>
<div class="line"><a name="l00455"></a><span class="lineno">  455</span>&#160;      $rows[] = $row;</div>
<div class="line"><a name="l00456"></a><span class="lineno">  456</span>&#160;      $selection_list[$selection_number] = $key;</div>
<div class="line"><a name="l00457"></a><span class="lineno">  457</span>&#160;    }</div>
<div class="line"><a name="l00458"></a><span class="lineno">  458</span>&#160;  }</div>
<div class="line"><a name="l00459"></a><span class="lineno">  459</span>&#160;  <a class="code" href="group__outputfunctions.html#ga2dfb80176f98c67097334acfa98211cd">drush_print_table</a>($rows, FALSE, $widths);</div>
<div class="line"><a name="l00460"></a><span class="lineno">  460</span>&#160;  <a class="code" href="group__outputfunctions.html#ga03664ee5326159c3f8e6c97aa93c7981">drush_print_pipe</a>(array_keys($options));</div>
<div class="line"><a name="l00461"></a><span class="lineno">  461</span>&#160;</div>
<div class="line"><a name="l00462"></a><span class="lineno">  462</span>&#160;  <span class="comment">// If the user specified --choice, then make an</span></div>
<div class="line"><a name="l00463"></a><span class="lineno">  463</span>&#160;  <span class="comment">// automatic selection.  Cancel if the choice is</span></div>
<div class="line"><a name="l00464"></a><span class="lineno">  464</span>&#160;  <span class="comment">// not an available option.</span></div>
<div class="line"><a name="l00465"></a><span class="lineno">  465</span>&#160;  <span class="keywordflow">if</span> (($choice = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;choice&#39;</span>, FALSE)) !== FALSE) {</div>
<div class="line"><a name="l00466"></a><span class="lineno">  466</span>&#160;    <span class="comment">// First check to see if $choice is one of the symbolic options</span></div>
<div class="line"><a name="l00467"></a><span class="lineno">  467</span>&#160;    <span class="keywordflow">if</span> (array_key_exists($choice, $options)) {</div>
<div class="line"><a name="l00468"></a><span class="lineno">  468</span>&#160;      <span class="keywordflow">return</span> $choice;</div>
<div class="line"><a name="l00469"></a><span class="lineno">  469</span>&#160;    }</div>
<div class="line"><a name="l00470"></a><span class="lineno">  470</span>&#160;    <span class="comment">// Next handle numeric selections</span></div>
<div class="line"><a name="l00471"></a><span class="lineno">  471</span>&#160;    elseif (array_key_exists($choice, $selection_list)) {</div>
<div class="line"><a name="l00472"></a><span class="lineno">  472</span>&#160;      <span class="keywordflow">return</span> $selection_list[$choice];</div>
<div class="line"><a name="l00473"></a><span class="lineno">  473</span>&#160;    }</div>
<div class="line"><a name="l00474"></a><span class="lineno">  474</span>&#160;    <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00475"></a><span class="lineno">  475</span>&#160;  }</div>
<div class="line"><a name="l00476"></a><span class="lineno">  476</span>&#160;</div>
<div class="line"><a name="l00477"></a><span class="lineno">  477</span>&#160;  <span class="comment">// If the user specified --no, then cancel; also avoid</span></div>
<div class="line"><a name="l00478"></a><span class="lineno">  478</span>&#160;  <span class="comment">// getting hung up waiting for user input in --pipe and</span></div>
<div class="line"><a name="l00479"></a><span class="lineno">  479</span>&#160;  <span class="comment">// backend modes.  If none of these apply, then wait,</span></div>
<div class="line"><a name="l00480"></a><span class="lineno">  480</span>&#160;  <span class="comment">// for user input and return the selected result.</span></div>
<div class="line"><a name="l00481"></a><span class="lineno">  481</span>&#160;  <span class="keywordflow">if</span> (!<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_NEGATIVE&#39;</span>) &amp;&amp; !<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_AFFIRMATIVE&#39;</span>) &amp;&amp; !<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_PIPE&#39;</span>)) {</div>
<div class="line"><a name="l00482"></a><span class="lineno">  482</span>&#160;    <span class="keywordflow">while</span> ($line = trim(fgets(STDIN))) {</div>
<div class="line"><a name="l00483"></a><span class="lineno">  483</span>&#160;      <span class="keywordflow">if</span> (array_key_exists($line, $selection_list)) {</div>
<div class="line"><a name="l00484"></a><span class="lineno">  484</span>&#160;        <span class="keywordflow">return</span> $selection_list[$line];</div>
<div class="line"><a name="l00485"></a><span class="lineno">  485</span>&#160;      }</div>
<div class="line"><a name="l00486"></a><span class="lineno">  486</span>&#160;    }</div>
<div class="line"><a name="l00487"></a><span class="lineno">  487</span>&#160;  }</div>
<div class="line"><a name="l00488"></a><span class="lineno">  488</span>&#160;  <span class="comment">// We will allow --yes to confirm input if there is only</span></div>
<div class="line"><a name="l00489"></a><span class="lineno">  489</span>&#160;  <span class="comment">// one choice; otherwise, --yes will cancel to avoid ambiguity</span></div>
<div class="line"><a name="l00490"></a><span class="lineno">  490</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_AFFIRMATIVE&#39;</span>)  &amp;&amp; (count($options) == 1)) {</div>
<div class="line"><a name="l00491"></a><span class="lineno">  491</span>&#160;    <span class="keywordflow">return</span> $selection_list[1];</div>
<div class="line"><a name="l00492"></a><span class="lineno">  492</span>&#160;  }</div>
<div class="line"><a name="l00493"></a><span class="lineno">  493</span>&#160;  <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Cancelled&#39;</span>));</div>
<div class="line"><a name="l00494"></a><span class="lineno">  494</span>&#160;  <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00495"></a><span class="lineno">  495</span>&#160;}</div>
<div class="line"><a name="l00496"></a><span class="lineno">  496</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00497"></a><span class="lineno">  497</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00498"></a><span class="lineno">  498</span>&#160;<span class="comment"> * Ask the user to select multiple items from a list.</span></div>
<div class="line"><a name="l00499"></a><span class="lineno">  499</span>&#160;<span class="comment"> * This is a wrapper around drush_choice, that repeats the selection process,</span></div>
<div class="line"><a name="l00500"></a><span class="lineno">  500</span>&#160;<span class="comment"> * allowing users to toggle a number of items in a list. The number of values</span></div>
<div class="line"><a name="l00501"></a><span class="lineno">  501</span>&#160;<span class="comment"> * that can be constrained by both min and max: the user will only be allowed</span></div>
<div class="line"><a name="l00502"></a><span class="lineno">  502</span>&#160;<span class="comment"> * finalize selection once the minimum number has been selected, and the oldest</span></div>
<div class="line"><a name="l00503"></a><span class="lineno">  503</span>&#160;<span class="comment"> * selected value will &quot;drop off&quot; the list, if they exceed the maximum number.</span></div>
<div class="line"><a name="l00504"></a><span class="lineno">  504</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00505"></a><span class="lineno">  505</span>&#160;<span class="comment"> * @param $options</span></div>
<div class="line"><a name="l00506"></a><span class="lineno">  506</span>&#160;<span class="comment"> *   Same as drush_choice() (see above).</span></div>
<div class="line"><a name="l00507"></a><span class="lineno">  507</span>&#160;<span class="comment"> * @param $defaults</span></div>
<div class="line"><a name="l00508"></a><span class="lineno">  508</span>&#160;<span class="comment"> *   This can take 3 forms:</span></div>
<div class="line"><a name="l00509"></a><span class="lineno">  509</span>&#160;<span class="comment"> *   - FALSE: (Default) All options are unselected by default.</span></div>
<div class="line"><a name="l00510"></a><span class="lineno">  510</span>&#160;<span class="comment"> *   - TRUE: All options are selected by default.</span></div>
<div class="line"><a name="l00511"></a><span class="lineno">  511</span>&#160;<span class="comment"> *   - Array of $options keys to be selected by default.</span></div>
<div class="line"><a name="l00512"></a><span class="lineno">  512</span>&#160;<span class="comment"> * @param $prompt</span></div>
<div class="line"><a name="l00513"></a><span class="lineno">  513</span>&#160;<span class="comment"> *   Same as drush_choice() (see above).</span></div>
<div class="line"><a name="l00514"></a><span class="lineno">  514</span>&#160;<span class="comment"> * @param $label</span></div>
<div class="line"><a name="l00515"></a><span class="lineno">  515</span>&#160;<span class="comment"> *   Same as drush_choice() (see above).</span></div>
<div class="line"><a name="l00516"></a><span class="lineno">  516</span>&#160;<span class="comment"> * @param $mark</span></div>
<div class="line"><a name="l00517"></a><span class="lineno">  517</span>&#160;<span class="comment"> *   Controls how selected values are marked.  Defaults to &#39;!value (selected)&#39;.</span></div>
<div class="line"><a name="l00518"></a><span class="lineno">  518</span>&#160;<span class="comment"> * @param $min</span></div>
<div class="line"><a name="l00519"></a><span class="lineno">  519</span>&#160;<span class="comment"> *   Constraint on minimum number of selections. Defaults to zero. When fewer</span></div>
<div class="line"><a name="l00520"></a><span class="lineno">  520</span>&#160;<span class="comment"> *   options than this are selected, no final options will be available.</span></div>
<div class="line"><a name="l00521"></a><span class="lineno">  521</span>&#160;<span class="comment"> * @param $max</span></div>
<div class="line"><a name="l00522"></a><span class="lineno">  522</span>&#160;<span class="comment"> *   Constraint on minimum number of selections. Defaults to NULL (unlimited).</span></div>
<div class="line"><a name="l00523"></a><span class="lineno">  523</span>&#160;<span class="comment"> *   If the a new selection causes this value to be exceeded, the oldest</span></div>
<div class="line"><a name="l00524"></a><span class="lineno">  524</span>&#160;<span class="comment"> *   previously selected value is automatically unselected.</span></div>
<div class="line"><a name="l00525"></a><span class="lineno">  525</span>&#160;<span class="comment"> * @param $final_options</span></div>
<div class="line"><a name="l00526"></a><span class="lineno">  526</span>&#160;<span class="comment"> *   An array of additional options in the same format as $options.</span></div>
<div class="line"><a name="l00527"></a><span class="lineno">  527</span>&#160;<span class="comment"> *   When the minimum number of selections is met, this array is merged into the</span></div>
<div class="line"><a name="l00528"></a><span class="lineno">  528</span>&#160;<span class="comment"> *   array of options. If the user selects one of these values and the</span></div>
<div class="line"><a name="l00529"></a><span class="lineno">  529</span>&#160;<span class="comment"> *   selection process will complete (the key for the final option is included</span></div>
<div class="line"><a name="l00530"></a><span class="lineno">  530</span>&#160;<span class="comment"> *   in the return value). If this is an empty array (default), then a built in</span></div>
<div class="line"><a name="l00531"></a><span class="lineno">  531</span>&#160;<span class="comment"> *   final option of &quot;Done&quot; will be added to the available options (in this case</span></div>
<div class="line"><a name="l00532"></a><span class="lineno">  532</span>&#160;<span class="comment"> *   no additional keys are added to the return value).</span></div>
<div class="line"><a name="l00533"></a><span class="lineno">  533</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00534"></a><span class="lineno"><a class="code" href="group__userinput.html#ga915b9fa18b5e95b387bddf5a50a266fe">  534</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__userinput.html#ga915b9fa18b5e95b387bddf5a50a266fe">drush_choice_multiple</a>($options, $defaults = FALSE, $prompt = <span class="stringliteral">&#39;Select some numbers.&#39;</span>, $label = <span class="stringliteral">&#39;!value&#39;</span>, $mark = <span class="stringliteral">&#39;!value (selected)&#39;</span>, $min = 0, $max = NULL, $final_options = array()) {</div>
<div class="line"><a name="l00535"></a><span class="lineno">  535</span>&#160;  $selections = array();</div>
<div class="line"><a name="l00536"></a><span class="lineno">  536</span>&#160;  <span class="comment">// Load default selections.</span></div>
<div class="line"><a name="l00537"></a><span class="lineno">  537</span>&#160;  <span class="keywordflow">if</span> (is_array($defaults)) {</div>
<div class="line"><a name="l00538"></a><span class="lineno">  538</span>&#160;    $selections = $defaults;</div>
<div class="line"><a name="l00539"></a><span class="lineno">  539</span>&#160;  }</div>
<div class="line"><a name="l00540"></a><span class="lineno">  540</span>&#160;  elseif ($defaults === TRUE) {</div>
<div class="line"><a name="l00541"></a><span class="lineno">  541</span>&#160;    $selections = array_keys($options);</div>
<div class="line"><a name="l00542"></a><span class="lineno">  542</span>&#160;  }</div>
<div class="line"><a name="l00543"></a><span class="lineno">  543</span>&#160;  $complete = FALSE;</div>
<div class="line"><a name="l00544"></a><span class="lineno">  544</span>&#160;  $final_builtin = array();</div>
<div class="line"><a name="l00545"></a><span class="lineno">  545</span>&#160;  <span class="keywordflow">if</span> (empty($final_options)) {</div>
<div class="line"><a name="l00546"></a><span class="lineno">  546</span>&#160;    $final_builtin[<span class="stringliteral">&#39;done&#39;</span>] = <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Done&#39;</span>);</div>
<div class="line"><a name="l00547"></a><span class="lineno">  547</span>&#160;  }</div>
<div class="line"><a name="l00548"></a><span class="lineno">  548</span>&#160;  $final_options_keys = array_keys($final_options);</div>
<div class="line"><a name="l00549"></a><span class="lineno">  549</span>&#160;  <span class="keywordflow">while</span> (TRUE) {</div>
<div class="line"><a name="l00550"></a><span class="lineno">  550</span>&#160;    $current_options = $options;</div>
<div class="line"><a name="l00551"></a><span class="lineno">  551</span>&#160;    <span class="comment">// Mark selections.</span></div>
<div class="line"><a name="l00552"></a><span class="lineno">  552</span>&#160;    <span class="keywordflow">foreach</span> ($selections as $selection) {</div>
<div class="line"><a name="l00553"></a><span class="lineno">  553</span>&#160;      $current_options[$selection] = <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>($mark, array(<span class="stringliteral">&#39;!key&#39;</span> =&gt; $selection, <span class="stringliteral">&#39;!value&#39;</span> =&gt; $options[$selection]));</div>
<div class="line"><a name="l00554"></a><span class="lineno">  554</span>&#160;    }</div>
<div class="line"><a name="l00555"></a><span class="lineno">  555</span>&#160;    <span class="comment">// Add final options, if the minimum number of selections has been reached.</span></div>
<div class="line"><a name="l00556"></a><span class="lineno">  556</span>&#160;    <span class="keywordflow">if</span> (count($selections) &gt;= $min) {</div>
<div class="line"><a name="l00557"></a><span class="lineno">  557</span>&#160;      $current_options = array_merge($current_options, $final_options, $final_builtin);</div>
<div class="line"><a name="l00558"></a><span class="lineno">  558</span>&#160;    }</div>
<div class="line"><a name="l00559"></a><span class="lineno">  559</span>&#160;    $toggle = <a class="code" href="group__userinput.html#ga7e823bcd58051b17e6e5601340f0c784">drush_choice</a>($current_options, $prompt, $label);</div>
<div class="line"><a name="l00560"></a><span class="lineno">  560</span>&#160;    <span class="keywordflow">if</span> ($toggle === FALSE) {</div>
<div class="line"><a name="l00561"></a><span class="lineno">  561</span>&#160;      <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00562"></a><span class="lineno">  562</span>&#160;    }</div>
<div class="line"><a name="l00563"></a><span class="lineno">  563</span>&#160;    <span class="comment">// Don&#39;t include the built in final option in the return value.</span></div>
<div class="line"><a name="l00564"></a><span class="lineno">  564</span>&#160;    <span class="keywordflow">if</span> (count($selections) &gt;= $min &amp;&amp; empty($final_options) &amp;&amp; $toggle == <span class="stringliteral">&#39;done&#39;</span>) {</div>
<div class="line"><a name="l00565"></a><span class="lineno">  565</span>&#160;      <span class="keywordflow">return</span> $selections;</div>
<div class="line"><a name="l00566"></a><span class="lineno">  566</span>&#160;    }</div>
<div class="line"><a name="l00567"></a><span class="lineno">  567</span>&#160;    <span class="comment">// Toggle the selected value.</span></div>
<div class="line"><a name="l00568"></a><span class="lineno">  568</span>&#160;    $item = array_search($toggle, $selections);</div>
<div class="line"><a name="l00569"></a><span class="lineno">  569</span>&#160;    <span class="keywordflow">if</span> ($item === FALSE) {</div>
<div class="line"><a name="l00570"></a><span class="lineno">  570</span>&#160;      array_unshift($selections, $toggle);</div>
<div class="line"><a name="l00571"></a><span class="lineno">  571</span>&#160;    }</div>
<div class="line"><a name="l00572"></a><span class="lineno">  572</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00573"></a><span class="lineno">  573</span>&#160;      unset($selections[$item]);</div>
<div class="line"><a name="l00574"></a><span class="lineno">  574</span>&#160;    }</div>
<div class="line"><a name="l00575"></a><span class="lineno">  575</span>&#160;    <span class="comment">// If the user selected one of the final options, return.</span></div>
<div class="line"><a name="l00576"></a><span class="lineno">  576</span>&#160;    <span class="keywordflow">if</span> (count($selections) &gt;= $min &amp;&amp; in_array($toggle, $final_options_keys)) {</div>
<div class="line"><a name="l00577"></a><span class="lineno">  577</span>&#160;      <span class="keywordflow">return</span> $selections;</div>
<div class="line"><a name="l00578"></a><span class="lineno">  578</span>&#160;    }</div>
<div class="line"><a name="l00579"></a><span class="lineno">  579</span>&#160;    <span class="comment">// If the user selected too many options, drop the oldest selection.</span></div>
<div class="line"><a name="l00580"></a><span class="lineno">  580</span>&#160;    <span class="keywordflow">if</span> (isset($max) &amp;&amp; count($selections) &gt; $max) {</div>
<div class="line"><a name="l00581"></a><span class="lineno">  581</span>&#160;      array_pop($selections);</div>
<div class="line"><a name="l00582"></a><span class="lineno">  582</span>&#160;    }</div>
<div class="line"><a name="l00583"></a><span class="lineno">  583</span>&#160;  }</div>
<div class="line"><a name="l00584"></a><span class="lineno">  584</span>&#160;}</div>
<div class="line"><a name="l00585"></a><span class="lineno">  585</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00586"></a><span class="lineno">  586</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00587"></a><span class="lineno">  587</span>&#160;<span class="comment"> * Prompt the user for input</span></div>
<div class="line"><a name="l00588"></a><span class="lineno">  588</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00589"></a><span class="lineno">  589</span>&#160;<span class="comment"> * The input can be anything that fits on a single line (not only y/n),</span></div>
<div class="line"><a name="l00590"></a><span class="lineno">  590</span>&#160;<span class="comment"> * so we can&#39;t use drush_confirm()</span></div>
<div class="line"><a name="l00591"></a><span class="lineno">  591</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00592"></a><span class="lineno">  592</span>&#160;<span class="comment"> * @param $prompt</span></div>
<div class="line"><a name="l00593"></a><span class="lineno">  593</span>&#160;<span class="comment"> *   The text which is displayed to the user.</span></div>
<div class="line"><a name="l00594"></a><span class="lineno">  594</span>&#160;<span class="comment"> * @param $default</span></div>
<div class="line"><a name="l00595"></a><span class="lineno">  595</span>&#160;<span class="comment"> *   The default value of the input.</span></div>
<div class="line"><a name="l00596"></a><span class="lineno">  596</span>&#160;<span class="comment"> * @param $required</span></div>
<div class="line"><a name="l00597"></a><span class="lineno">  597</span>&#160;<span class="comment"> *   If TRUE, user may continue even when no value is in the input.</span></div>
<div class="line"><a name="l00598"></a><span class="lineno">  598</span>&#160;<span class="comment"> * @param $password</span></div>
<div class="line"><a name="l00599"></a><span class="lineno">  599</span>&#160;<span class="comment"> *   If TRUE, surpress printing of the input.</span></div>
<div class="line"><a name="l00600"></a><span class="lineno">  600</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00601"></a><span class="lineno">  601</span>&#160;<span class="comment"> * @see drush_confirm()</span></div>
<div class="line"><a name="l00602"></a><span class="lineno">  602</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00603"></a><span class="lineno"><a class="code" href="group__userinput.html#gabbb9a40c8f7e0ba5ec384ccf86305a20">  603</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__userinput.html#gabbb9a40c8f7e0ba5ec384ccf86305a20">drush_prompt</a>($prompt, $default = NULL, $required = TRUE, $password = FALSE) {</div>
<div class="line"><a name="l00604"></a><span class="lineno">  604</span>&#160;  <span class="keywordflow">if</span> (isset($default)) {</div>
<div class="line"><a name="l00605"></a><span class="lineno">  605</span>&#160;    $prompt .= <span class="stringliteral">&quot; [&quot;</span> . $default . <span class="stringliteral">&quot;]&quot;</span>;</div>
<div class="line"><a name="l00606"></a><span class="lineno">  606</span>&#160;  }</div>
<div class="line"><a name="l00607"></a><span class="lineno">  607</span>&#160;  $prompt .= <span class="stringliteral">&quot;: &quot;</span>;</div>
<div class="line"><a name="l00608"></a><span class="lineno">  608</span>&#160;</div>
<div class="line"><a name="l00609"></a><span class="lineno">  609</span>&#160;  <a class="code" href="group__outputfunctions.html#ga6dc4aa94bd0a854c564a2538e166c749">drush_print_prompt</a>($prompt);</div>
<div class="line"><a name="l00610"></a><span class="lineno">  610</span>&#160;</div>
<div class="line"><a name="l00611"></a><span class="lineno">  611</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_AFFIRMATIVE&#39;</span>)) {</div>
<div class="line"><a name="l00612"></a><span class="lineno">  612</span>&#160;    <span class="keywordflow">return</span> $default;</div>
<div class="line"><a name="l00613"></a><span class="lineno">  613</span>&#160;  }</div>
<div class="line"><a name="l00614"></a><span class="lineno">  614</span>&#160;</div>
<div class="line"><a name="l00615"></a><span class="lineno">  615</span>&#160;  $stdin = fopen(<span class="stringliteral">&#39;php://stdin&#39;</span>, <span class="charliteral">&#39;r&#39;</span>);</div>
<div class="line"><a name="l00616"></a><span class="lineno">  616</span>&#160;</div>
<div class="line"><a name="l00617"></a><span class="lineno">  617</span>&#160;  <span class="keywordflow">if</span> ($password) <a class="code" href="group__commandwrappers.html#gafd358ceac1286dbdd141ff2b8eb7d556">drush_shell_exec</a>(<span class="stringliteral">&quot;stty -echo&quot;</span>);</div>
<div class="line"><a name="l00618"></a><span class="lineno">  618</span>&#160;</div>
<div class="line"><a name="l00619"></a><span class="lineno">  619</span>&#160;  stream_set_blocking($stdin, TRUE);</div>
<div class="line"><a name="l00620"></a><span class="lineno">  620</span>&#160;  <span class="keywordflow">while</span> (($line = fgets($stdin)) !== FALSE) {</div>
<div class="line"><a name="l00621"></a><span class="lineno">  621</span>&#160;    $line = trim($line);</div>
<div class="line"><a name="l00622"></a><span class="lineno">  622</span>&#160;    <span class="keywordflow">if</span> ($line === <span class="stringliteral">&quot;&quot;</span>) {</div>
<div class="line"><a name="l00623"></a><span class="lineno">  623</span>&#160;      $line = $default;</div>
<div class="line"><a name="l00624"></a><span class="lineno">  624</span>&#160;    }</div>
<div class="line"><a name="l00625"></a><span class="lineno">  625</span>&#160;    <span class="keywordflow">if</span> ($line || !$required) {</div>
<div class="line"><a name="l00626"></a><span class="lineno">  626</span>&#160;      <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00627"></a><span class="lineno">  627</span>&#160;    }</div>
<div class="line"><a name="l00628"></a><span class="lineno">  628</span>&#160;    <a class="code" href="group__outputfunctions.html#ga6dc4aa94bd0a854c564a2538e166c749">drush_print_prompt</a>($prompt);</div>
<div class="line"><a name="l00629"></a><span class="lineno">  629</span>&#160;  }</div>
<div class="line"><a name="l00630"></a><span class="lineno">  630</span>&#160;  fclose($stdin);</div>
<div class="line"><a name="l00631"></a><span class="lineno">  631</span>&#160;  <span class="keywordflow">if</span> ($password) {</div>
<div class="line"><a name="l00632"></a><span class="lineno">  632</span>&#160;    <a class="code" href="group__commandwrappers.html#gafd358ceac1286dbdd141ff2b8eb7d556">drush_shell_exec</a>(<span class="stringliteral">&quot;stty echo&quot;</span>);</div>
<div class="line"><a name="l00633"></a><span class="lineno">  633</span>&#160;    print <span class="stringliteral">&quot;\n&quot;</span>;</div>
<div class="line"><a name="l00634"></a><span class="lineno">  634</span>&#160;  }</div>
<div class="line"><a name="l00635"></a><span class="lineno">  635</span>&#160;  <span class="keywordflow">return</span> $line;</div>
<div class="line"><a name="l00636"></a><span class="lineno">  636</span>&#160;}</div>
<div class="line"><a name="l00637"></a><span class="lineno">  637</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00638"></a><span class="lineno">  638</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00639"></a><span class="lineno">  639</span>&#160;<span class="comment"> * @} End of &quot;defgroup userinput&quot;.</span></div>
<div class="line"><a name="l00640"></a><span class="lineno">  640</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00641"></a><span class="lineno">  641</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00642"></a><span class="lineno">  642</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00643"></a><span class="lineno">  643</span>&#160;<span class="comment"> * Calls a given function, passing through all arguments unchanged.</span></div>
<div class="line"><a name="l00644"></a><span class="lineno">  644</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00645"></a><span class="lineno">  645</span>&#160;<span class="comment"> * This should be used when calling possibly mutative or destructive functions</span></div>
<div class="line"><a name="l00646"></a><span class="lineno">  646</span>&#160;<span class="comment"> * (e.g. unlink() and other file system functions) so that can be suppressed</span></div>
<div class="line"><a name="l00647"></a><span class="lineno">  647</span>&#160;<span class="comment"> * if the simulation mode is enabled.</span></div>
<div class="line"><a name="l00648"></a><span class="lineno">  648</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00649"></a><span class="lineno">  649</span>&#160;<span class="comment"> * Important:  Call @see drush_op_system() to execute a shell command,</span></div>
<div class="line"><a name="l00650"></a><span class="lineno">  650</span>&#160;<span class="comment"> * or @see drush_shell_exec() to execute a shell command and capture the</span></div>
<div class="line"><a name="l00651"></a><span class="lineno">  651</span>&#160;<span class="comment"> * shell output.</span></div>
<div class="line"><a name="l00652"></a><span class="lineno">  652</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00653"></a><span class="lineno">  653</span>&#160;<span class="comment"> * @param $function</span></div>
<div class="line"><a name="l00654"></a><span class="lineno">  654</span>&#160;<span class="comment"> *   The name of the function. Any additional arguments are passed along.</span></div>
<div class="line"><a name="l00655"></a><span class="lineno">  655</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l00656"></a><span class="lineno">  656</span>&#160;<span class="comment"> *   The return value of the function, or TRUE if simulation mode is enabled.</span></div>
<div class="line"><a name="l00657"></a><span class="lineno">  657</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00658"></a><span class="lineno">  658</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00659"></a><span class="lineno"><a class="code" href="drush_8inc.html#a903c36790dbe5525fe9369c8476780af">  659</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a903c36790dbe5525fe9369c8476780af">drush_op</a>($function) {</div>
<div class="line"><a name="l00660"></a><span class="lineno">  660</span>&#160;  $args_printed = array();</div>
<div class="line"><a name="l00661"></a><span class="lineno">  661</span>&#160;  $args = func_get_args();</div>
<div class="line"><a name="l00662"></a><span class="lineno">  662</span>&#160;  array_shift($args); <span class="comment">// Skip function name</span></div>
<div class="line"><a name="l00663"></a><span class="lineno">  663</span>&#160;  <span class="keywordflow">foreach</span> ($args as $arg) {</div>
<div class="line"><a name="l00664"></a><span class="lineno">  664</span>&#160;    $args_printed[] = is_scalar($arg) ? $arg : (is_array($arg) ? <span class="stringliteral">&#39;Array&#39;</span> : <span class="stringliteral">&#39;Object&#39;</span>);</div>
<div class="line"><a name="l00665"></a><span class="lineno">  665</span>&#160;  }</div>
<div class="line"><a name="l00666"></a><span class="lineno">  666</span>&#160;</div>
<div class="line"><a name="l00667"></a><span class="lineno">  667</span>&#160;  <span class="comment">// Special checking for drush_op(&#39;system&#39;)</span></div>
<div class="line"><a name="l00668"></a><span class="lineno">  668</span>&#160;  <span class="keywordflow">if</span> ($function == <span class="stringliteral">&#39;system&#39;</span>) {</div>
<div class="line"><a name="l00669"></a><span class="lineno">  669</span>&#160;    <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;Do not call drush_op(&#39;system&#39;); use drush_op_system instead&quot;</span>), <span class="stringliteral">&#39;debug&#39;</span>);</div>
<div class="line"><a name="l00670"></a><span class="lineno">  670</span>&#160;  }</div>
<div class="line"><a name="l00671"></a><span class="lineno">  671</span>&#160;</div>
<div class="line"><a name="l00672"></a><span class="lineno">  672</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_VERBOSE&#39;</span>) || <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_SIMULATE&#39;</span>)) {</div>
<div class="line"><a name="l00673"></a><span class="lineno">  673</span>&#160;     <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(sprintf(<span class="stringliteral">&quot;Calling %s(%s)&quot;</span>, $function, implode(<span class="stringliteral">&quot;, &quot;</span>, $args_printed)), <span class="stringliteral">&#39;debug&#39;</span>);</div>
<div class="line"><a name="l00674"></a><span class="lineno">  674</span>&#160;  }</div>
<div class="line"><a name="l00675"></a><span class="lineno">  675</span>&#160;</div>
<div class="line"><a name="l00676"></a><span class="lineno">  676</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_SIMULATE&#39;</span>)) {</div>
<div class="line"><a name="l00677"></a><span class="lineno">  677</span>&#160;    <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l00678"></a><span class="lineno">  678</span>&#160;  }</div>
<div class="line"><a name="l00679"></a><span class="lineno">  679</span>&#160;</div>
<div class="line"><a name="l00680"></a><span class="lineno">  680</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="drush_8inc.html#a2dd83647cc42a2dfcde54dc38f54827d">drush_call_user_func_array</a>($function, $args);</div>
<div class="line"><a name="l00681"></a><span class="lineno">  681</span>&#160;}</div>
<div class="line"><a name="l00682"></a><span class="lineno">  682</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00683"></a><span class="lineno">  683</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00684"></a><span class="lineno">  684</span>&#160;<span class="comment"> * Mimic cufa but still call function directly. See http://drupal.org/node/329012#comment-1260752</span></div>
<div class="line"><a name="l00685"></a><span class="lineno">  685</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00686"></a><span class="lineno"><a class="code" href="drush_8inc.html#a2dd83647cc42a2dfcde54dc38f54827d">  686</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a2dd83647cc42a2dfcde54dc38f54827d">drush_call_user_func_array</a>($function, $args = array() ) {</div>
<div class="line"><a name="l00687"></a><span class="lineno">  687</span>&#160;  <span class="keywordflow">switch</span> (count($args)) {</div>
<div class="line"><a name="l00688"></a><span class="lineno">  688</span>&#160;    <span class="keywordflow">case</span> 0: <span class="keywordflow">return</span> $function(); <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00689"></a><span class="lineno">  689</span>&#160;    <span class="keywordflow">case</span> 1: <span class="keywordflow">return</span> $function($args[0]); <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00690"></a><span class="lineno">  690</span>&#160;    <span class="keywordflow">case</span> 2: <span class="keywordflow">return</span> $function($args[0], $args[1]); <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00691"></a><span class="lineno">  691</span>&#160;    <span class="keywordflow">case</span> 3: <span class="keywordflow">return</span> $function($args[0], $args[1], $args[2]); <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00692"></a><span class="lineno">  692</span>&#160;    <span class="keywordflow">case</span> 4: <span class="keywordflow">return</span> $function($args[0], $args[1], $args[2], $args[3]); <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00693"></a><span class="lineno">  693</span>&#160;    <span class="keywordflow">case</span> 5: <span class="keywordflow">return</span> $function($args[0], $args[1], $args[2], $args[3], $args[4]); <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00694"></a><span class="lineno">  694</span>&#160;    <span class="keywordflow">case</span> 6: <span class="keywordflow">return</span> $function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5]); <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00695"></a><span class="lineno">  695</span>&#160;    <span class="keywordflow">case</span> 7: <span class="keywordflow">return</span> $function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6]); <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00696"></a><span class="lineno">  696</span>&#160;    <span class="keywordflow">case</span> 8: <span class="keywordflow">return</span> $function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7]); <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00697"></a><span class="lineno">  697</span>&#160;    <span class="keywordflow">case</span> 9: <span class="keywordflow">return</span> $function($args[0], $args[1], $args[2], $args[3], $args[4], $args[5], $args[6], $args[7], $args[8]); <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00698"></a><span class="lineno">  698</span>&#160;    <span class="keywordflow">default</span>: <span class="keywordflow">return</span> call_user_func_array($function,$args);</div>
<div class="line"><a name="l00699"></a><span class="lineno">  699</span>&#160;  }</div>
<div class="line"><a name="l00700"></a><span class="lineno">  700</span>&#160;}</div>
<div class="line"><a name="l00701"></a><span class="lineno">  701</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00702"></a><span class="lineno">  702</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00703"></a><span class="lineno">  703</span>&#160;<span class="comment"> * Download a file using wget, curl or file_get_contents, or via download cache.</span></div>
<div class="line"><a name="l00704"></a><span class="lineno">  704</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00705"></a><span class="lineno">  705</span>&#160;<span class="comment"> * @param string $url</span></div>
<div class="line"><a name="l00706"></a><span class="lineno">  706</span>&#160;<span class="comment"> *   The url of the file to download.</span></div>
<div class="line"><a name="l00707"></a><span class="lineno">  707</span>&#160;<span class="comment"> * @param string $destination</span></div>
<div class="line"><a name="l00708"></a><span class="lineno">  708</span>&#160;<span class="comment"> *   The name of the file to be saved, which may include the full path.</span></div>
<div class="line"><a name="l00709"></a><span class="lineno">  709</span>&#160;<span class="comment"> *   Optional, if omitted the filename will be extracted from the url and the</span></div>
<div class="line"><a name="l00710"></a><span class="lineno">  710</span>&#160;<span class="comment"> *   file downloaded to the current working directory (Drupal root if</span></div>
<div class="line"><a name="l00711"></a><span class="lineno">  711</span>&#160;<span class="comment"> *   bootstrapped).</span></div>
<div class="line"><a name="l00712"></a><span class="lineno">  712</span>&#160;<span class="comment"> * @param integer $cache_duration</span></div>
<div class="line"><a name="l00713"></a><span class="lineno">  713</span>&#160;<span class="comment"> *   The acceptable age of a cached file. If cached file is too old, a fetch</span></div>
<div class="line"><a name="l00714"></a><span class="lineno">  714</span>&#160;<span class="comment"> *   will occur and cache will be updated. Optional, if ommitted the file will</span></div>
<div class="line"><a name="l00715"></a><span class="lineno">  715</span>&#160;<span class="comment"> *   be fetched directly.</span></div>
<div class="line"><a name="l00716"></a><span class="lineno">  716</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00717"></a><span class="lineno">  717</span>&#160;<span class="comment"> * @return string</span></div>
<div class="line"><a name="l00718"></a><span class="lineno">  718</span>&#160;<span class="comment"> *   The path to the downloaded file, or FALSE if the file could not be</span></div>
<div class="line"><a name="l00719"></a><span class="lineno">  719</span>&#160;<span class="comment"> *   downloaded.</span></div>
<div class="line"><a name="l00720"></a><span class="lineno">  720</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00721"></a><span class="lineno"><a class="code" href="drush_8inc.html#a9cce12bffedae74c4a45174c59c79311">  721</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a9cce12bffedae74c4a45174c59c79311">drush_download_file</a>($url, $destination = FALSE, $cache_duration = 0) {</div>
<div class="line"><a name="l00722"></a><span class="lineno">  722</span>&#160;  <span class="comment">// Generate destination if omitted.</span></div>
<div class="line"><a name="l00723"></a><span class="lineno">  723</span>&#160;  <span class="keywordflow">if</span> (!$destination) {</div>
<div class="line"><a name="l00724"></a><span class="lineno">  724</span>&#160;    $file = basename(current(explode(<span class="charliteral">&#39;?&#39;</span>, $url, 2)));</div>
<div class="line"><a name="l00725"></a><span class="lineno">  725</span>&#160;    $destination = getcwd() . <span class="charliteral">&#39;/&#39;</span> . basename($file);</div>
<div class="line"><a name="l00726"></a><span class="lineno">  726</span>&#160;  }</div>
<div class="line"><a name="l00727"></a><span class="lineno">  727</span>&#160;</div>
<div class="line"><a name="l00728"></a><span class="lineno">  728</span>&#160;  <span class="comment">// Simply copy local files to the destination</span></div>
<div class="line"><a name="l00729"></a><span class="lineno">  729</span>&#160;  <span class="keywordflow">if</span> (!<a class="code" href="drush_8inc.html#a5d3c123a1d8fa15642f08ff635dbe2a1">_drush_is_url</a>($url)) {</div>
<div class="line"><a name="l00730"></a><span class="lineno">  730</span>&#160;    <span class="keywordflow">return</span> copy($url, $destination) ? $destination : FALSE;</div>
<div class="line"><a name="l00731"></a><span class="lineno">  731</span>&#160;  }</div>
<div class="line"><a name="l00732"></a><span class="lineno">  732</span>&#160;</div>
<div class="line"><a name="l00733"></a><span class="lineno">  733</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;cache&#39;</span>) &amp;&amp; $cache_duration !== 0 &amp;&amp; $cache_file = <a class="code" href="drush_8inc.html#a6b7589c9e3cd3f683c0ef137e1c30f49">drush_download_file_name</a>($url)) {</div>
<div class="line"><a name="l00734"></a><span class="lineno">  734</span>&#160;    <span class="comment">// Check for cached, unexpired file.</span></div>
<div class="line"><a name="l00735"></a><span class="lineno">  735</span>&#160;    <span class="keywordflow">if</span> (file_exists($cache_file) &amp;&amp; filectime($cache_file) &gt; ($_SERVER[<span class="stringliteral">&#39;REQUEST_TIME&#39;</span>]-$cache_duration)) {</div>
<div class="line"><a name="l00736"></a><span class="lineno">  736</span>&#160;      <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;!name retrieved from cache.&#39;</span>, array(<span class="stringliteral">&#39;!name&#39;</span> =&gt; $cache_file)));</div>
<div class="line"><a name="l00737"></a><span class="lineno">  737</span>&#160;    }</div>
<div class="line"><a name="l00738"></a><span class="lineno">  738</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00739"></a><span class="lineno">  739</span>&#160;      <span class="keywordflow">if</span> (<a class="code" href="drush_8inc.html#a5c2a88712f3905874900166f3b2c397c">_drush_download_file</a>($url, $cache_file, TRUE)) {</div>
<div class="line"><a name="l00740"></a><span class="lineno">  740</span>&#160;        <span class="comment">// Cache was set just by downloading file to right location.</span></div>
<div class="line"><a name="l00741"></a><span class="lineno">  741</span>&#160;      }</div>
<div class="line"><a name="l00742"></a><span class="lineno">  742</span>&#160;      elseif (file_exists($cache_file)) {</div>
<div class="line"><a name="l00743"></a><span class="lineno">  743</span>&#160;        <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;!name retrieved from an expired cache since refresh failed.&#39;</span>, array(<span class="stringliteral">&#39;!name&#39;</span> =&gt; $cache_file)), <span class="stringliteral">&#39;warning&#39;</span>);</div>
<div class="line"><a name="l00744"></a><span class="lineno">  744</span>&#160;      }</div>
<div class="line"><a name="l00745"></a><span class="lineno">  745</span>&#160;      <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00746"></a><span class="lineno">  746</span>&#160;        $cache_file = FALSE;</div>
<div class="line"><a name="l00747"></a><span class="lineno">  747</span>&#160;      }</div>
<div class="line"><a name="l00748"></a><span class="lineno">  748</span>&#160;    }</div>
<div class="line"><a name="l00749"></a><span class="lineno">  749</span>&#160;</div>
<div class="line"><a name="l00750"></a><span class="lineno">  750</span>&#160;    <span class="keywordflow">if</span> ($cache_file &amp;&amp; copy($cache_file, $destination)) {</div>
<div class="line"><a name="l00751"></a><span class="lineno">  751</span>&#160;      <span class="comment">// Copy cached file to the destination</span></div>
<div class="line"><a name="l00752"></a><span class="lineno">  752</span>&#160;      <span class="keywordflow">return</span> $destination;</div>
<div class="line"><a name="l00753"></a><span class="lineno">  753</span>&#160;    }</div>
<div class="line"><a name="l00754"></a><span class="lineno">  754</span>&#160;  }</div>
<div class="line"><a name="l00755"></a><span class="lineno">  755</span>&#160;  elseif ($return = <a class="code" href="drush_8inc.html#a5c2a88712f3905874900166f3b2c397c">_drush_download_file</a>($url, $destination)) {</div>
<div class="line"><a name="l00756"></a><span class="lineno">  756</span>&#160;    <a class="code" href="group__filesystemfunctions.html#ga7557e035207db8d2dbe475e6a52c579c">drush_register_file_for_deletion</a>($return);</div>
<div class="line"><a name="l00757"></a><span class="lineno">  757</span>&#160;    <span class="keywordflow">return</span> $return;</div>
<div class="line"><a name="l00758"></a><span class="lineno">  758</span>&#160;  }</div>
<div class="line"><a name="l00759"></a><span class="lineno">  759</span>&#160;</div>
<div class="line"><a name="l00760"></a><span class="lineno">  760</span>&#160;  <span class="comment">// Unable to retrieve from cache nor download.</span></div>
<div class="line"><a name="l00761"></a><span class="lineno">  761</span>&#160;  <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00762"></a><span class="lineno">  762</span>&#160;}</div>
<div class="line"><a name="l00763"></a><span class="lineno">  763</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00764"></a><span class="lineno">  764</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00765"></a><span class="lineno">  765</span>&#160;<span class="comment"> * Helper function to determine name of cached file.</span></div>
<div class="line"><a name="l00766"></a><span class="lineno">  766</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00767"></a><span class="lineno"><a class="code" href="drush_8inc.html#a6b7589c9e3cd3f683c0ef137e1c30f49">  767</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a6b7589c9e3cd3f683c0ef137e1c30f49">drush_download_file_name</a>($url) {</div>
<div class="line"><a name="l00768"></a><span class="lineno">  768</span>&#160;  <span class="keywordflow">if</span> ($cache_dir = <a class="code" href="includes_2environment_8inc.html#a92afdf9afda25ac6d226ba45f6f1fbe0">drush_directory_cache</a>(<span class="stringliteral">&#39;download&#39;</span>)) {</div>
<div class="line"><a name="l00769"></a><span class="lineno">  769</span>&#160;    $cache_name = str_replace(array(<span class="charliteral">&#39;:&#39;</span>, <span class="charliteral">&#39;/&#39;</span>, <span class="charliteral">&#39;?&#39;</span>, <span class="charliteral">&#39;=&#39;</span>), <span class="charliteral">&#39;-&#39;</span>, $url);</div>
<div class="line"><a name="l00770"></a><span class="lineno">  770</span>&#160;    <span class="keywordflow">return</span> $cache_dir . <span class="stringliteral">&quot;/&quot;</span> . $cache_name;</div>
<div class="line"><a name="l00771"></a><span class="lineno">  771</span>&#160;  }</div>
<div class="line"><a name="l00772"></a><span class="lineno">  772</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00773"></a><span class="lineno">  773</span>&#160;    <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00774"></a><span class="lineno">  774</span>&#160;  }</div>
<div class="line"><a name="l00775"></a><span class="lineno">  775</span>&#160;}</div>
<div class="line"><a name="l00776"></a><span class="lineno">  776</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00777"></a><span class="lineno">  777</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00778"></a><span class="lineno">  778</span>&#160;<span class="comment"> * Check whether the given path is just a url or a local path</span></div>
<div class="line"><a name="l00779"></a><span class="lineno">  779</span>&#160;<span class="comment"> * @param string $url</span></div>
<div class="line"><a name="l00780"></a><span class="lineno">  780</span>&#160;<span class="comment"> * @return boolean</span></div>
<div class="line"><a name="l00781"></a><span class="lineno">  781</span>&#160;<span class="comment"> *   TRUE if the path does not contain a schema:// part.</span></div>
<div class="line"><a name="l00782"></a><span class="lineno">  782</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00783"></a><span class="lineno"><a class="code" href="drush_8inc.html#a5d3c123a1d8fa15642f08ff635dbe2a1">  783</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a5d3c123a1d8fa15642f08ff635dbe2a1">_drush_is_url</a>($url) {</div>
<div class="line"><a name="l00784"></a><span class="lineno">  784</span>&#160;  <span class="keywordflow">return</span> parse_url($url, PHP_URL_SCHEME) !== NULL;</div>
<div class="line"><a name="l00785"></a><span class="lineno">  785</span>&#160;}</div>
<div class="line"><a name="l00786"></a><span class="lineno">  786</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00787"></a><span class="lineno">  787</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00788"></a><span class="lineno">  788</span>&#160;<span class="comment"> * Download a file using wget, curl or file_get_contents. Does not use download</span></div>
<div class="line"><a name="l00789"></a><span class="lineno">  789</span>&#160;<span class="comment"> * cache.</span></div>
<div class="line"><a name="l00790"></a><span class="lineno">  790</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00791"></a><span class="lineno">  791</span>&#160;<span class="comment"> * @param string $url</span></div>
<div class="line"><a name="l00792"></a><span class="lineno">  792</span>&#160;<span class="comment"> *   The url of the file to download.</span></div>
<div class="line"><a name="l00793"></a><span class="lineno">  793</span>&#160;<span class="comment"> * @param string $destination</span></div>
<div class="line"><a name="l00794"></a><span class="lineno">  794</span>&#160;<span class="comment"> *   The name of the file to be saved, which may include the full path.</span></div>
<div class="line"><a name="l00795"></a><span class="lineno">  795</span>&#160;<span class="comment"> * @param boolean $overwrite</span></div>
<div class="line"><a name="l00796"></a><span class="lineno">  796</span>&#160;<span class="comment"> *   Overwrite any file thats already at the destination.</span></div>
<div class="line"><a name="l00797"></a><span class="lineno">  797</span>&#160;<span class="comment"> * @return string</span></div>
<div class="line"><a name="l00798"></a><span class="lineno">  798</span>&#160;<span class="comment"> *   The path to the downloaded file, or FALSE if the file could not be</span></div>
<div class="line"><a name="l00799"></a><span class="lineno">  799</span>&#160;<span class="comment"> *   downloaded.</span></div>
<div class="line"><a name="l00800"></a><span class="lineno">  800</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00801"></a><span class="lineno"><a class="code" href="drush_8inc.html#a5c2a88712f3905874900166f3b2c397c">  801</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a5c2a88712f3905874900166f3b2c397c">_drush_download_file</a>($url, $destination, $overwrite = TRUE) {</div>
<div class="line"><a name="l00802"></a><span class="lineno">  802</span>&#160;  <span class="keyword">static</span> $use_wget;</div>
<div class="line"><a name="l00803"></a><span class="lineno">  803</span>&#160;  <span class="keywordflow">if</span> ($use_wget === NULL) {</div>
<div class="line"><a name="l00804"></a><span class="lineno">  804</span>&#160;    $use_wget = <a class="code" href="group__commandwrappers.html#gafd358ceac1286dbdd141ff2b8eb7d556">drush_shell_exec</a>(<span class="stringliteral">&#39;wget --version&#39;</span>);</div>
<div class="line"><a name="l00805"></a><span class="lineno">  805</span>&#160;  }</div>
<div class="line"><a name="l00806"></a><span class="lineno">  806</span>&#160;</div>
<div class="line"><a name="l00807"></a><span class="lineno">  807</span>&#160;  $destination_tmp = <a class="code" href="group__filesystemfunctions.html#ga01729c5c432a2f30974966d888146d09">drush_tempnam</a>(<span class="stringliteral">&#39;download_file&#39;</span>);</div>
<div class="line"><a name="l00808"></a><span class="lineno">  808</span>&#160;  <span class="keywordflow">if</span> ($use_wget) {</div>
<div class="line"><a name="l00809"></a><span class="lineno">  809</span>&#160;    <a class="code" href="group__commandwrappers.html#gafd358ceac1286dbdd141ff2b8eb7d556">drush_shell_exec</a>(<span class="stringliteral">&quot;wget -q --timeout=30 -O %s %s&quot;</span>, $destination_tmp, $url);</div>
<div class="line"><a name="l00810"></a><span class="lineno">  810</span>&#160;  }</div>
<div class="line"><a name="l00811"></a><span class="lineno">  811</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00812"></a><span class="lineno">  812</span>&#160;    <a class="code" href="group__commandwrappers.html#gafd358ceac1286dbdd141ff2b8eb7d556">drush_shell_exec</a>(<span class="stringliteral">&quot;curl --fail -s -L --connect-timeout 30 -o %s %s&quot;</span>, $destination_tmp, $url);</div>
<div class="line"><a name="l00813"></a><span class="lineno">  813</span>&#160;  }</div>
<div class="line"><a name="l00814"></a><span class="lineno">  814</span>&#160;  <span class="keywordflow">if</span> (!<a class="code" href="group__filesystemfunctions.html#ga0d795889ef507c45abb793b8685b36d0">drush_file_not_empty</a>($destination_tmp) &amp;&amp; $file = @file_get_contents($url)) {</div>
<div class="line"><a name="l00815"></a><span class="lineno">  815</span>&#160;    @file_put_contents($destination_tmp, $file);</div>
<div class="line"><a name="l00816"></a><span class="lineno">  816</span>&#160;  }</div>
<div class="line"><a name="l00817"></a><span class="lineno">  817</span>&#160;  <span class="keywordflow">if</span> (!<a class="code" href="group__filesystemfunctions.html#ga0d795889ef507c45abb793b8685b36d0">drush_file_not_empty</a>($destination_tmp)) {</div>
<div class="line"><a name="l00818"></a><span class="lineno">  818</span>&#160;    <span class="comment">// Download failed.</span></div>
<div class="line"><a name="l00819"></a><span class="lineno">  819</span>&#160;    <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00820"></a><span class="lineno">  820</span>&#160;  }</div>
<div class="line"><a name="l00821"></a><span class="lineno">  821</span>&#160;</div>
<div class="line"><a name="l00822"></a><span class="lineno">  822</span>&#160;  <a class="code" href="group__filesystemfunctions.html#gaac7379e8cfa2163a874542fc021bf521">drush_move_dir</a>($destination_tmp, $destination, $overwrite);</div>
<div class="line"><a name="l00823"></a><span class="lineno">  823</span>&#160;  <span class="keywordflow">return</span> $destination;</div>
<div class="line"><a name="l00824"></a><span class="lineno">  824</span>&#160;}</div>
<div class="line"><a name="l00825"></a><span class="lineno">  825</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00826"></a><span class="lineno">  826</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00827"></a><span class="lineno">  827</span>&#160;<span class="comment"> * Determines the MIME content type of the specified file.</span></div>
<div class="line"><a name="l00828"></a><span class="lineno">  828</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00829"></a><span class="lineno">  829</span>&#160;<span class="comment"> * The power of this function depends on whether the PHP installation</span></div>
<div class="line"><a name="l00830"></a><span class="lineno">  830</span>&#160;<span class="comment"> * has either mime_content_type() or finfo installed -- if not, only tar,</span></div>
<div class="line"><a name="l00831"></a><span class="lineno">  831</span>&#160;<span class="comment"> * gz, zip and bzip2 types can be detected.</span></div>
<div class="line"><a name="l00832"></a><span class="lineno">  832</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00833"></a><span class="lineno">  833</span>&#160;<span class="comment"> * If mime type can&#39;t be obtained, an error will be set.</span></div>
<div class="line"><a name="l00834"></a><span class="lineno">  834</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00835"></a><span class="lineno">  835</span>&#160;<span class="comment"> * @return mixed</span></div>
<div class="line"><a name="l00836"></a><span class="lineno">  836</span>&#160;<span class="comment"> *   The MIME content type of the file or FALSE.</span></div>
<div class="line"><a name="l00837"></a><span class="lineno">  837</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00838"></a><span class="lineno"><a class="code" href="drush_8inc.html#a4ff511402c9ffe30239b8bdbee33a3dc">  838</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a4ff511402c9ffe30239b8bdbee33a3dc">drush_mime_content_type</a>($filename) {</div>
<div class="line"><a name="l00839"></a><span class="lineno">  839</span>&#160;  $content_type = FALSE;</div>
<div class="line"><a name="l00840"></a><span class="lineno">  840</span>&#160;  <span class="keywordflow">if</span> (class_exists(<span class="stringliteral">&#39;finfo&#39;</span>)) {</div>
<div class="line"><a name="l00841"></a><span class="lineno">  841</span>&#160;    $finfo = <span class="keyword">new</span> finfo(FILEINFO_MIME_TYPE);</div>
<div class="line"><a name="l00842"></a><span class="lineno">  842</span>&#160;    $content_type = $finfo-&gt;file($filename);</div>
<div class="line"><a name="l00843"></a><span class="lineno">  843</span>&#160;    <span class="keywordflow">if</span> ($content_type == <span class="stringliteral">&#39;application/octet-stream&#39;</span>) {</div>
<div class="line"><a name="l00844"></a><span class="lineno">  844</span>&#160;      <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Mime type for !file is application/octet-stream.&#39;</span>, array(<span class="stringliteral">&#39;!file&#39;</span> =&gt; $filename)), <span class="stringliteral">&#39;debug&#39;</span>);</div>
<div class="line"><a name="l00845"></a><span class="lineno">  845</span>&#160;      $content_type = FALSE;</div>
<div class="line"><a name="l00846"></a><span class="lineno">  846</span>&#160;    }</div>
<div class="line"><a name="l00847"></a><span class="lineno">  847</span>&#160;  }</div>
<div class="line"><a name="l00848"></a><span class="lineno">  848</span>&#160;  <span class="comment">// If apache is configured in such a way that all files are considered</span></div>
<div class="line"><a name="l00849"></a><span class="lineno">  849</span>&#160;  <span class="comment">// octet-stream (e.g with mod_mime_magic and an http conf that&#39;s serving all</span></div>
<div class="line"><a name="l00850"></a><span class="lineno">  850</span>&#160;  <span class="comment">// archives as octet-stream for other reasons) we&#39;ll detect mime types on our</span></div>
<div class="line"><a name="l00851"></a><span class="lineno">  851</span>&#160;  <span class="comment">//  own by examing the file&#39;s magic header bytes.</span></div>
<div class="line"><a name="l00852"></a><span class="lineno">  852</span>&#160;  <span class="keywordflow">if</span> (!$content_type) {</div>
<div class="line"><a name="l00853"></a><span class="lineno">  853</span>&#160;    <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Examining !file headers.&#39;</span>, array(<span class="stringliteral">&#39;!file&#39;</span> =&gt; $filename)), <span class="stringliteral">&#39;debug&#39;</span>);</div>
<div class="line"><a name="l00854"></a><span class="lineno">  854</span>&#160;    <span class="keywordflow">if</span> ($file = fopen($filename, <span class="stringliteral">&#39;rb&#39;</span>)) {</div>
<div class="line"><a name="l00855"></a><span class="lineno">  855</span>&#160;      $first = fread($file, 2);</div>
<div class="line"><a name="l00856"></a><span class="lineno">  856</span>&#160;      fclose($file);</div>
<div class="line"><a name="l00857"></a><span class="lineno">  857</span>&#160;</div>
<div class="line"><a name="l00858"></a><span class="lineno">  858</span>&#160;      <span class="keywordflow">if</span> ($first !== FALSE) {</div>
<div class="line"><a name="l00859"></a><span class="lineno">  859</span>&#160;        <span class="comment">// Interpret the two bytes as a little endian 16-bit unsigned int.</span></div>
<div class="line"><a name="l00860"></a><span class="lineno">  860</span>&#160;        $data = unpack(<span class="charliteral">&#39;v&#39;</span>, $first);</div>
<div class="line"><a name="l00861"></a><span class="lineno">  861</span>&#160;        <span class="keywordflow">switch</span> ($data[1]) {</div>
<div class="line"><a name="l00862"></a><span class="lineno">  862</span>&#160;          <span class="keywordflow">case</span> 0x8b1f:</div>
<div class="line"><a name="l00863"></a><span class="lineno">  863</span>&#160;            <span class="comment">// First two bytes of gzip files are 0x1f, 0x8b (little-endian).</span></div>
<div class="line"><a name="l00864"></a><span class="lineno">  864</span>&#160;            <span class="comment">// See http://www.gzip.org/zlib/rfc-gzip.html#header-trailer</span></div>
<div class="line"><a name="l00865"></a><span class="lineno">  865</span>&#160;            $content_type = <span class="stringliteral">&#39;application/x-gzip&#39;</span>;</div>
<div class="line"><a name="l00866"></a><span class="lineno">  866</span>&#160;            <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00867"></a><span class="lineno">  867</span>&#160;</div>
<div class="line"><a name="l00868"></a><span class="lineno">  868</span>&#160;          <span class="keywordflow">case</span> 0x4b50:</div>
<div class="line"><a name="l00869"></a><span class="lineno">  869</span>&#160;            <span class="comment">// First two bytes of zip files are 0x50, 0x4b (&#39;PK&#39;) (little-endian).</span></div>
<div class="line"><a name="l00870"></a><span class="lineno">  870</span>&#160;            <span class="comment">// See http://en.wikipedia.org/wiki/Zip_(file_format)#File_headers</span></div>
<div class="line"><a name="l00871"></a><span class="lineno">  871</span>&#160;            $content_type = <span class="stringliteral">&#39;application/zip&#39;</span>;</div>
<div class="line"><a name="l00872"></a><span class="lineno">  872</span>&#160;            <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00873"></a><span class="lineno">  873</span>&#160;</div>
<div class="line"><a name="l00874"></a><span class="lineno">  874</span>&#160;          <span class="keywordflow">case</span> 0x5a42:</div>
<div class="line"><a name="l00875"></a><span class="lineno">  875</span>&#160;            <span class="comment">// First two bytes of bzip2 files are 0x5a, 0x42 (&#39;BZ&#39;) (big-endian).</span></div>
<div class="line"><a name="l00876"></a><span class="lineno">  876</span>&#160;            <span class="comment">// See http://en.wikipedia.org/wiki/Bzip2#File_format</span></div>
<div class="line"><a name="l00877"></a><span class="lineno">  877</span>&#160;            $content_type = <span class="stringliteral">&#39;application/x-bzip2&#39;</span>;</div>
<div class="line"><a name="l00878"></a><span class="lineno">  878</span>&#160;            <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00879"></a><span class="lineno">  879</span>&#160;</div>
<div class="line"><a name="l00880"></a><span class="lineno">  880</span>&#160;          <span class="keywordflow">default</span>:</div>
<div class="line"><a name="l00881"></a><span class="lineno">  881</span>&#160;            <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to determine mime type from header bytes 0x!hex of !file.&#39;</span>, array(<span class="stringliteral">&#39;!hex&#39;</span> =&gt; dechex($data[1]), <span class="stringliteral">&#39;!file&#39;</span> =&gt; $filename,), <span class="stringliteral">&#39;debug&#39;</span>));</div>
<div class="line"><a name="l00882"></a><span class="lineno">  882</span>&#160;        }</div>
<div class="line"><a name="l00883"></a><span class="lineno">  883</span>&#160;      }</div>
<div class="line"><a name="l00884"></a><span class="lineno">  884</span>&#160;      <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00885"></a><span class="lineno">  885</span>&#160;        <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to read !file.&#39;</span>, array(<span class="stringliteral">&#39;!file&#39;</span> =&gt; $filename)), <span class="stringliteral">&#39;warning&#39;</span>);</div>
<div class="line"><a name="l00886"></a><span class="lineno">  886</span>&#160;      }</div>
<div class="line"><a name="l00887"></a><span class="lineno">  887</span>&#160;    }</div>
<div class="line"><a name="l00888"></a><span class="lineno">  888</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l00889"></a><span class="lineno">  889</span>&#160;      <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to open !file.&#39;</span>, array(<span class="stringliteral">&#39;!file&#39;</span> =&gt; $filename)), <span class="stringliteral">&#39;warning&#39;</span>);</div>
<div class="line"><a name="l00890"></a><span class="lineno">  890</span>&#160;    }</div>
<div class="line"><a name="l00891"></a><span class="lineno">  891</span>&#160;  }</div>
<div class="line"><a name="l00892"></a><span class="lineno">  892</span>&#160;</div>
<div class="line"><a name="l00893"></a><span class="lineno">  893</span>&#160;  <span class="comment">// 3. Lastly if above methods didn&#39;t work, try to guess the mime type from</span></div>
<div class="line"><a name="l00894"></a><span class="lineno">  894</span>&#160;  <span class="comment">// the file extension. This is useful if the file has no identificable magic</span></div>
<div class="line"><a name="l00895"></a><span class="lineno">  895</span>&#160;  <span class="comment">// header bytes (for example tarballs).</span></div>
<div class="line"><a name="l00896"></a><span class="lineno">  896</span>&#160;  <span class="keywordflow">if</span> (!$content_type) {</div>
<div class="line"><a name="l00897"></a><span class="lineno">  897</span>&#160;    <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Examining !file extension.&#39;</span>, array(<span class="stringliteral">&#39;!file&#39;</span> =&gt; $filename)), <span class="stringliteral">&#39;debug&#39;</span>);</div>
<div class="line"><a name="l00898"></a><span class="lineno">  898</span>&#160;</div>
<div class="line"><a name="l00899"></a><span class="lineno">  899</span>&#160;    <span class="comment">// Remove querystring from the filename, if present.</span></div>
<div class="line"><a name="l00900"></a><span class="lineno">  900</span>&#160;    $filename = basename(current(explode(<span class="charliteral">&#39;?&#39;</span>, $filename, 2)));</div>
<div class="line"><a name="l00901"></a><span class="lineno">  901</span>&#160;    $extension_mimetype = array(</div>
<div class="line"><a name="l00902"></a><span class="lineno">  902</span>&#160;      <span class="stringliteral">&#39;.tar&#39;</span>     =&gt; <span class="stringliteral">&#39;application/x-tar&#39;</span>,</div>
<div class="line"><a name="l00903"></a><span class="lineno">  903</span>&#160;    );</div>
<div class="line"><a name="l00904"></a><span class="lineno">  904</span>&#160;    <span class="keywordflow">foreach</span> ($extension_mimetype as $extension =&gt; $ct) {</div>
<div class="line"><a name="l00905"></a><span class="lineno">  905</span>&#160;      <span class="keywordflow">if</span> (substr($filename, -strlen($extension)) === $extension) {</div>
<div class="line"><a name="l00906"></a><span class="lineno">  906</span>&#160;        $content_type = $ct;</div>
<div class="line"><a name="l00907"></a><span class="lineno">  907</span>&#160;        <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l00908"></a><span class="lineno">  908</span>&#160;      }</div>
<div class="line"><a name="l00909"></a><span class="lineno">  909</span>&#160;    }</div>
<div class="line"><a name="l00910"></a><span class="lineno">  910</span>&#160;  }</div>
<div class="line"><a name="l00911"></a><span class="lineno">  911</span>&#160;</div>
<div class="line"><a name="l00912"></a><span class="lineno">  912</span>&#160;  <span class="keywordflow">if</span> ($content_type) {</div>
<div class="line"><a name="l00913"></a><span class="lineno">  913</span>&#160;    <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Mime type for !file is !mt&#39;</span>, array(<span class="stringliteral">&#39;!file&#39;</span> =&gt; $filename, <span class="stringliteral">&#39;!mt&#39;</span> =&gt; $content_type)), <span class="stringliteral">&#39;notice&#39;</span>);</div>
<div class="line"><a name="l00914"></a><span class="lineno">  914</span>&#160;    <span class="keywordflow">return</span> $content_type;</div>
<div class="line"><a name="l00915"></a><span class="lineno">  915</span>&#160;  }</div>
<div class="line"><a name="l00916"></a><span class="lineno">  916</span>&#160;</div>
<div class="line"><a name="l00917"></a><span class="lineno">  917</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;MIME_CONTENT_TYPE_UNKNOWN&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to determine mime type for !file.&#39;</span>, array(<span class="stringliteral">&#39;!file&#39;</span> =&gt; $filename)));</div>
<div class="line"><a name="l00918"></a><span class="lineno">  918</span>&#160;}</div>
<div class="line"><a name="l00919"></a><span class="lineno">  919</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00920"></a><span class="lineno">  920</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00921"></a><span class="lineno">  921</span>&#160;<span class="comment"> * Check whether a file is a supported tarball.</span></div>
<div class="line"><a name="l00922"></a><span class="lineno">  922</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00923"></a><span class="lineno">  923</span>&#160;<span class="comment"> * @return mixed</span></div>
<div class="line"><a name="l00924"></a><span class="lineno">  924</span>&#160;<span class="comment"> *   The file content type if it&#39;s a tarball. FALSE otherwise.</span></div>
<div class="line"><a name="l00925"></a><span class="lineno">  925</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00926"></a><span class="lineno"><a class="code" href="drush_8inc.html#a78aae9f3ebfdb2bee27dee73fe088652">  926</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a78aae9f3ebfdb2bee27dee73fe088652">drush_file_is_tarball</a>($path) {</div>
<div class="line"><a name="l00927"></a><span class="lineno">  927</span>&#160;  $content_type = <a class="code" href="drush_8inc.html#a4ff511402c9ffe30239b8bdbee33a3dc">drush_mime_content_type</a>($path);</div>
<div class="line"><a name="l00928"></a><span class="lineno">  928</span>&#160;  $supported = array(</div>
<div class="line"><a name="l00929"></a><span class="lineno">  929</span>&#160;    <span class="stringliteral">&#39;application/x-bzip2&#39;</span>,</div>
<div class="line"><a name="l00930"></a><span class="lineno">  930</span>&#160;    <span class="stringliteral">&#39;application/x-gzip&#39;</span>,</div>
<div class="line"><a name="l00931"></a><span class="lineno">  931</span>&#160;    <span class="stringliteral">&#39;application/x-tar&#39;</span>,</div>
<div class="line"><a name="l00932"></a><span class="lineno">  932</span>&#160;    <span class="stringliteral">&#39;application/x-zip&#39;</span>,</div>
<div class="line"><a name="l00933"></a><span class="lineno">  933</span>&#160;    <span class="stringliteral">&#39;application/zip&#39;</span>,</div>
<div class="line"><a name="l00934"></a><span class="lineno">  934</span>&#160;  );</div>
<div class="line"><a name="l00935"></a><span class="lineno">  935</span>&#160;  <span class="keywordflow">if</span> (in_array($content_type, $supported)) {</div>
<div class="line"><a name="l00936"></a><span class="lineno">  936</span>&#160;    <span class="keywordflow">return</span> $content_type;</div>
<div class="line"><a name="l00937"></a><span class="lineno">  937</span>&#160;  }</div>
<div class="line"><a name="l00938"></a><span class="lineno">  938</span>&#160;  <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00939"></a><span class="lineno">  939</span>&#160;}</div>
<div class="line"><a name="l00940"></a><span class="lineno">  940</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l00941"></a><span class="lineno">  941</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l00942"></a><span class="lineno">  942</span>&#160;<span class="comment"> * Extract a tarball.</span></div>
<div class="line"><a name="l00943"></a><span class="lineno">  943</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00944"></a><span class="lineno">  944</span>&#160;<span class="comment"> * @param string $path</span></div>
<div class="line"><a name="l00945"></a><span class="lineno">  945</span>&#160;<span class="comment"> *   Path to the archive to be extracted.</span></div>
<div class="line"><a name="l00946"></a><span class="lineno">  946</span>&#160;<span class="comment"> * @param string $destination</span></div>
<div class="line"><a name="l00947"></a><span class="lineno">  947</span>&#160;<span class="comment"> *   The destination directory the tarball should be extracted into.</span></div>
<div class="line"><a name="l00948"></a><span class="lineno">  948</span>&#160;<span class="comment"> *   Optional, if ommitted the tarball directory will be used as destination.</span></div>
<div class="line"><a name="l00949"></a><span class="lineno">  949</span>&#160;<span class="comment"> * @param boolean $listing</span></div>
<div class="line"><a name="l00950"></a><span class="lineno">  950</span>&#160;<span class="comment"> *   If TRUE, a listing of the tar contents will be returned on success.</span></div>
<div class="line"><a name="l00951"></a><span class="lineno">  951</span>&#160;<span class="comment"> * @param string $tar_extra_options</span></div>
<div class="line"><a name="l00952"></a><span class="lineno">  952</span>&#160;<span class="comment"> *   Extra options to be passed to the tar command.</span></div>
<div class="line"><a name="l00953"></a><span class="lineno">  953</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l00954"></a><span class="lineno">  954</span>&#160;<span class="comment"> * @return mixed</span></div>
<div class="line"><a name="l00955"></a><span class="lineno">  955</span>&#160;<span class="comment"> *   TRUE on success, FALSE on fail. If $listing is TRUE, a file listing of the</span></div>
<div class="line"><a name="l00956"></a><span class="lineno">  956</span>&#160;<span class="comment"> *   tarball is returned if the extraction reported success, instead of TRUE.</span></div>
<div class="line"><a name="l00957"></a><span class="lineno">  957</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l00958"></a><span class="lineno"><a class="code" href="drush_8inc.html#ad8f8c8d5b65e0d9a863173da63ef78ee">  958</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#ad8f8c8d5b65e0d9a863173da63ef78ee">drush_tarball_extract</a>($path, $destination = FALSE, $listing = FALSE, $tar_extra_options = <span class="stringliteral">&#39;&#39;</span>) {</div>
<div class="line"><a name="l00959"></a><span class="lineno">  959</span>&#160;  <span class="comment">// Check if tarball is supported.</span></div>
<div class="line"><a name="l00960"></a><span class="lineno">  960</span>&#160;  <span class="keywordflow">if</span> (!($mimetype = <a class="code" href="drush_8inc.html#a78aae9f3ebfdb2bee27dee73fe088652">drush_file_is_tarball</a>($path))) {</div>
<div class="line"><a name="l00961"></a><span class="lineno">  961</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;TARBALL_EXTRACT_UNKNOWN_FORMAT&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to extract !path. Unknown archive format.&#39;</span>, array(<span class="stringliteral">&#39;!path&#39;</span> =&gt; $path)));</div>
<div class="line"><a name="l00962"></a><span class="lineno">  962</span>&#160;  }</div>
<div class="line"><a name="l00963"></a><span class="lineno">  963</span>&#160;</div>
<div class="line"><a name="l00964"></a><span class="lineno">  964</span>&#160;  <span class="comment">// Check if destination is valid.</span></div>
<div class="line"><a name="l00965"></a><span class="lineno">  965</span>&#160;  <span class="keywordflow">if</span> (!$destination) {</div>
<div class="line"><a name="l00966"></a><span class="lineno">  966</span>&#160;    $destination = dirname($path);</div>
<div class="line"><a name="l00967"></a><span class="lineno">  967</span>&#160;  }</div>
<div class="line"><a name="l00968"></a><span class="lineno">  968</span>&#160;  <span class="keywordflow">if</span> (!<a class="code" href="group__filesystemfunctions.html#ga6027285d97028ad3299d3aa262be8c2f">drush_mkdir</a>($destination)) {</div>
<div class="line"><a name="l00969"></a><span class="lineno">  969</span>&#160;    <span class="comment">// drush_mkdir already set an error.</span></div>
<div class="line"><a name="l00970"></a><span class="lineno">  970</span>&#160;    <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l00971"></a><span class="lineno">  971</span>&#160;  }</div>
<div class="line"><a name="l00972"></a><span class="lineno">  972</span>&#160;</div>
<div class="line"><a name="l00973"></a><span class="lineno">  973</span>&#160;  <span class="comment">// Perform the extraction of a zip file.</span></div>
<div class="line"><a name="l00974"></a><span class="lineno">  974</span>&#160;  <span class="keywordflow">if</span> (($mimetype == <span class="stringliteral">&#39;application/zip&#39;</span>) || ($mimetype == <span class="stringliteral">&#39;application/x-zip&#39;</span>)) {</div>
<div class="line"><a name="l00975"></a><span class="lineno">  975</span>&#160;    $return = <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>(dirname($path), <span class="stringliteral">&quot;unzip %s -d %s&quot;</span>, $path, $destination);</div>
<div class="line"><a name="l00976"></a><span class="lineno">  976</span>&#160;    <span class="keywordflow">if</span> (!$return) {</div>
<div class="line"><a name="l00977"></a><span class="lineno">  977</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_TARBALL_EXTRACT_ERROR&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to unzip !filename.&#39;</span>, array(<span class="stringliteral">&#39;!filename&#39;</span> =&gt; $path)));</div>
<div class="line"><a name="l00978"></a><span class="lineno">  978</span>&#160;    }</div>
<div class="line"><a name="l00979"></a><span class="lineno">  979</span>&#160;    <span class="keywordflow">if</span> ($listing) {</div>
<div class="line"><a name="l00980"></a><span class="lineno">  980</span>&#160;      <span class="comment">// unzip prefixes the file listing output with a header line,</span></div>
<div class="line"><a name="l00981"></a><span class="lineno">  981</span>&#160;      <span class="comment">// and prefixes each line with a verb representing the compression type.</span></div>
<div class="line"><a name="l00982"></a><span class="lineno">  982</span>&#160;      $output = <a class="code" href="group__commandwrappers.html#gadba8c59ba260dd39f615bc22ca78e1af">drush_shell_exec_output</a>();</div>
<div class="line"><a name="l00983"></a><span class="lineno">  983</span>&#160;      <span class="comment">// Remove the header line.</span></div>
<div class="line"><a name="l00984"></a><span class="lineno">  984</span>&#160;      array_shift($output);</div>
<div class="line"><a name="l00985"></a><span class="lineno">  985</span>&#160;      <span class="comment">// Remove the prefix verb from each line.</span></div>
<div class="line"><a name="l00986"></a><span class="lineno">  986</span>&#160;      $output = array_map(create_function(<span class="stringliteral">&#39;$str&#39;</span>, <span class="stringliteral">&#39;return substr($str, strpos($str, &quot;:&quot;) + 3 + &#39;</span> . strlen($destination) . <span class="stringliteral">&#39;);&#39;</span>), $output);</div>
<div class="line"><a name="l00987"></a><span class="lineno">  987</span>&#160;      <span class="comment">// Remove any remaining blank lines.</span></div>
<div class="line"><a name="l00988"></a><span class="lineno">  988</span>&#160;      $return = array_filter($output, create_function(<span class="stringliteral">&#39;$str&#39;</span>, <span class="stringliteral">&#39;return $str != &quot;&quot;;&#39;</span>));</div>
<div class="line"><a name="l00989"></a><span class="lineno">  989</span>&#160;    }</div>
<div class="line"><a name="l00990"></a><span class="lineno">  990</span>&#160;  }</div>
<div class="line"><a name="l00991"></a><span class="lineno">  991</span>&#160;  <span class="comment">// Otherwise we have a possibly-compressed Tar file.</span></div>
<div class="line"><a name="l00992"></a><span class="lineno">  992</span>&#160;  <span class="comment">// If we are not on Windows, then try to do &quot;tar&quot; in a single operation.</span></div>
<div class="line"><a name="l00993"></a><span class="lineno">  993</span>&#160;  elseif (!<a class="code" href="includes_2environment_8inc.html#a88114295372bcb0ca8dbb5f10b36368e">drush_is_windows</a>()) {</div>
<div class="line"><a name="l00994"></a><span class="lineno">  994</span>&#160;    $tar = <a class="code" href="includes_2environment_8inc.html#a68b121976df4c48d67d77c020e45814f">drush_get_tar_executable</a>();</div>
<div class="line"><a name="l00995"></a><span class="lineno">  995</span>&#160;    $tar_compression_flag = <span class="stringliteral">&#39;&#39;</span>;</div>
<div class="line"><a name="l00996"></a><span class="lineno">  996</span>&#160;    <span class="keywordflow">if</span> ($mimetype == <span class="stringliteral">&#39;application/x-gzip&#39;</span>) {</div>
<div class="line"><a name="l00997"></a><span class="lineno">  997</span>&#160;      $tar_compression_flag = <span class="charliteral">&#39;z&#39;</span>;</div>
<div class="line"><a name="l00998"></a><span class="lineno">  998</span>&#160;    }</div>
<div class="line"><a name="l00999"></a><span class="lineno">  999</span>&#160;    elseif ($mimetype == <span class="stringliteral">&#39;application/x-bzip2&#39;</span>) {</div>
<div class="line"><a name="l01000"></a><span class="lineno"> 1000</span>&#160;      $tar_compression_flag = <span class="charliteral">&#39;j&#39;</span>;</div>
<div class="line"><a name="l01001"></a><span class="lineno"> 1001</span>&#160;    }</div>
<div class="line"><a name="l01002"></a><span class="lineno"> 1002</span>&#160;</div>
<div class="line"><a name="l01003"></a><span class="lineno"> 1003</span>&#160;    $return = <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>(dirname($path), <span class="stringliteral">&quot;$tar {$tar_extra_options} -C %s -x%sf %s&quot;</span>, $destination, $tar_compression_flag, basename($path));</div>
<div class="line"><a name="l01004"></a><span class="lineno"> 1004</span>&#160;    <span class="keywordflow">if</span> (!$return) {</div>
<div class="line"><a name="l01005"></a><span class="lineno"> 1005</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_TARBALL_EXTRACT_ERROR&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to untar !filename.&#39;</span>, array(<span class="stringliteral">&#39;!filename&#39;</span> =&gt; $path)));</div>
<div class="line"><a name="l01006"></a><span class="lineno"> 1006</span>&#160;    }</div>
<div class="line"><a name="l01007"></a><span class="lineno"> 1007</span>&#160;    <span class="keywordflow">if</span> ($listing) {</div>
<div class="line"><a name="l01008"></a><span class="lineno"> 1008</span>&#160;      <span class="comment">// We use a separate tar -tf instead of -xvf above because</span></div>
<div class="line"><a name="l01009"></a><span class="lineno"> 1009</span>&#160;      <span class="comment">// the output is not the same in Mac.</span></div>
<div class="line"><a name="l01010"></a><span class="lineno"> 1010</span>&#160;      <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>(dirname($path), <span class="stringliteral">&quot;$tar -t%sf %s&quot;</span>, $tar_compression_flag, basename($path));</div>
<div class="line"><a name="l01011"></a><span class="lineno"> 1011</span>&#160;      $return = <a class="code" href="group__commandwrappers.html#gadba8c59ba260dd39f615bc22ca78e1af">drush_shell_exec_output</a>();</div>
<div class="line"><a name="l01012"></a><span class="lineno"> 1012</span>&#160;    }</div>
<div class="line"><a name="l01013"></a><span class="lineno"> 1013</span>&#160;  }</div>
<div class="line"><a name="l01014"></a><span class="lineno"> 1014</span>&#160;  <span class="comment">// In windows, do the extraction by its primitive steps.</span></div>
<div class="line"><a name="l01015"></a><span class="lineno"> 1015</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l01016"></a><span class="lineno"> 1016</span>&#160;    <span class="comment">// 1. copy the source tarball to the destination directory. Rename to a</span></div>
<div class="line"><a name="l01017"></a><span class="lineno"> 1017</span>&#160;    <span class="comment">// temp name in case the destination directory == dirname($path)</span></div>
<div class="line"><a name="l01018"></a><span class="lineno"> 1018</span>&#160;    $tmpfile = <a class="code" href="group__filesystemfunctions.html#ga01729c5c432a2f30974966d888146d09">drush_tempnam</a>(basename($path), $destination);</div>
<div class="line"><a name="l01019"></a><span class="lineno"> 1019</span>&#160;    <a class="code" href="group__filesystemfunctions.html#ga1d86ac8e2e56a75acb0abcdc8e0dcf09">drush_copy_dir</a>($path, $tmpfile, FILE_EXISTS_OVERWRITE);</div>
<div class="line"><a name="l01020"></a><span class="lineno"> 1020</span>&#160;</div>
<div class="line"><a name="l01021"></a><span class="lineno"> 1021</span>&#160;    <span class="comment">// 2. uncompress the tarball, if compressed.</span></div>
<div class="line"><a name="l01022"></a><span class="lineno"> 1022</span>&#160;    <span class="keywordflow">if</span> (($mimetype == <span class="stringliteral">&#39;application/x-gzip&#39;</span>) || ($mimetype == <span class="stringliteral">&#39;application/x-bzip2&#39;</span>)) {</div>
<div class="line"><a name="l01023"></a><span class="lineno"> 1023</span>&#160;      <span class="keywordflow">if</span> ($mimetype == <span class="stringliteral">&#39;application/x-gzip&#39;</span>) {</div>
<div class="line"><a name="l01024"></a><span class="lineno"> 1024</span>&#160;        $compressed = $tmpfile . <span class="stringliteral">&#39;.gz&#39;</span>;</div>
<div class="line"><a name="l01025"></a><span class="lineno"> 1025</span>&#160;        <span class="comment">// We used to use gzip --decompress in --stdout &gt; out, but the output</span></div>
<div class="line"><a name="l01026"></a><span class="lineno"> 1026</span>&#160;        <span class="comment">// redirection sometimes failed on Windows for some binary output.</span></div>
<div class="line"><a name="l01027"></a><span class="lineno"> 1027</span>&#160;        $command = <span class="stringliteral">&#39;gzip --decompress %s&#39;</span>;</div>
<div class="line"><a name="l01028"></a><span class="lineno"> 1028</span>&#160;      }</div>
<div class="line"><a name="l01029"></a><span class="lineno"> 1029</span>&#160;      elseif ($mimetype == <span class="stringliteral">&#39;application/x-bzip2&#39;</span>) {</div>
<div class="line"><a name="l01030"></a><span class="lineno"> 1030</span>&#160;        $compressed = $tmpfile . <span class="stringliteral">&#39;.bz2&#39;</span>;</div>
<div class="line"><a name="l01031"></a><span class="lineno"> 1031</span>&#160;        $command = <span class="stringliteral">&#39;bzip2 --decompress %s&#39;</span>;</div>
<div class="line"><a name="l01032"></a><span class="lineno"> 1032</span>&#160;      }</div>
<div class="line"><a name="l01033"></a><span class="lineno"> 1033</span>&#160;      <a class="code" href="drush_8inc.html#a903c36790dbe5525fe9369c8476780af">drush_op</a>(<span class="stringliteral">&#39;rename&#39;</span>, $tmpfile, $compressed);</div>
<div class="line"><a name="l01034"></a><span class="lineno"> 1034</span>&#160;      $return = <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>(dirname($compressed), $command, $compressed);</div>
<div class="line"><a name="l01035"></a><span class="lineno"> 1035</span>&#160;      <span class="keywordflow">if</span> (!$return || !file_exists($tmpfile)) {</div>
<div class="line"><a name="l01036"></a><span class="lineno"> 1036</span>&#160;        <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_TARBALL_EXTRACT_ERROR&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to decompress !filename.&#39;</span>, array(<span class="stringliteral">&#39;!filename&#39;</span> =&gt; $compressed)));</div>
<div class="line"><a name="l01037"></a><span class="lineno"> 1037</span>&#160;      }</div>
<div class="line"><a name="l01038"></a><span class="lineno"> 1038</span>&#160;    }</div>
<div class="line"><a name="l01039"></a><span class="lineno"> 1039</span>&#160;</div>
<div class="line"><a name="l01040"></a><span class="lineno"> 1040</span>&#160;    <span class="comment">// 3. Untar.</span></div>
<div class="line"><a name="l01041"></a><span class="lineno"> 1041</span>&#160;    $tar = <a class="code" href="includes_2environment_8inc.html#a68b121976df4c48d67d77c020e45814f">drush_get_tar_executable</a>();</div>
<div class="line"><a name="l01042"></a><span class="lineno"> 1042</span>&#160;    $return = <a class="code" href="group__commandwrappers.html#ga59e8ee9f53442f2029080ac723ed008f">drush_shell_cd_and_exec</a>(dirname($tmpfile), <span class="stringliteral">&quot;$tar {$tar_extra_options} -xvf %s&quot;</span>, basename($tmpfile));</div>
<div class="line"><a name="l01043"></a><span class="lineno"> 1043</span>&#160;    <span class="keywordflow">if</span> (!$return) {</div>
<div class="line"><a name="l01044"></a><span class="lineno"> 1044</span>&#160;      <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_TARBALL_EXTRACT_ERROR&#39;</span>, <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Unable to untar !filename.&#39;</span>, array(<span class="stringliteral">&#39;!filename&#39;</span> =&gt; $tmpfile)));</div>
<div class="line"><a name="l01045"></a><span class="lineno"> 1045</span>&#160;    }</div>
<div class="line"><a name="l01046"></a><span class="lineno"> 1046</span>&#160;    <span class="keywordflow">if</span> ($listing) {</div>
<div class="line"><a name="l01047"></a><span class="lineno"> 1047</span>&#160;      $return = <a class="code" href="group__commandwrappers.html#gadba8c59ba260dd39f615bc22ca78e1af">drush_shell_exec_output</a>();</div>
<div class="line"><a name="l01048"></a><span class="lineno"> 1048</span>&#160;      <span class="comment">// Cut off the &#39;x &#39; prefix for the each line of the tar output</span></div>
<div class="line"><a name="l01049"></a><span class="lineno"> 1049</span>&#160;      <span class="comment">// See http://drupal.org/node/1775520</span></div>
<div class="line"><a name="l01050"></a><span class="lineno"> 1050</span>&#160;      <span class="keywordflow">foreach</span>($return as &amp;$line) {</div>
<div class="line"><a name="l01051"></a><span class="lineno"> 1051</span>&#160;        <span class="keywordflow">if</span>(strpos($line, <span class="stringliteral">&quot;x &quot;</span>) === 0)</div>
<div class="line"><a name="l01052"></a><span class="lineno"> 1052</span>&#160;          $line = substr($line, 2);</div>
<div class="line"><a name="l01053"></a><span class="lineno"> 1053</span>&#160;      }</div>
<div class="line"><a name="l01054"></a><span class="lineno"> 1054</span>&#160;    }</div>
<div class="line"><a name="l01055"></a><span class="lineno"> 1055</span>&#160;</div>
<div class="line"><a name="l01056"></a><span class="lineno"> 1056</span>&#160;    <span class="comment">// Remove the temporary file so the md5 hash is accurate.</span></div>
<div class="line"><a name="l01057"></a><span class="lineno"> 1057</span>&#160;    unlink($tmpfile);</div>
<div class="line"><a name="l01058"></a><span class="lineno"> 1058</span>&#160;  }</div>
<div class="line"><a name="l01059"></a><span class="lineno"> 1059</span>&#160;</div>
<div class="line"><a name="l01060"></a><span class="lineno"> 1060</span>&#160;  <span class="keywordflow">return</span> $return;</div>
<div class="line"><a name="l01061"></a><span class="lineno"> 1061</span>&#160;}</div>
<div class="line"><a name="l01062"></a><span class="lineno"> 1062</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01063"></a><span class="lineno"> 1063</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01064"></a><span class="lineno"> 1064</span>&#160;<span class="comment"> * @defgroup commandprocessing Command processing functions.</span></div>
<div class="line"><a name="l01065"></a><span class="lineno"> 1065</span>&#160;<span class="comment"> * @{</span></div>
<div class="line"><a name="l01066"></a><span class="lineno"> 1066</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01067"></a><span class="lineno"> 1067</span>&#160;<span class="comment"> * These functions manage command processing by the</span></div>
<div class="line"><a name="l01068"></a><span class="lineno"> 1068</span>&#160;<span class="comment"> * main function in drush.php.</span></div>
<div class="line"><a name="l01069"></a><span class="lineno"> 1069</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01070"></a><span class="lineno"> 1070</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01071"></a><span class="lineno"> 1071</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01072"></a><span class="lineno"> 1072</span>&#160;<span class="comment"> * Handle any command preprocessing that may need to be done, including</span></div>
<div class="line"><a name="l01073"></a><span class="lineno"> 1073</span>&#160;<span class="comment"> * potentially redispatching the command immediately (e.g. for remote</span></div>
<div class="line"><a name="l01074"></a><span class="lineno"> 1074</span>&#160;<span class="comment"> * commands).</span></div>
<div class="line"><a name="l01075"></a><span class="lineno"> 1075</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01076"></a><span class="lineno"> 1076</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l01077"></a><span class="lineno"> 1077</span>&#160;<span class="comment"> *   TRUE if the command was handled remotely.</span></div>
<div class="line"><a name="l01078"></a><span class="lineno"> 1078</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01079"></a><span class="lineno"><a class="code" href="group__commandprocessing.html#gac5fea44d3fe064240192925f864d57a6"> 1079</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__commandprocessing.html#gac5fea44d3fe064240192925f864d57a6">drush_preflight_command_dispatch</a>() {</div>
<div class="line"><a name="l01080"></a><span class="lineno"> 1080</span>&#160;  $interactive = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;interactive&#39;</span>, FALSE);</div>
<div class="line"><a name="l01081"></a><span class="lineno"> 1081</span>&#160;</div>
<div class="line"><a name="l01082"></a><span class="lineno"> 1082</span>&#160;  <span class="comment">// The command will be executed remotely if the --remote-host flag</span></div>
<div class="line"><a name="l01083"></a><span class="lineno"> 1083</span>&#160;  <span class="comment">// is set; note that if a site alias is provided on the command line,</span></div>
<div class="line"><a name="l01084"></a><span class="lineno"> 1084</span>&#160;  <span class="comment">// and the site alias references a remote server, then the --remote-host</span></div>
<div class="line"><a name="l01085"></a><span class="lineno"> 1085</span>&#160;  <span class="comment">// option will be set when the site alias is processed.</span></div>
<div class="line"><a name="l01086"></a><span class="lineno"> 1086</span>&#160;  <span class="comment">// @see drush_sitealias_check_arg</span></div>
<div class="line"><a name="l01087"></a><span class="lineno"> 1087</span>&#160;  $remote_host = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;remote-host&#39;</span>);</div>
<div class="line"><a name="l01088"></a><span class="lineno"> 1088</span>&#160;  <span class="comment">// Get the command early so that we can allow commands to directly handle remote aliases if they wish</span></div>
<div class="line"><a name="l01089"></a><span class="lineno"> 1089</span>&#160;  $command = <a class="code" href="includes_2command_8inc.html#aaf301462cb45c0da60e79ea868323858">drush_parse_command</a>();</div>
<div class="line"><a name="l01090"></a><span class="lineno"> 1090</span>&#160;  <a class="code" href="includes_2command_8inc.html#ad5dd93fad069d6ba73b3546d26855071">drush_command_default_options</a>($command);</div>
<div class="line"><a name="l01091"></a><span class="lineno"> 1091</span>&#160;</div>
<div class="line"><a name="l01092"></a><span class="lineno"> 1092</span>&#160;  <span class="comment">// If the command sets the &#39;strict-option-handling&#39; flag, then we will remove</span></div>
<div class="line"><a name="l01093"></a><span class="lineno"> 1093</span>&#160;  <span class="comment">// any cli options that appear after the command name from the &#39;cli&#39; context.</span></div>
<div class="line"><a name="l01094"></a><span class="lineno"> 1094</span>&#160;  <span class="comment">// The cli options that appear before the command name are stored in the</span></div>
<div class="line"><a name="l01095"></a><span class="lineno"> 1095</span>&#160;  <span class="comment">// &#39;DRUSH_GLOBAL_CLI_OPTIONS&#39; context, so we will just overwrite the cli context</span></div>
<div class="line"><a name="l01096"></a><span class="lineno"> 1096</span>&#160;  <span class="comment">// with this, after doing the neccessary fixup from short-form to long-form options.</span></div>
<div class="line"><a name="l01097"></a><span class="lineno"> 1097</span>&#160;  <span class="comment">// After we do that, we put back any local drush options identified by $command[&#39;options&#39;].</span></div>
<div class="line"><a name="l01098"></a><span class="lineno"> 1098</span>&#160;  <span class="keywordflow">if</span> (is_array($command) &amp;&amp; !empty($command[<span class="stringliteral">&#39;strict-option-handling&#39;</span>])) {</div>
<div class="line"><a name="l01099"></a><span class="lineno"> 1099</span>&#160;    $cli_options = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_GLOBAL_CLI_OPTIONS&#39;</span>, array());</div>
<div class="line"><a name="l01100"></a><span class="lineno"> 1100</span>&#160;    <span class="comment">// Now we are going to sort out any options that exist in $command[&#39;options&#39;];</span></div>
<div class="line"><a name="l01101"></a><span class="lineno"> 1101</span>&#160;    <span class="comment">// we will remove these from DRUSH_COMMAND_ARGS and put them back into the</span></div>
<div class="line"><a name="l01102"></a><span class="lineno"> 1102</span>&#160;    <span class="comment">// cli options.</span></div>
<div class="line"><a name="l01103"></a><span class="lineno"> 1103</span>&#160;    $cli_context = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;cli&#39;</span>);</div>
<div class="line"><a name="l01104"></a><span class="lineno"> 1104</span>&#160;    $remove_from_command_args = array();</div>
<div class="line"><a name="l01105"></a><span class="lineno"> 1105</span>&#160;    <span class="keywordflow">foreach</span> ($command[<span class="stringliteral">&#39;options&#39;</span>] as $option =&gt; $info) {</div>
<div class="line"><a name="l01106"></a><span class="lineno"> 1106</span>&#160;      <span class="keywordflow">if</span> (array_key_exists($option, $cli_context)) {</div>
<div class="line"><a name="l01107"></a><span class="lineno"> 1107</span>&#160;        $cli_options[$option] = $cli_context[$option];</div>
<div class="line"><a name="l01108"></a><span class="lineno"> 1108</span>&#160;        $remove_from_command_args[$option] = $option;</div>
<div class="line"><a name="l01109"></a><span class="lineno"> 1109</span>&#160;      }</div>
<div class="line"><a name="l01110"></a><span class="lineno"> 1110</span>&#160;    }</div>
<div class="line"><a name="l01111"></a><span class="lineno"> 1111</span>&#160;    <span class="keywordflow">if</span> (!empty($remove_from_command_args)) {</div>
<div class="line"><a name="l01112"></a><span class="lineno"> 1112</span>&#160;      $drush_command_args = array();</div>
<div class="line"><a name="l01113"></a><span class="lineno"> 1113</span>&#160;      <span class="keywordflow">foreach</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_COMMAND_ARGS&#39;</span>) as $arg) {</div>
<div class="line"><a name="l01114"></a><span class="lineno"> 1114</span>&#160;        <span class="keywordflow">if</span> (!<a class="code" href="group__commandprocessing.html#ga8698a7441bb154ecc60e73f36254a9d8">_drush_should_remove_command_arg</a>($arg, $remove_from_command_args)) {</div>
<div class="line"><a name="l01115"></a><span class="lineno"> 1115</span>&#160;          $drush_command_args[] = $arg;</div>
<div class="line"><a name="l01116"></a><span class="lineno"> 1116</span>&#160;        }</div>
<div class="line"><a name="l01117"></a><span class="lineno"> 1117</span>&#160;      }</div>
<div class="line"><a name="l01118"></a><span class="lineno"> 1118</span>&#160;      <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>(<span class="stringliteral">&#39;DRUSH_COMMAND_ARGS&#39;</span>, $drush_command_args);</div>
<div class="line"><a name="l01119"></a><span class="lineno"> 1119</span>&#160;    }</div>
<div class="line"><a name="l01120"></a><span class="lineno"> 1120</span>&#160;    <a class="code" href="context_8inc.html#a2082bda0c615dc7163f69851ddd8edaf">drush_expand_short_form_options</a>($cli_options);</div>
<div class="line"><a name="l01121"></a><span class="lineno"> 1121</span>&#160;    <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>(<span class="stringliteral">&#39;cli&#39;</span>, $cli_options);</div>
<div class="line"><a name="l01122"></a><span class="lineno"> 1122</span>&#160;    _drush_preflight_global_options();</div>
<div class="line"><a name="l01123"></a><span class="lineno"> 1123</span>&#160;  }</div>
<div class="line"><a name="l01124"></a><span class="lineno"> 1124</span>&#160;  <span class="comment">// If the command sets the &#39;handle-remote-commands&#39; flag, then we will short-circuit</span></div>
<div class="line"><a name="l01125"></a><span class="lineno"> 1125</span>&#160;  <span class="comment">// remote command dispatching and site-list command dispatching, and always let</span></div>
<div class="line"><a name="l01126"></a><span class="lineno"> 1126</span>&#160;  <span class="comment">// the command handler run on the local machine.</span></div>
<div class="line"><a name="l01127"></a><span class="lineno"> 1127</span>&#160;  <span class="keywordflow">if</span> (is_array($command) &amp;&amp; !empty($command[<span class="stringliteral">&#39;handle-remote-commands&#39;</span>])) {</div>
<div class="line"><a name="l01128"></a><span class="lineno"> 1128</span>&#160;    <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l01129"></a><span class="lineno"> 1129</span>&#160;  }</div>
<div class="line"><a name="l01130"></a><span class="lineno"> 1130</span>&#160;  <span class="keywordflow">if</span> (isset($remote_host)) {</div>
<div class="line"><a name="l01131"></a><span class="lineno"> 1131</span>&#160;    $args = <a class="code" href="context_8inc.html#afaf9361f1297f29d10402b075985985a">drush_get_arguments</a>();</div>
<div class="line"><a name="l01132"></a><span class="lineno"> 1132</span>&#160;    $command_name = array_shift($args);</div>
<div class="line"><a name="l01133"></a><span class="lineno"> 1133</span>&#160;    $remote_user = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;remote-user&#39;</span>);</div>
<div class="line"><a name="l01134"></a><span class="lineno"> 1134</span>&#160;</div>
<div class="line"><a name="l01135"></a><span class="lineno"> 1135</span>&#160;    <span class="comment">// Force interactive mode if there is a single remote target.  #interactive is added by drush_do_command_redispatch</span></div>
<div class="line"><a name="l01136"></a><span class="lineno"> 1136</span>&#160;    $user_interactive = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;interactive&#39;</span>);</div>
<div class="line"><a name="l01137"></a><span class="lineno"> 1137</span>&#160;    <a class="code" href="context_8inc.html#aa4b55e2f6174c8b6efaa8f23a0f9e0af">drush_set_option</a>(<span class="stringliteral">&#39;interactive&#39;</span>, TRUE);</div>
<div class="line"><a name="l01138"></a><span class="lineno"> 1138</span>&#160;    $values = <a class="code" href="group__commandprocessing.html#ga2e0ae6f140c9e0f5c301657cebde33d6">drush_do_command_redispatch</a>(is_array($command) ? $command : $command_name, $args, $remote_host, $remote_user, $user_interactive);</div>
<div class="line"><a name="l01139"></a><span class="lineno"> 1139</span>&#160;    <span class="comment">// In &#39;interactive&#39; mode, $values is the result code from drush_shell_proc_open.</span></div>
<div class="line"><a name="l01140"></a><span class="lineno"> 1140</span>&#160;    <span class="comment">// @todo: in _drush_backend_invoke, return array(&#39;error_status&#39; =&gt; $ret) instead for uniformity.</span></div>
<div class="line"><a name="l01141"></a><span class="lineno"> 1141</span>&#160;    <span class="keywordflow">if</span> (!is_array($values) &amp;&amp; ($values != 0)) {</div>
<div class="line"><a name="l01142"></a><span class="lineno"> 1142</span>&#160;      <span class="comment">// Force an error result code.  Note that drush_shutdown() will still run.</span></div>
<div class="line"><a name="l01143"></a><span class="lineno"> 1143</span>&#160;      <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>(<span class="stringliteral">&#39;DRUSH_EXECUTION_COMPLETED&#39;</span>, TRUE);</div>
<div class="line"><a name="l01144"></a><span class="lineno"> 1144</span>&#160;      exit($values);</div>
<div class="line"><a name="l01145"></a><span class="lineno"> 1145</span>&#160;    }</div>
<div class="line"><a name="l01146"></a><span class="lineno"> 1146</span>&#160;    <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l01147"></a><span class="lineno"> 1147</span>&#160;  }</div>
<div class="line"><a name="l01148"></a><span class="lineno"> 1148</span>&#160;  <span class="comment">// If the --site-list flag is set, then we will execute the specified</span></div>
<div class="line"><a name="l01149"></a><span class="lineno"> 1149</span>&#160;  <span class="comment">// command once for every site listed in the site list.</span></div>
<div class="line"><a name="l01150"></a><span class="lineno"> 1150</span>&#160;  $site_list = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;site-list&#39;</span>);</div>
<div class="line"><a name="l01151"></a><span class="lineno"> 1151</span>&#160;  <span class="keywordflow">if</span> (isset($site_list)) {</div>
<div class="line"><a name="l01152"></a><span class="lineno"> 1152</span>&#160;    <span class="keywordflow">if</span> (!is_array($site_list)) {</div>
<div class="line"><a name="l01153"></a><span class="lineno"> 1153</span>&#160;      $site_list = explode(<span class="charliteral">&#39;,&#39;</span>, $site_list);</div>
<div class="line"><a name="l01154"></a><span class="lineno"> 1154</span>&#160;    }</div>
<div class="line"><a name="l01155"></a><span class="lineno"> 1155</span>&#160;    $site_record = array(<span class="stringliteral">&#39;site-list&#39;</span> =&gt; $site_list);</div>
<div class="line"><a name="l01156"></a><span class="lineno"> 1156</span>&#160;    $args = <a class="code" href="context_8inc.html#afaf9361f1297f29d10402b075985985a">drush_get_arguments</a>();</div>
<div class="line"><a name="l01157"></a><span class="lineno"> 1157</span>&#160;</div>
<div class="line"><a name="l01158"></a><span class="lineno"> 1158</span>&#160;    <span class="keywordflow">if</span> (!<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_SIMULATE&#39;</span>) &amp;&amp; !$interactive  &amp;&amp; !<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_AFFIRMATIVE&#39;</span>) &amp;&amp; !<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_QUIET&#39;</span>)) {</div>
<div class="line"><a name="l01159"></a><span class="lineno"> 1159</span>&#160;      <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&quot;You are about to execute &#39;!command&#39; non-interactively (--yes forced) on all of the following targets:&quot;</span>, array(<span class="stringliteral">&#39;!command&#39;</span> =&gt; implode(<span class="stringliteral">&quot; &quot;</span>, $args))));</div>
<div class="line"><a name="l01160"></a><span class="lineno"> 1160</span>&#160;      <span class="keywordflow">foreach</span> ($site_list as $one_destination) {</div>
<div class="line"><a name="l01161"></a><span class="lineno"> 1161</span>&#160;        <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;  !target&#39;</span>, array(<span class="stringliteral">&#39;!target&#39;</span> =&gt; $one_destination)));</div>
<div class="line"><a name="l01162"></a><span class="lineno"> 1162</span>&#160;      }</div>
<div class="line"><a name="l01163"></a><span class="lineno"> 1163</span>&#160;</div>
<div class="line"><a name="l01164"></a><span class="lineno"> 1164</span>&#160;      <span class="keywordflow">if</span> (<a class="code" href="group__userinput.html#gaa4169b83ff9dc4222af95d376b21268b">drush_confirm</a>(<span class="stringliteral">&#39;Continue? &#39;</span>) === FALSE) {</div>
<div class="line"><a name="l01165"></a><span class="lineno"> 1165</span>&#160;        <a class="code" href="group__errorhandling.html#ga366aaafdf8c774a58653c64a65b6d91c">drush_user_abort</a>();</div>
<div class="line"><a name="l01166"></a><span class="lineno"> 1166</span>&#160;        <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l01167"></a><span class="lineno"> 1167</span>&#160;      }</div>
<div class="line"><a name="l01168"></a><span class="lineno"> 1168</span>&#160;    }</div>
<div class="line"><a name="l01169"></a><span class="lineno"> 1169</span>&#160;    $command_name = array_shift($args);</div>
<div class="line"><a name="l01170"></a><span class="lineno"> 1170</span>&#160;    $multi_options = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;cli&#39;</span>);</div>
<div class="line"><a name="l01171"></a><span class="lineno"> 1171</span>&#160;    $backend_options = array();</div>
<div class="line"><a name="l01172"></a><span class="lineno"> 1172</span>&#160;    <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;pipe&#39;</span>) || <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;interactive&#39;</span>)) {</div>
<div class="line"><a name="l01173"></a><span class="lineno"> 1173</span>&#160;      $backend_options[<span class="stringliteral">&#39;interactive&#39;</span>] = TRUE;</div>
<div class="line"><a name="l01174"></a><span class="lineno"> 1174</span>&#160;    }</div>
<div class="line"><a name="l01175"></a><span class="lineno"> 1175</span>&#160;    <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;no-label&#39;</span>, FALSE)) {</div>
<div class="line"><a name="l01176"></a><span class="lineno"> 1176</span>&#160;      $backend_options[<span class="stringliteral">&#39;no-label&#39;</span>] = TRUE;</div>
<div class="line"><a name="l01177"></a><span class="lineno"> 1177</span>&#160;    }</div>
<div class="line"><a name="l01178"></a><span class="lineno"> 1178</span>&#160;    <span class="comment">// If the user specified a format, try to look up the</span></div>
<div class="line"><a name="l01179"></a><span class="lineno"> 1179</span>&#160;    <span class="comment">// default list separator for the specified format.</span></div>
<div class="line"><a name="l01180"></a><span class="lineno"> 1180</span>&#160;    <span class="comment">// If the user did not specify a different label separator,</span></div>
<div class="line"><a name="l01181"></a><span class="lineno"> 1181</span>&#160;    <span class="comment">// then pass in the default as an option, so that the</span></div>
<div class="line"><a name="l01182"></a><span class="lineno"> 1182</span>&#160;    <span class="comment">// separator between the items in the list and the site</span></div>
<div class="line"><a name="l01183"></a><span class="lineno"> 1183</span>&#160;    <span class="comment">// name will be consistent.</span></div>
<div class="line"><a name="l01184"></a><span class="lineno"> 1184</span>&#160;    $format = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;format&#39;</span>, FALSE);</div>
<div class="line"><a name="l01185"></a><span class="lineno"> 1185</span>&#160;    <span class="keywordflow">if</span> ($format &amp;&amp; !array_key_exists(<span class="stringliteral">&#39;label-separator&#39;</span>, $multi_options)) {</div>
<div class="line"><a name="l01186"></a><span class="lineno"> 1186</span>&#160;      $formatter = <a class="code" href="engines_8inc.html#af360562cce71af9828bbbb7326b1d7a8">drush_load_engine</a>(<span class="stringliteral">&#39;outputformat&#39;</span>, $format);</div>
<div class="line"><a name="l01187"></a><span class="lineno"> 1187</span>&#160;      <span class="keywordflow">if</span> ($formatter) {</div>
<div class="line"><a name="l01188"></a><span class="lineno"> 1188</span>&#160;        $list_separator = $formatter-&gt;get_info(<span class="stringliteral">&#39;list-separator&#39;</span>);</div>
<div class="line"><a name="l01189"></a><span class="lineno"> 1189</span>&#160;        <span class="keywordflow">if</span> ($list_separator) {</div>
<div class="line"><a name="l01190"></a><span class="lineno"> 1190</span>&#160;          $multi_options[<span class="stringliteral">&#39;label-separator&#39;</span>] = $list_separator;</div>
<div class="line"><a name="l01191"></a><span class="lineno"> 1191</span>&#160;        }</div>
<div class="line"><a name="l01192"></a><span class="lineno"> 1192</span>&#160;      }</div>
<div class="line"><a name="l01193"></a><span class="lineno"> 1193</span>&#160;    }</div>
<div class="line"><a name="l01194"></a><span class="lineno"> 1194</span>&#160;    $values = <a class="code" href="group__dispatching.html#ga125471885af052278a0874446b332cf9">drush_invoke_process</a>($site_record, $command_name, $args, $multi_options, $backend_options);</div>
<div class="line"><a name="l01195"></a><span class="lineno"> 1195</span>&#160;    <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l01196"></a><span class="lineno"> 1196</span>&#160;  }</div>
<div class="line"><a name="l01197"></a><span class="lineno"> 1197</span>&#160;  <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l01198"></a><span class="lineno"> 1198</span>&#160;}</div>
<div class="line"><a name="l01199"></a><span class="lineno"> 1199</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01200"></a><span class="lineno"> 1200</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01201"></a><span class="lineno"> 1201</span>&#160;<span class="comment"> * Determine whether or not an argument should be removed from the</span></div>
<div class="line"><a name="l01202"></a><span class="lineno"> 1202</span>&#160;<span class="comment"> * DRUSH_COMMAND_ARGS context.  This method is used when a Drush</span></div>
<div class="line"><a name="l01203"></a><span class="lineno"> 1203</span>&#160;<span class="comment"> * command has set the &#39;strict-option-handling&#39; flag indicating</span></div>
<div class="line"><a name="l01204"></a><span class="lineno"> 1204</span>&#160;<span class="comment"> * that it will pass through all commandline arguments and any</span></div>
<div class="line"><a name="l01205"></a><span class="lineno"> 1205</span>&#160;<span class="comment"> * additional options (not known to Drush) to some shell command.</span></div>
<div class="line"><a name="l01206"></a><span class="lineno"> 1206</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01207"></a><span class="lineno"> 1207</span>&#160;<span class="comment"> * Take as an example the following call to core-rsync:</span></div>
<div class="line"><a name="l01208"></a><span class="lineno"> 1208</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01209"></a><span class="lineno"> 1209</span>&#160;<span class="comment"> *   drush --yes core-rsync -v -az --exclude-paths=&#39;.git:.svn&#39; local-files/ @site:%files</span></div>
<div class="line"><a name="l01210"></a><span class="lineno"> 1210</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01211"></a><span class="lineno"> 1211</span>&#160;<span class="comment"> * In this instance:</span></div>
<div class="line"><a name="l01212"></a><span class="lineno"> 1212</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01213"></a><span class="lineno"> 1213</span>&#160;<span class="comment"> *   --yes is a global Drush option</span></div>
<div class="line"><a name="l01214"></a><span class="lineno"> 1214</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01215"></a><span class="lineno"> 1215</span>&#160;<span class="comment"> *   -v is an rsync option.  It will make rsync run in verbose mode,</span></div>
<div class="line"><a name="l01216"></a><span class="lineno"> 1216</span>&#160;<span class="comment"> *     but will not make Drush run in verbose mode due to the fact that</span></div>
<div class="line"><a name="l01217"></a><span class="lineno"> 1217</span>&#160;<span class="comment"> *     core-rsync sets the &#39;strict-option-handling&#39; flag.</span></div>
<div class="line"><a name="l01218"></a><span class="lineno"> 1218</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01219"></a><span class="lineno"> 1219</span>&#160;<span class="comment"> *   --exclude-paths is a local Drush option.  It will be converted by</span></div>
<div class="line"><a name="l01220"></a><span class="lineno"> 1220</span>&#160;<span class="comment"> *     Drush into --exclude=&#39;.git&#39; and --exclude=&#39;.svn&#39;, and then passed</span></div>
<div class="line"><a name="l01221"></a><span class="lineno"> 1221</span>&#160;<span class="comment"> *     on to the rsync command.</span></div>
<div class="line"><a name="l01222"></a><span class="lineno"> 1222</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01223"></a><span class="lineno"> 1223</span>&#160;<span class="comment"> * The parameter $arg passed to this function is one of the elements</span></div>
<div class="line"><a name="l01224"></a><span class="lineno"> 1224</span>&#160;<span class="comment"> * of DRUSH_COMMAND_ARGS.  It will have values such as:</span></div>
<div class="line"><a name="l01225"></a><span class="lineno"> 1225</span>&#160;<span class="comment"> *   -v</span></div>
<div class="line"><a name="l01226"></a><span class="lineno"> 1226</span>&#160;<span class="comment"> *   -az</span></div>
<div class="line"><a name="l01227"></a><span class="lineno"> 1227</span>&#160;<span class="comment"> *   --exclude-paths=&#39;.git:.svn&#39;</span></div>
<div class="line"><a name="l01228"></a><span class="lineno"> 1228</span>&#160;<span class="comment"> *   local-files/</span></div>
<div class="line"><a name="l01229"></a><span class="lineno"> 1229</span>&#160;<span class="comment"> *   @site:%files</span></div>
<div class="line"><a name="l01230"></a><span class="lineno"> 1230</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01231"></a><span class="lineno"> 1231</span>&#160;<span class="comment"> * Our job in this function is to determine if $arg should be removed</span></div>
<div class="line"><a name="l01232"></a><span class="lineno"> 1232</span>&#160;<span class="comment"> * by virtue of appearing in $removal_list.  $removal_list is an array</span></div>
<div class="line"><a name="l01233"></a><span class="lineno"> 1233</span>&#160;<span class="comment"> * that will contain values such as &#39;exclude-paths&#39;.  Both the key and</span></div>
<div class="line"><a name="l01234"></a><span class="lineno"> 1234</span>&#160;<span class="comment"> * the value of $removal_list is the same.</span></div>
<div class="line"><a name="l01235"></a><span class="lineno"> 1235</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01236"></a><span class="lineno"><a class="code" href="group__commandprocessing.html#ga8698a7441bb154ecc60e73f36254a9d8"> 1236</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__commandprocessing.html#ga8698a7441bb154ecc60e73f36254a9d8">_drush_should_remove_command_arg</a>($arg, $removal_list) {</div>
<div class="line"><a name="l01237"></a><span class="lineno"> 1237</span>&#160;  <span class="keywordflow">foreach</span> ($removal_list as $candidate) {</div>
<div class="line"><a name="l01238"></a><span class="lineno"> 1238</span>&#160;    <span class="keywordflow">if</span> (($arg == <span class="stringliteral">&quot;-$candidate&quot;</span>) ||</div>
<div class="line"><a name="l01239"></a><span class="lineno"> 1239</span>&#160;        ($arg == <span class="stringliteral">&quot;--$candidate&quot;</span>) ||</div>
<div class="line"><a name="l01240"></a><span class="lineno"> 1240</span>&#160;        (substr($arg,0,strlen($candidate)+3) == <span class="stringliteral">&quot;--$candidate=&quot;</span>) ) {</div>
<div class="line"><a name="l01241"></a><span class="lineno"> 1241</span>&#160;      <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l01242"></a><span class="lineno"> 1242</span>&#160;    }</div>
<div class="line"><a name="l01243"></a><span class="lineno"> 1243</span>&#160;  }</div>
<div class="line"><a name="l01244"></a><span class="lineno"> 1244</span>&#160;  <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l01245"></a><span class="lineno"> 1245</span>&#160;}</div>
<div class="line"><a name="l01246"></a><span class="lineno"> 1246</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01247"></a><span class="lineno"> 1247</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01248"></a><span class="lineno"> 1248</span>&#160;<span class="comment"> * Used by functions that operate on lists of sites, moving</span></div>
<div class="line"><a name="l01249"></a><span class="lineno"> 1249</span>&#160;<span class="comment"> * information from the source to the destination.  Currenlty</span></div>
<div class="line"><a name="l01250"></a><span class="lineno"> 1250</span>&#160;<span class="comment"> * this includes &#39;drush rsync&#39; and &#39;drush sql sync&#39;.</span></div>
<div class="line"><a name="l01251"></a><span class="lineno"> 1251</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01252"></a><span class="lineno"><a class="code" href="group__commandprocessing.html#gaadd12f0ca081399dea1c99984c77e567"> 1252</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__commandprocessing.html#gaadd12f0ca081399dea1c99984c77e567">drush_do_multiple_command</a>($command, $source_record, $destination_record, $allow_single_source = FALSE) {</div>
<div class="line"><a name="l01253"></a><span class="lineno"> 1253</span>&#160;  $is_multiple_command = FALSE;</div>
<div class="line"><a name="l01254"></a><span class="lineno"> 1254</span>&#160;</div>
<div class="line"><a name="l01255"></a><span class="lineno"> 1255</span>&#160;  <span class="keywordflow">if</span> ((($allow_single_source == TRUE) || array_key_exists(<span class="stringliteral">&#39;site-list&#39;</span>, $source_record)) &amp;&amp; array_key_exists(<span class="stringliteral">&#39;site-list&#39;</span>, $destination_record)) {</div>
<div class="line"><a name="l01256"></a><span class="lineno"> 1256</span>&#160;    $is_multiple_command = TRUE;</div>
<div class="line"><a name="l01257"></a><span class="lineno"> 1257</span>&#160;    $source_path = array_key_exists(<span class="stringliteral">&#39;path-component&#39;</span>, $source_record) ? $source_record[<span class="stringliteral">&#39;path-component&#39;</span>] : <span class="stringliteral">&#39;&#39;</span>;</div>
<div class="line"><a name="l01258"></a><span class="lineno"> 1258</span>&#160;    $destination_path = array_key_exists(<span class="stringliteral">&#39;path-component&#39;</span>, $destination_record) ? $destination_record[<span class="stringliteral">&#39;path-component&#39;</span>] : <span class="stringliteral">&#39;&#39;</span>;</div>
<div class="line"><a name="l01259"></a><span class="lineno"> 1259</span>&#160;</div>
<div class="line"><a name="l01260"></a><span class="lineno"> 1260</span>&#160;    $target_list = array_values(<a class="code" href="sitealias_8inc.html#a79d866a010f76b7d6ec47ab2a72a0c43">drush_sitealias_resolve_sitelist</a>($destination_record));</div>
<div class="line"><a name="l01261"></a><span class="lineno"> 1261</span>&#160;    <span class="keywordflow">if</span> (array_key_exists(<span class="stringliteral">&#39;site-list&#39;</span>, $source_record)) {</div>
<div class="line"><a name="l01262"></a><span class="lineno"> 1262</span>&#160;      $source_list = array_values(<a class="code" href="sitealias_8inc.html#a79d866a010f76b7d6ec47ab2a72a0c43">drush_sitealias_resolve_sitelist</a>($source_record));</div>
<div class="line"><a name="l01263"></a><span class="lineno"> 1263</span>&#160;</div>
<div class="line"><a name="l01264"></a><span class="lineno"> 1264</span>&#160;      <span class="keywordflow">if</span> (<a class="code" href="sitealias_8inc.html#acab0404ba65f276dc64beed139cde5d0">drush_sitealias_check_lists_alignment</a>($source_list, $target_list) === FALSE) {</div>
<div class="line"><a name="l01265"></a><span class="lineno"> 1265</span>&#160;        <span class="keywordflow">if</span> (array_key_exists(<span class="stringliteral">&#39;unordered-list&#39;</span>, $source_record) || array_key_exists(<span class="stringliteral">&#39;unordered-list&#39;</span>, $destination_record)) {</div>
<div class="line"><a name="l01266"></a><span class="lineno"> 1266</span>&#160;          <a class="code" href="sitealias_8inc.html#ab631bdb54ebd2fe0d113011769d1c7e4">drush_sitelist_align_lists</a>($source_list, $target_list, $aligned_source, $aligned_target);</div>
<div class="line"><a name="l01267"></a><span class="lineno"> 1267</span>&#160;          $source_list = $aligned_source;</div>
<div class="line"><a name="l01268"></a><span class="lineno"> 1268</span>&#160;          $target_list = $aligned_target;</div>
<div class="line"><a name="l01269"></a><span class="lineno"> 1269</span>&#160;        }</div>
<div class="line"><a name="l01270"></a><span class="lineno"> 1270</span>&#160;      }</div>
<div class="line"><a name="l01271"></a><span class="lineno"> 1271</span>&#160;    }</div>
<div class="line"><a name="l01272"></a><span class="lineno"> 1272</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l01273"></a><span class="lineno"> 1273</span>&#160;      $source_list = array_fill(0, count($target_list), $source_record);</div>
<div class="line"><a name="l01274"></a><span class="lineno"> 1274</span>&#160;    }</div>
<div class="line"><a name="l01275"></a><span class="lineno"> 1275</span>&#160;</div>
<div class="line"><a name="l01276"></a><span class="lineno"> 1276</span>&#160;    <span class="keywordflow">if</span> (!<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_SIMULATE&#39;</span>)) {</div>
<div class="line"><a name="l01277"></a><span class="lineno"> 1277</span>&#160;      <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;You are about to !command between all of the following targets:&#39;</span>, array(<span class="stringliteral">&#39;!command&#39;</span> =&gt; $command)));</div>
<div class="line"><a name="l01278"></a><span class="lineno"> 1278</span>&#160;      $i = 0;</div>
<div class="line"><a name="l01279"></a><span class="lineno"> 1279</span>&#160;      <span class="keywordflow">foreach</span> ($source_list as $one_source) {</div>
<div class="line"><a name="l01280"></a><span class="lineno"> 1280</span>&#160;        $one_target = $target_list[$i];</div>
<div class="line"><a name="l01281"></a><span class="lineno"> 1281</span>&#160;        ++$i;</div>
<div class="line"><a name="l01282"></a><span class="lineno"> 1282</span>&#160;        <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;  !source will overwrite !target&#39;</span>, array(<span class="stringliteral">&#39;!source&#39;</span> =&gt; <a class="code" href="sitealias_8inc.html#a926d838da4c2c24300e7e7461d8079b0">drush_sitealias_alias_record_to_spec</a>($one_source) . $source_path, <span class="stringliteral">&#39;!target&#39;</span> =&gt; <a class="code" href="sitealias_8inc.html#a926d838da4c2c24300e7e7461d8079b0">drush_sitealias_alias_record_to_spec</a>($one_target) . $destination_path)));</div>
<div class="line"><a name="l01283"></a><span class="lineno"> 1283</span>&#160;      }</div>
<div class="line"><a name="l01284"></a><span class="lineno"> 1284</span>&#160;</div>
<div class="line"><a name="l01285"></a><span class="lineno"> 1285</span>&#160;      <span class="keywordflow">if</span> (<a class="code" href="group__userinput.html#gaa4169b83ff9dc4222af95d376b21268b">drush_confirm</a>(<span class="stringliteral">&#39;Continue? &#39;</span>) === FALSE) {</div>
<div class="line"><a name="l01286"></a><span class="lineno"> 1286</span>&#160;         <span class="keywordflow">return</span> <a class="code" href="group__errorhandling.html#ga366aaafdf8c774a58653c64a65b6d91c">drush_user_abort</a>();</div>
<div class="line"><a name="l01287"></a><span class="lineno"> 1287</span>&#160;      }</div>
<div class="line"><a name="l01288"></a><span class="lineno"> 1288</span>&#160;    }</div>
<div class="line"><a name="l01289"></a><span class="lineno"> 1289</span>&#160;</div>
<div class="line"><a name="l01290"></a><span class="lineno"> 1290</span>&#160;    $data = <a class="code" href="group__dispatching.html#ga9b1a98376983ee529fc868ef4280b12d">drush_redispatch_get_options</a>();</div>
<div class="line"><a name="l01291"></a><span class="lineno"> 1291</span>&#160;    $i = 0;</div>
<div class="line"><a name="l01292"></a><span class="lineno"> 1292</span>&#160;    <span class="keywordflow">foreach</span> ($source_list as $one_source) {</div>
<div class="line"><a name="l01293"></a><span class="lineno"> 1293</span>&#160;      $one_target = $target_list[$i];</div>
<div class="line"><a name="l01294"></a><span class="lineno"> 1294</span>&#160;      ++$i;</div>
<div class="line"><a name="l01295"></a><span class="lineno"> 1295</span>&#160;</div>
<div class="line"><a name="l01296"></a><span class="lineno"> 1296</span>&#160;      $source_spec = <a class="code" href="sitealias_8inc.html#a926d838da4c2c24300e7e7461d8079b0">drush_sitealias_alias_record_to_spec</a>($one_source);</div>
<div class="line"><a name="l01297"></a><span class="lineno"> 1297</span>&#160;      $target_spec = <a class="code" href="sitealias_8inc.html#a926d838da4c2c24300e7e7461d8079b0">drush_sitealias_alias_record_to_spec</a>($one_target);</div>
<div class="line"><a name="l01298"></a><span class="lineno"> 1298</span>&#160;</div>
<div class="line"><a name="l01299"></a><span class="lineno"> 1299</span>&#160;      <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Begin do_multiple !command via backend invoke&#39;</span>, array(<span class="stringliteral">&#39;!command&#39;</span> =&gt; $command)));</div>
<div class="line"><a name="l01300"></a><span class="lineno"> 1300</span>&#160;      $values = <a class="code" href="group__dispatching.html#ga125471885af052278a0874446b332cf9">drush_invoke_process</a>(<span class="stringliteral">&#39;@self&#39;</span>, $command, array($source_spec . $source_path, $target_spec . $destination_path), $data);</div>
<div class="line"><a name="l01301"></a><span class="lineno"> 1301</span>&#160;      <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Backend invoke is complete&#39;</span>));</div>
<div class="line"><a name="l01302"></a><span class="lineno"> 1302</span>&#160;    }</div>
<div class="line"><a name="l01303"></a><span class="lineno"> 1303</span>&#160;  }</div>
<div class="line"><a name="l01304"></a><span class="lineno"> 1304</span>&#160;</div>
<div class="line"><a name="l01305"></a><span class="lineno"> 1305</span>&#160;  <span class="keywordflow">return</span> $is_multiple_command;</div>
<div class="line"><a name="l01306"></a><span class="lineno"> 1306</span>&#160;}</div>
<div class="line"><a name="l01307"></a><span class="lineno"> 1307</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01308"></a><span class="lineno"> 1308</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01309"></a><span class="lineno"> 1309</span>&#160;<span class="comment"> * Run a command on the site specified by the provided command record.</span></div>
<div class="line"><a name="l01310"></a><span class="lineno"> 1310</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01311"></a><span class="lineno"> 1311</span>&#160;<span class="comment"> * The standard function that provides this service is called</span></div>
<div class="line"><a name="l01312"></a><span class="lineno"> 1312</span>&#160;<span class="comment"> * drush_invoke_process.  Please call the standard function.</span></div>
<div class="line"><a name="l01313"></a><span class="lineno"> 1313</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01314"></a><span class="lineno"> 1314</span>&#160;<span class="comment"> * @param backend_options</span></div>
<div class="line"><a name="l01315"></a><span class="lineno"> 1315</span>&#160;<span class="comment"> *   TRUE - integrate errors</span></div>
<div class="line"><a name="l01316"></a><span class="lineno"> 1316</span>&#160;<span class="comment"> *   FALSE - do not integrate errors</span></div>
<div class="line"><a name="l01317"></a><span class="lineno"> 1317</span>&#160;<span class="comment"> *   array - @see drush_backend_invoke_concurrent</span></div>
<div class="line"><a name="l01318"></a><span class="lineno"> 1318</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01319"></a><span class="lineno"> 1319</span>&#160;<span class="comment">function drush_do_site_command($site_record, $command, $args = array(), $command_options = array(), $backend_options = FALSE) {</span></div>
<div class="line"><a name="l01320"></a><span class="lineno"> 1320</span>&#160;<span class="comment">  return drush_invoke_process($site_record, $command, $args, $command_options, $backend_options);</span></div>
<div class="line"><a name="l01321"></a><span class="lineno"> 1321</span>&#160;<span class="comment">}</span></div>
<div class="line"><a name="l01322"></a><span class="lineno"> 1322</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01323"></a><span class="lineno"> 1323</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01324"></a><span class="lineno"> 1324</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01325"></a><span class="lineno"> 1325</span>&#160;<span class="comment"> * Redispatch the specified command using the same</span></div>
<div class="line"><a name="l01326"></a><span class="lineno"> 1326</span>&#160;<span class="comment"> * options that were passed to this invocation of drush.</span></div>
<div class="line"><a name="l01327"></a><span class="lineno"> 1327</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01328"></a><span class="lineno"><a class="code" href="group__commandprocessing.html#ga2e0ae6f140c9e0f5c301657cebde33d6"> 1328</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__commandprocessing.html#ga2e0ae6f140c9e0f5c301657cebde33d6">drush_do_command_redispatch</a>($command, $args = array(), $remote_host = NULL, $remote_user = NULL, $drush_path = NULL, $user_interactive = FALSE) {</div>
<div class="line"><a name="l01329"></a><span class="lineno"> 1329</span>&#160;  $additional_global_options = array();</div>
<div class="line"><a name="l01330"></a><span class="lineno"> 1330</span>&#160;  $command_options = <a class="code" href="group__dispatching.html#ga9b1a98376983ee529fc868ef4280b12d">drush_redispatch_get_options</a>();</div>
<div class="line"><a name="l01331"></a><span class="lineno"> 1331</span>&#160;  <span class="keywordflow">if</span> (is_array($command)) {</div>
<div class="line"><a name="l01332"></a><span class="lineno"> 1332</span>&#160;    $command_name = $command[<span class="stringliteral">&#39;command&#39;</span>];</div>
<div class="line"><a name="l01333"></a><span class="lineno"> 1333</span>&#160;    <span class="comment">// If we are executing a remote command that uses strict option handling,</span></div>
<div class="line"><a name="l01334"></a><span class="lineno"> 1334</span>&#160;    <span class="comment">// then mark all of the options in the alias context as global, so that they</span></div>
<div class="line"><a name="l01335"></a><span class="lineno"> 1335</span>&#160;    <span class="comment">// will appear before the command name.</span></div>
<div class="line"><a name="l01336"></a><span class="lineno"> 1336</span>&#160;    <span class="keywordflow">if</span> (!empty($command[<span class="stringliteral">&#39;strict-option-handling&#39;</span>])) {</div>
<div class="line"><a name="l01337"></a><span class="lineno"> 1337</span>&#160;      <span class="keywordflow">foreach</span>(<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;alias&#39;</span>) as $alias_key =&gt; $alias_value) {</div>
<div class="line"><a name="l01338"></a><span class="lineno"> 1338</span>&#160;        <span class="keywordflow">if</span> (array_key_exists($alias_key, $command_options) &amp;&amp; !array_key_exists($alias_key, $command[<span class="stringliteral">&#39;options&#39;</span>])) {</div>
<div class="line"><a name="l01339"></a><span class="lineno"> 1339</span>&#160;          $additional_global_options[$alias_key] = $alias_value;</div>
<div class="line"><a name="l01340"></a><span class="lineno"> 1340</span>&#160;        }</div>
<div class="line"><a name="l01341"></a><span class="lineno"> 1341</span>&#160;      }</div>
<div class="line"><a name="l01342"></a><span class="lineno"> 1342</span>&#160;    }</div>
<div class="line"><a name="l01343"></a><span class="lineno"> 1343</span>&#160;  }</div>
<div class="line"><a name="l01344"></a><span class="lineno"> 1344</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l01345"></a><span class="lineno"> 1345</span>&#160;    $command_name = $command;</div>
<div class="line"><a name="l01346"></a><span class="lineno"> 1346</span>&#160;  }</div>
<div class="line"><a name="l01347"></a><span class="lineno"> 1347</span>&#160;  <span class="comment">// If the path to drush was supplied, then use it to invoke the new command.</span></div>
<div class="line"><a name="l01348"></a><span class="lineno"> 1348</span>&#160;  <span class="keywordflow">if</span> ($drush_path == NULL) {</div>
<div class="line"><a name="l01349"></a><span class="lineno"> 1349</span>&#160;    $drush_path = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;drush-script&#39;</span>);</div>
<div class="line"><a name="l01350"></a><span class="lineno"> 1350</span>&#160;    <span class="keywordflow">if</span> (!isset($drush_path)) {</div>
<div class="line"><a name="l01351"></a><span class="lineno"> 1351</span>&#160;      $drush_folder = <a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;drush&#39;</span>);</div>
<div class="line"><a name="l01352"></a><span class="lineno"> 1352</span>&#160;      <span class="keywordflow">if</span> (isset($drush)) {</div>
<div class="line"><a name="l01353"></a><span class="lineno"> 1353</span>&#160;        $drush_path = $drush_folder . <span class="stringliteral">&#39;/drush&#39;</span>;</div>
<div class="line"><a name="l01354"></a><span class="lineno"> 1354</span>&#160;      }</div>
<div class="line"><a name="l01355"></a><span class="lineno"> 1355</span>&#160;    }</div>
<div class="line"><a name="l01356"></a><span class="lineno"> 1356</span>&#160;  }</div>
<div class="line"><a name="l01357"></a><span class="lineno"> 1357</span>&#160;  $backend_options = array(<span class="stringliteral">&#39;drush-script&#39;</span> =&gt; $drush_path, <span class="stringliteral">&#39;remote-host&#39;</span> =&gt; $remote_host, <span class="stringliteral">&#39;remote-user&#39;</span> =&gt; $remote_user, <span class="stringliteral">&#39;integrate&#39;</span> =&gt; TRUE, <span class="stringliteral">&#39;additional-global-options&#39;</span> =&gt; $additional_global_options);</div>
<div class="line"><a name="l01358"></a><span class="lineno"> 1358</span>&#160;  <span class="comment">// Set the tty if requested, if the command necessitates it,</span></div>
<div class="line"><a name="l01359"></a><span class="lineno"> 1359</span>&#160;  <span class="comment">// or if the user explicitly asks for interactive mode, but</span></div>
<div class="line"><a name="l01360"></a><span class="lineno"> 1360</span>&#160;  <span class="comment">// not if interactive mode is forced.  tty implies interactive</span></div>
<div class="line"><a name="l01361"></a><span class="lineno"> 1361</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;tty&#39;</span>) || $user_interactive || !empty($command[<span class="stringliteral">&#39;remote-tty&#39;</span>])) {</div>
<div class="line"><a name="l01362"></a><span class="lineno"> 1362</span>&#160;    $backend_options[<span class="stringliteral">&#39;#tty&#39;</span>] = TRUE;</div>
<div class="line"><a name="l01363"></a><span class="lineno"> 1363</span>&#160;    $backend_options[<span class="stringliteral">&#39;interactive&#39;</span>] = TRUE;</div>
<div class="line"><a name="l01364"></a><span class="lineno"> 1364</span>&#160;  }</div>
<div class="line"><a name="l01365"></a><span class="lineno"> 1365</span>&#160;  elseif (<a class="code" href="context_8inc.html#afe91fb3e5219ecb2208c3b036b1f0cb8">drush_get_option</a>(<span class="stringliteral">&#39;interactive&#39;</span>)) {</div>
<div class="line"><a name="l01366"></a><span class="lineno"> 1366</span>&#160;    $backend_options[<span class="stringliteral">&#39;interactive&#39;</span>] = TRUE;</div>
<div class="line"><a name="l01367"></a><span class="lineno"> 1367</span>&#160;  }</div>
<div class="line"><a name="l01368"></a><span class="lineno"> 1368</span>&#160;</div>
<div class="line"><a name="l01369"></a><span class="lineno"> 1369</span>&#160;  <span class="comment">// Run the command in a new process.</span></div>
<div class="line"><a name="l01370"></a><span class="lineno"> 1370</span>&#160;  <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Begin redispatch via drush_invoke_process().&#39;</span>));</div>
<div class="line"><a name="l01371"></a><span class="lineno"> 1371</span>&#160;  $values = <a class="code" href="group__dispatching.html#ga125471885af052278a0874446b332cf9">drush_invoke_process</a>(<span class="stringliteral">&#39;@self&#39;</span>, $command_name, $args, $command_options, $backend_options);</div>
<div class="line"><a name="l01372"></a><span class="lineno"> 1372</span>&#160;  <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(<a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;End redispatch via drush_invoke_process().&#39;</span>));</div>
<div class="line"><a name="l01373"></a><span class="lineno"> 1373</span>&#160;</div>
<div class="line"><a name="l01374"></a><span class="lineno"> 1374</span>&#160;  <span class="keywordflow">return</span> $values;</div>
<div class="line"><a name="l01375"></a><span class="lineno"> 1375</span>&#160;}</div>
<div class="line"><a name="l01376"></a><span class="lineno"> 1376</span>&#160;</div>
<div class="line"><a name="l01377"></a><span class="lineno"> 1377</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01378"></a><span class="lineno"> 1378</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01379"></a><span class="lineno"> 1379</span>&#160;<span class="comment"> * @} End of &quot;defgroup commandprocessing&quot;.</span></div>
<div class="line"><a name="l01380"></a><span class="lineno"> 1380</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01381"></a><span class="lineno"> 1381</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01382"></a><span class="lineno"> 1382</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01383"></a><span class="lineno"> 1383</span>&#160;<span class="comment"> * @defgroup logging Logging information to be provided as output.</span></div>
<div class="line"><a name="l01384"></a><span class="lineno"> 1384</span>&#160;<span class="comment"> * @{</span></div>
<div class="line"><a name="l01385"></a><span class="lineno"> 1385</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01386"></a><span class="lineno"> 1386</span>&#160;<span class="comment"> * These functions are primarily for diagnostic purposes, but also provide an overview of tasks that were taken</span></div>
<div class="line"><a name="l01387"></a><span class="lineno"> 1387</span>&#160;<span class="comment"> * by drush.</span></div>
<div class="line"><a name="l01388"></a><span class="lineno"> 1388</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01389"></a><span class="lineno"> 1389</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01390"></a><span class="lineno"> 1390</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01391"></a><span class="lineno"> 1391</span>&#160;<span class="comment"> * Add a log message to the log history.</span></div>
<div class="line"><a name="l01392"></a><span class="lineno"> 1392</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01393"></a><span class="lineno"> 1393</span>&#160;<span class="comment"> * This function calls the callback stored in the &#39;DRUSH_LOG_CALLBACK&#39; context with</span></div>
<div class="line"><a name="l01394"></a><span class="lineno"> 1394</span>&#160;<span class="comment"> * the resulting entry at the end of execution.</span></div>
<div class="line"><a name="l01395"></a><span class="lineno"> 1395</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01396"></a><span class="lineno"> 1396</span>&#160;<span class="comment"> * This allows you to replace it with custom logging implementations if needed,</span></div>
<div class="line"><a name="l01397"></a><span class="lineno"> 1397</span>&#160;<span class="comment"> * such as logging to a file or logging to a database (drupal or otherwise).</span></div>
<div class="line"><a name="l01398"></a><span class="lineno"> 1398</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01399"></a><span class="lineno"> 1399</span>&#160;<span class="comment"> * The default callback is the _drush_print_log() function with prints the messages</span></div>
<div class="line"><a name="l01400"></a><span class="lineno"> 1400</span>&#160;<span class="comment"> * to the shell.</span></div>
<div class="line"><a name="l01401"></a><span class="lineno"> 1401</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01402"></a><span class="lineno"> 1402</span>&#160;<span class="comment"> * @param message</span></div>
<div class="line"><a name="l01403"></a><span class="lineno"> 1403</span>&#160;<span class="comment"> *   String containing the message to be logged.</span></div>
<div class="line"><a name="l01404"></a><span class="lineno"> 1404</span>&#160;<span class="comment"> * @param type</span></div>
<div class="line"><a name="l01405"></a><span class="lineno"> 1405</span>&#160;<span class="comment"> *   The type of message to be logged. Common types are &#39;warning&#39;, &#39;error&#39;, &#39;success&#39; and &#39;notice&#39;.</span></div>
<div class="line"><a name="l01406"></a><span class="lineno"> 1406</span>&#160;<span class="comment"> *   A type of &#39;failed&#39; can also be supplied to flag as an &#39;error&#39;.</span></div>
<div class="line"><a name="l01407"></a><span class="lineno"> 1407</span>&#160;<span class="comment"> *   A type of &#39;ok&#39; or &#39;completed&#39; can also be supplied to flag as a &#39;success&#39;.</span></div>
<div class="line"><a name="l01408"></a><span class="lineno"> 1408</span>&#160;<span class="comment"> *   If you want your log messages to print to screen without the user entering</span></div>
<div class="line"><a name="l01409"></a><span class="lineno"> 1409</span>&#160;<span class="comment"> *   a -v or --verbose flag, use type &#39;ok&#39;, this prints log messages out to</span></div>
<div class="line"><a name="l01410"></a><span class="lineno"> 1410</span>&#160;<span class="comment"> *   STDERR, which prints to screen (unless you have redirected it). All other</span></div>
<div class="line"><a name="l01411"></a><span class="lineno"> 1411</span>&#160;<span class="comment"> *   types of messages will be assumed to be notices.</span></div>
<div class="line"><a name="l01412"></a><span class="lineno"> 1412</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01413"></a><span class="lineno"><a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6"> 1413</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>($message, $type = <span class="stringliteral">&#39;notice&#39;</span>, $error = null) {</div>
<div class="line"><a name="l01414"></a><span class="lineno"> 1414</span>&#160;  $log =&amp; <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_LOG&#39;</span>, array());</div>
<div class="line"><a name="l01415"></a><span class="lineno"> 1415</span>&#160;  $callback = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_LOG_CALLBACK&#39;</span>, <span class="stringliteral">&#39;_drush_print_log&#39;</span>);</div>
<div class="line"><a name="l01416"></a><span class="lineno"> 1416</span>&#160;  $entry = array(</div>
<div class="line"><a name="l01417"></a><span class="lineno"> 1417</span>&#160;     <span class="stringliteral">&#39;type&#39;</span> =&gt; $type,</div>
<div class="line"><a name="l01418"></a><span class="lineno"> 1418</span>&#160;     <span class="stringliteral">&#39;message&#39;</span> =&gt; $message,</div>
<div class="line"><a name="l01419"></a><span class="lineno"> 1419</span>&#160;     <span class="stringliteral">&#39;timestamp&#39;</span> =&gt; microtime(TRUE),</div>
<div class="line"><a name="l01420"></a><span class="lineno"> 1420</span>&#160;     <span class="stringliteral">&#39;memory&#39;</span> =&gt; memory_get_usage(),</div>
<div class="line"><a name="l01421"></a><span class="lineno"> 1421</span>&#160;   );</div>
<div class="line"><a name="l01422"></a><span class="lineno"> 1422</span>&#160;  $entry[<span class="stringliteral">&#39;error&#39;</span>] = $error;</div>
<div class="line"><a name="l01423"></a><span class="lineno"> 1423</span>&#160;  $log[] = $entry;</div>
<div class="line"><a name="l01424"></a><span class="lineno"> 1424</span>&#160;  <a class="code" href="backend_8inc.html#a38490210d77373f3d8492caf4e9a3190">drush_backend_packet</a>(<span class="stringliteral">&#39;log&#39;</span>, $entry);</div>
<div class="line"><a name="l01425"></a><span class="lineno"> 1425</span>&#160;</div>
<div class="line"><a name="l01426"></a><span class="lineno"> 1426</span>&#160;  <span class="keywordflow">return</span> $callback($entry);</div>
<div class="line"><a name="l01427"></a><span class="lineno"> 1427</span>&#160;}</div>
<div class="line"><a name="l01428"></a><span class="lineno"> 1428</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01429"></a><span class="lineno"> 1429</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01430"></a><span class="lineno"> 1430</span>&#160;<span class="comment"> * Backend command callback. Add a log message to the log history.</span></div>
<div class="line"><a name="l01431"></a><span class="lineno"> 1431</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01432"></a><span class="lineno"> 1432</span>&#160;<span class="comment"> * @param entry</span></div>
<div class="line"><a name="l01433"></a><span class="lineno"> 1433</span>&#160;<span class="comment"> *   The log entry.</span></div>
<div class="line"><a name="l01434"></a><span class="lineno"> 1434</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01435"></a><span class="lineno"><a class="code" href="group__logging.html#gab4b585b7e23e1133de0497661b0d829c"> 1435</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__logging.html#gab4b585b7e23e1133de0497661b0d829c">drush_backend_packet_log</a>($entry, $backend_options) {</div>
<div class="line"><a name="l01436"></a><span class="lineno"> 1436</span>&#160;  <span class="keywordflow">if</span> (!$backend_options[<span class="stringliteral">&#39;log&#39;</span>]) {</div>
<div class="line"><a name="l01437"></a><span class="lineno"> 1437</span>&#160;    <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l01438"></a><span class="lineno"> 1438</span>&#160;  }</div>
<div class="line"><a name="l01439"></a><span class="lineno"> 1439</span>&#160;  <span class="keywordflow">if</span> (!is_string($entry[<span class="stringliteral">&#39;message&#39;</span>])) {</div>
<div class="line"><a name="l01440"></a><span class="lineno"> 1440</span>&#160;    $entry[<span class="stringliteral">&#39;message&#39;</span>] = implode(<span class="stringliteral">&quot;\n&quot;</span>, (array)$entry[<span class="stringliteral">&#39;message&#39;</span>]);</div>
<div class="line"><a name="l01441"></a><span class="lineno"> 1441</span>&#160;  }</div>
<div class="line"><a name="l01442"></a><span class="lineno"> 1442</span>&#160;  $entry[<span class="stringliteral">&#39;message&#39;</span>] = $entry[<span class="stringliteral">&#39;message&#39;</span>];</div>
<div class="line"><a name="l01443"></a><span class="lineno"> 1443</span>&#160;  $log =&amp; <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_LOG&#39;</span>, array());</div>
<div class="line"><a name="l01444"></a><span class="lineno"> 1444</span>&#160;  $log[] = $entry;</div>
<div class="line"><a name="l01445"></a><span class="lineno"> 1445</span>&#160;  <span class="comment">// Yes, this looks odd, but we might in fact be a backend command</span></div>
<div class="line"><a name="l01446"></a><span class="lineno"> 1446</span>&#160;  <span class="comment">// that ran another backend command.</span></div>
<div class="line"><a name="l01447"></a><span class="lineno"> 1447</span>&#160;  <a class="code" href="backend_8inc.html#a38490210d77373f3d8492caf4e9a3190">drush_backend_packet</a>(<span class="stringliteral">&#39;log&#39;</span>, $entry);</div>
<div class="line"><a name="l01448"></a><span class="lineno"> 1448</span>&#160;  <span class="keywordflow">if</span> (array_key_exists(<span class="stringliteral">&#39;#output-label&#39;</span>, $backend_options)) {</div>
<div class="line"><a name="l01449"></a><span class="lineno"> 1449</span>&#160;    $entry[<span class="stringliteral">&#39;message&#39;</span>] = $backend_options[<span class="stringliteral">&#39;#output-label&#39;</span>] . $entry[<span class="stringliteral">&#39;message&#39;</span>];</div>
<div class="line"><a name="l01450"></a><span class="lineno"> 1450</span>&#160;  }</div>
<div class="line"><a name="l01451"></a><span class="lineno"> 1451</span>&#160;</div>
<div class="line"><a name="l01452"></a><span class="lineno"> 1452</span>&#160;  <span class="comment">// If integrate is FALSE, then log messages are stored in DRUSH_LOG,</span></div>
<div class="line"><a name="l01453"></a><span class="lineno"> 1453</span>&#160;  <span class="comment">// but are -not- printed to the console.</span></div>
<div class="line"><a name="l01454"></a><span class="lineno"> 1454</span>&#160;  <span class="keywordflow">if</span> ($backend_options[<span class="stringliteral">&#39;integrate&#39;</span>]) {</div>
<div class="line"><a name="l01455"></a><span class="lineno"> 1455</span>&#160;    $callback = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_LOG_CALLBACK&#39;</span>, <span class="stringliteral">&#39;_drush_print_log&#39;</span>);</div>
<div class="line"><a name="l01456"></a><span class="lineno"> 1456</span>&#160;    <span class="keywordflow">return</span> $callback($entry);</div>
<div class="line"><a name="l01457"></a><span class="lineno"> 1457</span>&#160;  }</div>
<div class="line"><a name="l01458"></a><span class="lineno"> 1458</span>&#160;}</div>
<div class="line"><a name="l01459"></a><span class="lineno"> 1459</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01460"></a><span class="lineno"> 1460</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01461"></a><span class="lineno"> 1461</span>&#160;<span class="comment"> * Retrieve the log messages from the log history</span></div>
<div class="line"><a name="l01462"></a><span class="lineno"> 1462</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01463"></a><span class="lineno"> 1463</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l01464"></a><span class="lineno"> 1464</span>&#160;<span class="comment"> *   Entire log history</span></div>
<div class="line"><a name="l01465"></a><span class="lineno"> 1465</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01466"></a><span class="lineno"><a class="code" href="group__logging.html#ga5258324e4f8b274b092f8ce17610619f"> 1466</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__logging.html#ga5258324e4f8b274b092f8ce17610619f">drush_get_log</a>() {</div>
<div class="line"><a name="l01467"></a><span class="lineno"> 1467</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_LOG&#39;</span>, array());</div>
<div class="line"><a name="l01468"></a><span class="lineno"> 1468</span>&#160;}</div>
<div class="line"><a name="l01469"></a><span class="lineno"> 1469</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01470"></a><span class="lineno"> 1470</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01471"></a><span class="lineno"> 1471</span>&#160;<span class="comment"> * Run print_r on a variable and log the output.</span></div>
<div class="line"><a name="l01472"></a><span class="lineno"> 1472</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01473"></a><span class="lineno"><a class="code" href="group__logging.html#ga04ee00415bd09ba25a40b8532887e73f"> 1473</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__logging.html#ga04ee00415bd09ba25a40b8532887e73f">dlm</a>($object) {</div>
<div class="line"><a name="l01474"></a><span class="lineno"> 1474</span>&#160;  <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(print_r($object, TRUE));</div>
<div class="line"><a name="l01475"></a><span class="lineno"> 1475</span>&#160;}</div>
<div class="line"><a name="l01476"></a><span class="lineno"> 1476</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01477"></a><span class="lineno"> 1477</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01478"></a><span class="lineno"> 1478</span>&#160;<span class="comment"> * Display the pipe output for the current request.</span></div>
<div class="line"><a name="l01479"></a><span class="lineno"> 1479</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01480"></a><span class="lineno"><a class="code" href="group__logging.html#ga4abb05d29558e4bc563592c0e3442623"> 1480</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__logging.html#ga4abb05d29558e4bc563592c0e3442623">drush_pipe_output</a>() {</div>
<div class="line"><a name="l01481"></a><span class="lineno"> 1481</span>&#160;  $pipe = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_PIPE_BUFFER&#39;</span>);</div>
<div class="line"><a name="l01482"></a><span class="lineno"> 1482</span>&#160;  <span class="keywordflow">if</span> (!empty($pipe)) {</div>
<div class="line"><a name="l01483"></a><span class="lineno"> 1483</span>&#160;    <a class="code" href="group__outputfunctions.html#gaef65927c0dd1ce225ca1e3fca4eff03f">drush_print_r</a>($pipe, NULL, FALSE);</div>
<div class="line"><a name="l01484"></a><span class="lineno"> 1484</span>&#160;  }</div>
<div class="line"><a name="l01485"></a><span class="lineno"> 1485</span>&#160;}</div>
<div class="line"><a name="l01486"></a><span class="lineno"> 1486</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01487"></a><span class="lineno"> 1487</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01488"></a><span class="lineno"> 1488</span>&#160;<span class="comment"> * Display the log message</span></div>
<div class="line"><a name="l01489"></a><span class="lineno"> 1489</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01490"></a><span class="lineno"> 1490</span>&#160;<span class="comment"> * By default, only warnings and errors will be displayed, if &#39;verbose&#39; is specified, it will also display notices.</span></div>
<div class="line"><a name="l01491"></a><span class="lineno"> 1491</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01492"></a><span class="lineno"> 1492</span>&#160;<span class="comment"> * @param</span></div>
<div class="line"><a name="l01493"></a><span class="lineno"> 1493</span>&#160;<span class="comment"> *   The associative array for the entry.</span></div>
<div class="line"><a name="l01494"></a><span class="lineno"> 1494</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01495"></a><span class="lineno"> 1495</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l01496"></a><span class="lineno"> 1496</span>&#160;<span class="comment"> *   False in case of an error or failed type, True in all other cases.</span></div>
<div class="line"><a name="l01497"></a><span class="lineno"> 1497</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01498"></a><span class="lineno"><a class="code" href="group__logging.html#ga15a903e2bc6fdb8aa8016fd73599c12b"> 1498</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__logging.html#ga15a903e2bc6fdb8aa8016fd73599c12b">_drush_print_log</a>($entry) {</div>
<div class="line"><a name="l01499"></a><span class="lineno"> 1499</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_NOCOLOR&#39;</span>)) {</div>
<div class="line"><a name="l01500"></a><span class="lineno"> 1500</span>&#160;    $red = <span class="stringliteral">&quot;[%s]&quot;</span>;</div>
<div class="line"><a name="l01501"></a><span class="lineno"> 1501</span>&#160;    $yellow = <span class="stringliteral">&quot;[%s]&quot;</span>;</div>
<div class="line"><a name="l01502"></a><span class="lineno"> 1502</span>&#160;    $green = <span class="stringliteral">&quot;[%s]&quot;</span>;</div>
<div class="line"><a name="l01503"></a><span class="lineno"> 1503</span>&#160;  }</div>
<div class="line"><a name="l01504"></a><span class="lineno"> 1504</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l01505"></a><span class="lineno"> 1505</span>&#160;    $red = <span class="stringliteral">&quot;\033[31;40m\033[1m[%s]\033[0m&quot;</span>;</div>
<div class="line"><a name="l01506"></a><span class="lineno"> 1506</span>&#160;    $yellow = <span class="stringliteral">&quot;\033[1;33;40m\033[1m[%s]\033[0m&quot;</span>;</div>
<div class="line"><a name="l01507"></a><span class="lineno"> 1507</span>&#160;    $green = <span class="stringliteral">&quot;\033[1;32;40m\033[1m[%s]\033[0m&quot;</span>;</div>
<div class="line"><a name="l01508"></a><span class="lineno"> 1508</span>&#160;  }</div>
<div class="line"><a name="l01509"></a><span class="lineno"> 1509</span>&#160;</div>
<div class="line"><a name="l01510"></a><span class="lineno"> 1510</span>&#160;  $verbose = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_VERBOSE&#39;</span>);</div>
<div class="line"><a name="l01511"></a><span class="lineno"> 1511</span>&#160;  $debug = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_DEBUG&#39;</span>);</div>
<div class="line"><a name="l01512"></a><span class="lineno"> 1512</span>&#160;</div>
<div class="line"><a name="l01513"></a><span class="lineno"> 1513</span>&#160;  $return = TRUE;</div>
<div class="line"><a name="l01514"></a><span class="lineno"> 1514</span>&#160;  <span class="keywordflow">switch</span> ($entry[<span class="stringliteral">&#39;type&#39;</span>]) {</div>
<div class="line"><a name="l01515"></a><span class="lineno"> 1515</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;warning&#39;</span> :</div>
<div class="line"><a name="l01516"></a><span class="lineno"> 1516</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;cancel&#39;</span> :</div>
<div class="line"><a name="l01517"></a><span class="lineno"> 1517</span>&#160;      $type_msg = sprintf($yellow, $entry[<span class="stringliteral">&#39;type&#39;</span>]);</div>
<div class="line"><a name="l01518"></a><span class="lineno"> 1518</span>&#160;      <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l01519"></a><span class="lineno"> 1519</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;failed&#39;</span> :</div>
<div class="line"><a name="l01520"></a><span class="lineno"> 1520</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;error&#39;</span> :</div>
<div class="line"><a name="l01521"></a><span class="lineno"> 1521</span>&#160;      $type_msg = sprintf($red, $entry[<span class="stringliteral">&#39;type&#39;</span>]);</div>
<div class="line"><a name="l01522"></a><span class="lineno"> 1522</span>&#160;      $return = FALSE;</div>
<div class="line"><a name="l01523"></a><span class="lineno"> 1523</span>&#160;      <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l01524"></a><span class="lineno"> 1524</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;ok&#39;</span> :</div>
<div class="line"><a name="l01525"></a><span class="lineno"> 1525</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;completed&#39;</span> :</div>
<div class="line"><a name="l01526"></a><span class="lineno"> 1526</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;success&#39;</span> :</div>
<div class="line"><a name="l01527"></a><span class="lineno"> 1527</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;status&#39;</span>:</div>
<div class="line"><a name="l01528"></a><span class="lineno"> 1528</span>&#160;      <span class="comment">// In quiet mode, suppress progress messages</span></div>
<div class="line"><a name="l01529"></a><span class="lineno"> 1529</span>&#160;      <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_QUIET&#39;</span>)) {</div>
<div class="line"><a name="l01530"></a><span class="lineno"> 1530</span>&#160;        <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l01531"></a><span class="lineno"> 1531</span>&#160;      }</div>
<div class="line"><a name="l01532"></a><span class="lineno"> 1532</span>&#160;      $type_msg = sprintf($green, $entry[<span class="stringliteral">&#39;type&#39;</span>]);</div>
<div class="line"><a name="l01533"></a><span class="lineno"> 1533</span>&#160;      <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l01534"></a><span class="lineno"> 1534</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;notice&#39;</span> :</div>
<div class="line"><a name="l01535"></a><span class="lineno"> 1535</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;message&#39;</span> :</div>
<div class="line"><a name="l01536"></a><span class="lineno"> 1536</span>&#160;    <span class="keywordflow">case</span> <span class="stringliteral">&#39;info&#39;</span> :</div>
<div class="line"><a name="l01537"></a><span class="lineno"> 1537</span>&#160;      <span class="keywordflow">if</span> (!$verbose) {</div>
<div class="line"><a name="l01538"></a><span class="lineno"> 1538</span>&#160;        <span class="comment">// print nothing. exit cleanly.</span></div>
<div class="line"><a name="l01539"></a><span class="lineno"> 1539</span>&#160;        <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l01540"></a><span class="lineno"> 1540</span>&#160;      }</div>
<div class="line"><a name="l01541"></a><span class="lineno"> 1541</span>&#160;      $type_msg = sprintf(<span class="stringliteral">&quot;[%s]&quot;</span>, $entry[<span class="stringliteral">&#39;type&#39;</span>]);</div>
<div class="line"><a name="l01542"></a><span class="lineno"> 1542</span>&#160;      <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l01543"></a><span class="lineno"> 1543</span>&#160;    <span class="keywordflow">default</span> :</div>
<div class="line"><a name="l01544"></a><span class="lineno"> 1544</span>&#160;      <span class="keywordflow">if</span> (!$debug) {</div>
<div class="line"><a name="l01545"></a><span class="lineno"> 1545</span>&#160;        <span class="comment">// print nothing. exit cleanly.</span></div>
<div class="line"><a name="l01546"></a><span class="lineno"> 1546</span>&#160;        <span class="keywordflow">return</span> TRUE;</div>
<div class="line"><a name="l01547"></a><span class="lineno"> 1547</span>&#160;      }</div>
<div class="line"><a name="l01548"></a><span class="lineno"> 1548</span>&#160;      $type_msg = sprintf(<span class="stringliteral">&quot;[%s]&quot;</span>, $entry[<span class="stringliteral">&#39;type&#39;</span>]);</div>
<div class="line"><a name="l01549"></a><span class="lineno"> 1549</span>&#160;      <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l01550"></a><span class="lineno"> 1550</span>&#160;  }</div>
<div class="line"><a name="l01551"></a><span class="lineno"> 1551</span>&#160;</div>
<div class="line"><a name="l01552"></a><span class="lineno"> 1552</span>&#160;  <span class="comment">// When running in backend mode, log messages are not displayed, as they will</span></div>
<div class="line"><a name="l01553"></a><span class="lineno"> 1553</span>&#160;  <span class="comment">// be returned in the JSON encoded associative array.</span></div>
<div class="line"><a name="l01554"></a><span class="lineno"> 1554</span>&#160;  <span class="keywordflow">if</span> (<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_BACKEND&#39;</span>)) {</div>
<div class="line"><a name="l01555"></a><span class="lineno"> 1555</span>&#160;    <span class="keywordflow">return</span> $return;</div>
<div class="line"><a name="l01556"></a><span class="lineno"> 1556</span>&#160;  }</div>
<div class="line"><a name="l01557"></a><span class="lineno"> 1557</span>&#160;</div>
<div class="line"><a name="l01558"></a><span class="lineno"> 1558</span>&#160;  $columns = <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_COLUMNS&#39;</span>, 80);</div>
<div class="line"><a name="l01559"></a><span class="lineno"> 1559</span>&#160;</div>
<div class="line"><a name="l01560"></a><span class="lineno"> 1560</span>&#160;  $width[1] = 11;</div>
<div class="line"><a name="l01561"></a><span class="lineno"> 1561</span>&#160;  <span class="comment">// Append timer and memory values.</span></div>
<div class="line"><a name="l01562"></a><span class="lineno"> 1562</span>&#160;  <span class="keywordflow">if</span> ($debug) {</div>
<div class="line"><a name="l01563"></a><span class="lineno"> 1563</span>&#160;    $timer = sprintf(<span class="stringliteral">&#39;[%s sec, %s]&#39;</span>, round($entry[<span class="stringliteral">&#39;timestamp&#39;</span>]-DRUSH_REQUEST_TIME, 2), drush_format_size($entry[<span class="stringliteral">&#39;memory&#39;</span>]));</div>
<div class="line"><a name="l01564"></a><span class="lineno"> 1564</span>&#160;    $entry[<span class="stringliteral">&#39;message&#39;</span>] = $entry[<span class="stringliteral">&#39;message&#39;</span>] . <span class="charliteral">&#39; &#39;</span> . $timer;</div>
<div class="line"><a name="l01565"></a><span class="lineno"> 1565</span>&#160;  }</div>
<div class="line"><a name="l01566"></a><span class="lineno"> 1566</span>&#160;</div>
<div class="line"><a name="l01567"></a><span class="lineno"> 1567</span>&#160;  $width[0] = ($columns - 11);</div>
<div class="line"><a name="l01568"></a><span class="lineno"> 1568</span>&#160;</div>
<div class="line"><a name="l01569"></a><span class="lineno"> 1569</span>&#160;  $format = sprintf(<span class="stringliteral">&quot;%%-%ds%%%ds&quot;</span>, $width[0], $width[1]);</div>
<div class="line"><a name="l01570"></a><span class="lineno"> 1570</span>&#160;</div>
<div class="line"><a name="l01571"></a><span class="lineno"> 1571</span>&#160;  <span class="comment">// Place the status message right aligned with the top line of the error message.</span></div>
<div class="line"><a name="l01572"></a><span class="lineno"> 1572</span>&#160;  $message = wordwrap($entry[<span class="stringliteral">&#39;message&#39;</span>], $width[0]);</div>
<div class="line"><a name="l01573"></a><span class="lineno"> 1573</span>&#160;  $lines = explode(<span class="stringliteral">&quot;\n&quot;</span>, $message);</div>
<div class="line"><a name="l01574"></a><span class="lineno"> 1574</span>&#160;  $lines[0] = sprintf($format, $lines[0], $type_msg);</div>
<div class="line"><a name="l01575"></a><span class="lineno"> 1575</span>&#160;  $message = implode(<span class="stringliteral">&quot;\n&quot;</span>, $lines);</div>
<div class="line"><a name="l01576"></a><span class="lineno"> 1576</span>&#160;  <a class="code" href="group__outputfunctions.html#ga63acbb94925d6d2693e235e966bba740">drush_print</a>($message, 0, STDERR);</div>
<div class="line"><a name="l01577"></a><span class="lineno"> 1577</span>&#160;  <span class="keywordflow">return</span> $return;</div>
<div class="line"><a name="l01578"></a><span class="lineno"> 1578</span>&#160;}</div>
<div class="line"><a name="l01579"></a><span class="lineno"> 1579</span>&#160;</div>
<div class="line"><a name="l01580"></a><span class="lineno"> 1580</span>&#160;<span class="comment">// Print all timers for the request.</span></div>
<div class="line"><a name="l01581"></a><span class="lineno"> 1581</span>&#160;<span class="keyword">function</span> drush_print_timers() {</div>
<div class="line"><a name="l01582"></a><span class="lineno"> 1582</span>&#160;  global $timers;</div>
<div class="line"><a name="l01583"></a><span class="lineno"> 1583</span>&#160;  $temparray = array();</div>
<div class="line"><a name="l01584"></a><span class="lineno"> 1584</span>&#160;  <span class="keywordflow">foreach</span> ((array)$timers as $name =&gt; $timerec) {</div>
<div class="line"><a name="l01585"></a><span class="lineno"> 1585</span>&#160;    <span class="comment">// We have to use timer_read() for active timers, and check the record for others</span></div>
<div class="line"><a name="l01586"></a><span class="lineno"> 1586</span>&#160;    <span class="keywordflow">if</span> (isset($timerec[<span class="stringliteral">&#39;start&#39;</span>])) {</div>
<div class="line"><a name="l01587"></a><span class="lineno"> 1587</span>&#160;      $temparray[$name] = timer_read($name);</div>
<div class="line"><a name="l01588"></a><span class="lineno"> 1588</span>&#160;    }</div>
<div class="line"><a name="l01589"></a><span class="lineno"> 1589</span>&#160;    <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l01590"></a><span class="lineno"> 1590</span>&#160;      $temparray[$name] = $timerec[<span class="stringliteral">&#39;time&#39;</span>];</div>
<div class="line"><a name="l01591"></a><span class="lineno"> 1591</span>&#160;    }</div>
<div class="line"><a name="l01592"></a><span class="lineno"> 1592</span>&#160;  }</div>
<div class="line"><a name="l01593"></a><span class="lineno"> 1593</span>&#160;  <span class="comment">// Go no farther if there were no timers</span></div>
<div class="line"><a name="l01594"></a><span class="lineno"> 1594</span>&#160;  <span class="keywordflow">if</span> (count($temparray) &gt; 0) {</div>
<div class="line"><a name="l01595"></a><span class="lineno"> 1595</span>&#160;    <span class="comment">// Put the highest cumulative times first</span></div>
<div class="line"><a name="l01596"></a><span class="lineno"> 1596</span>&#160;    arsort($temparray);</div>
<div class="line"><a name="l01597"></a><span class="lineno"> 1597</span>&#160;    $table = array();</div>
<div class="line"><a name="l01598"></a><span class="lineno"> 1598</span>&#160;    $table[] = array(<span class="stringliteral">&#39;Timer&#39;</span>, <span class="stringliteral">&#39;Cum (sec)&#39;</span>, <span class="stringliteral">&#39;Count&#39;</span>, <span class="stringliteral">&#39;Avg (msec)&#39;</span>);</div>
<div class="line"><a name="l01599"></a><span class="lineno"> 1599</span>&#160;    <span class="keywordflow">foreach</span> ($temparray as $name =&gt; $time) {</div>
<div class="line"><a name="l01600"></a><span class="lineno"> 1600</span>&#160;      $cum = round($time/1000, 3);</div>
<div class="line"><a name="l01601"></a><span class="lineno"> 1601</span>&#160;      $count = $timers[$name][<span class="stringliteral">&#39;count&#39;</span>];</div>
<div class="line"><a name="l01602"></a><span class="lineno"> 1602</span>&#160;      <span class="keywordflow">if</span> ($count &gt; 0) {</div>
<div class="line"><a name="l01603"></a><span class="lineno"> 1603</span>&#160;        $avg = round($time/$count, 3);</div>
<div class="line"><a name="l01604"></a><span class="lineno"> 1604</span>&#160;      }</div>
<div class="line"><a name="l01605"></a><span class="lineno"> 1605</span>&#160;      <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l01606"></a><span class="lineno"> 1606</span>&#160;        $avg = <span class="stringliteral">&#39;N/A&#39;</span>;</div>
<div class="line"><a name="l01607"></a><span class="lineno"> 1607</span>&#160;      }</div>
<div class="line"><a name="l01608"></a><span class="lineno"> 1608</span>&#160;      $table[] = array($name, $cum, $count, $avg);</div>
<div class="line"><a name="l01609"></a><span class="lineno"> 1609</span>&#160;    }</div>
<div class="line"><a name="l01610"></a><span class="lineno"> 1610</span>&#160;    <a class="code" href="group__outputfunctions.html#ga2dfb80176f98c67097334acfa98211cd">drush_print_table</a>($table, TRUE, array(), STDERR);</div>
<div class="line"><a name="l01611"></a><span class="lineno"> 1611</span>&#160;  }</div>
<div class="line"><a name="l01612"></a><span class="lineno"> 1612</span>&#160;}</div>
<div class="line"><a name="l01613"></a><span class="lineno"> 1613</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01614"></a><span class="lineno"> 1614</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01615"></a><span class="lineno"> 1615</span>&#160;<span class="comment">* Turn drupal_set_message errors into drush_log errors</span></div>
<div class="line"><a name="l01616"></a><span class="lineno"> 1616</span>&#160;<span class="comment">*/</span></div>
<div class="line"><a name="l01617"></a><span class="lineno"><a class="code" href="group__logging.html#ga15230dd6f6b5765f6c1447d4c2b73940"> 1617</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__logging.html#ga15230dd6f6b5765f6c1447d4c2b73940">_drush_log_drupal_messages</a>() {</div>
<div class="line"><a name="l01618"></a><span class="lineno"> 1618</span>&#160;  <span class="keywordflow">if</span> (function_exists(<span class="stringliteral">&#39;drupal_get_messages&#39;</span>)) {</div>
<div class="line"><a name="l01619"></a><span class="lineno"> 1619</span>&#160;</div>
<div class="line"><a name="l01620"></a><span class="lineno"> 1620</span>&#160;    $messages = drupal_get_messages(NULL, TRUE);</div>
<div class="line"><a name="l01621"></a><span class="lineno"> 1621</span>&#160;</div>
<div class="line"><a name="l01622"></a><span class="lineno"> 1622</span>&#160;    <span class="keywordflow">if</span> (array_key_exists(<span class="stringliteral">&#39;error&#39;</span>, $messages)) {</div>
<div class="line"><a name="l01623"></a><span class="lineno"> 1623</span>&#160;      <span class="comment">//Drupal message errors.</span></div>
<div class="line"><a name="l01624"></a><span class="lineno"> 1624</span>&#160;      <span class="keywordflow">foreach</span> ((array) $messages[<span class="stringliteral">&#39;error&#39;</span>] as $error) {</div>
<div class="line"><a name="l01625"></a><span class="lineno"> 1625</span>&#160;        $error = strip_tags($error);</div>
<div class="line"><a name="l01626"></a><span class="lineno"> 1626</span>&#160;        $header = preg_match(<span class="stringliteral">&#39;/^warning: Cannot modify header information - headers already sent by /i&#39;</span>, $error);</div>
<div class="line"><a name="l01627"></a><span class="lineno"> 1627</span>&#160;        $session = preg_match(<span class="stringliteral">&#39;/^warning: session_start\(\): Cannot send session /i&#39;</span>, $error);</div>
<div class="line"><a name="l01628"></a><span class="lineno"> 1628</span>&#160;        <span class="keywordflow">if</span> ($header || $session) {</div>
<div class="line"><a name="l01629"></a><span class="lineno"> 1629</span>&#160;          <span class="comment">//These are special cases for an unavoidable warnings</span></div>
<div class="line"><a name="l01630"></a><span class="lineno"> 1630</span>&#160;          <span class="comment">//that are generated by generating output before Drupal is bootstrapped.</span></div>
<div class="line"><a name="l01631"></a><span class="lineno"> 1631</span>&#160;          <span class="comment">//or sending a session cookie (seems to affect d7 only?)</span></div>
<div class="line"><a name="l01632"></a><span class="lineno"> 1632</span>&#160;          <span class="comment">//Simply ignore them.</span></div>
<div class="line"><a name="l01633"></a><span class="lineno"> 1633</span>&#160;          <span class="keywordflow">continue</span>;</div>
<div class="line"><a name="l01634"></a><span class="lineno"> 1634</span>&#160;        }</div>
<div class="line"><a name="l01635"></a><span class="lineno"> 1635</span>&#160;        elseif (preg_match(<span class="stringliteral">&#39;/^warning:/i&#39;</span>, $error)) {</div>
<div class="line"><a name="l01636"></a><span class="lineno"> 1636</span>&#160;          <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(preg_replace(<span class="stringliteral">&#39;/^warning: /i&#39;</span>, <span class="stringliteral">&#39;&#39;</span>, $error), <span class="stringliteral">&#39;warning&#39;</span>);</div>
<div class="line"><a name="l01637"></a><span class="lineno"> 1637</span>&#160;        }</div>
<div class="line"><a name="l01638"></a><span class="lineno"> 1638</span>&#160;        elseif (preg_match(<span class="stringliteral">&#39;/^notice:/i&#39;</span>, $error)) {</div>
<div class="line"><a name="l01639"></a><span class="lineno"> 1639</span>&#160;          <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(preg_replace(<span class="stringliteral">&#39;/^notice: /i&#39;</span>, <span class="stringliteral">&#39;&#39;</span>, $error), <span class="stringliteral">&#39;notice&#39;</span>);</div>
<div class="line"><a name="l01640"></a><span class="lineno"> 1640</span>&#160;        }</div>
<div class="line"><a name="l01641"></a><span class="lineno"> 1641</span>&#160;        elseif (preg_match(<span class="stringliteral">&#39;/^user warning:/i&#39;</span>, $error)) {</div>
<div class="line"><a name="l01642"></a><span class="lineno"> 1642</span>&#160;          <span class="comment">// This is a special case. PHP logs sql errors as &#39;User Warnings&#39;, not errors.</span></div>
<div class="line"><a name="l01643"></a><span class="lineno"> 1643</span>&#160;          <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_DRUPAL_ERROR_MESSAGE&#39;</span>, preg_replace(<span class="stringliteral">&#39;/^user warning: /i&#39;</span>, <span class="stringliteral">&#39;&#39;</span>, $error));</div>
<div class="line"><a name="l01644"></a><span class="lineno"> 1644</span>&#160;        }</div>
<div class="line"><a name="l01645"></a><span class="lineno"> 1645</span>&#160;        <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l01646"></a><span class="lineno"> 1646</span>&#160;          <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>(<span class="stringliteral">&#39;DRUSH_DRUPAL_ERROR_MESSAGE&#39;</span>, $error);</div>
<div class="line"><a name="l01647"></a><span class="lineno"> 1647</span>&#160;        }</div>
<div class="line"><a name="l01648"></a><span class="lineno"> 1648</span>&#160;      }</div>
<div class="line"><a name="l01649"></a><span class="lineno"> 1649</span>&#160;    }</div>
<div class="line"><a name="l01650"></a><span class="lineno"> 1650</span>&#160;    unset($messages[<span class="stringliteral">&#39;error&#39;</span>]);</div>
<div class="line"><a name="l01651"></a><span class="lineno"> 1651</span>&#160;</div>
<div class="line"><a name="l01652"></a><span class="lineno"> 1652</span>&#160;    <span class="comment">// Log non-error messages.</span></div>
<div class="line"><a name="l01653"></a><span class="lineno"> 1653</span>&#160;    <span class="keywordflow">foreach</span> ($messages as $type =&gt; $items) {</div>
<div class="line"><a name="l01654"></a><span class="lineno"> 1654</span>&#160;      <span class="keywordflow">foreach</span> ($items as $item) {</div>
<div class="line"><a name="l01655"></a><span class="lineno"> 1655</span>&#160;        <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(strip_tags($item), $type);</div>
<div class="line"><a name="l01656"></a><span class="lineno"> 1656</span>&#160;      }</div>
<div class="line"><a name="l01657"></a><span class="lineno"> 1657</span>&#160;    }</div>
<div class="line"><a name="l01658"></a><span class="lineno"> 1658</span>&#160;  }</div>
<div class="line"><a name="l01659"></a><span class="lineno"> 1659</span>&#160;}</div>
<div class="line"><a name="l01660"></a><span class="lineno"> 1660</span>&#160;</div>
<div class="line"><a name="l01661"></a><span class="lineno"> 1661</span>&#160;<span class="comment">// Copy of format_size() in Drupal.</span></div>
<div class="line"><a name="l01662"></a><span class="lineno"> 1662</span>&#160;<span class="keyword">function</span> drush_format_size($size, $langcode = NULL) {</div>
<div class="line"><a name="l01663"></a><span class="lineno"> 1663</span>&#160;  <span class="keywordflow">if</span> ($size &lt; <a class="code" href="drush_8inc.html#a0a75d4291b848dda33fab74050e0ab14">DRUSH_KILOBYTE</a>) {</div>
<div class="line"><a name="l01664"></a><span class="lineno"> 1664</span>&#160;    <span class="comment">// format_plural() not always available.</span></div>
<div class="line"><a name="l01665"></a><span class="lineno"> 1665</span>&#160;    <span class="keywordflow">return</span> <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;@count bytes&#39;</span>, array(<span class="stringliteral">&#39;@count&#39;</span> =&gt; $size));</div>
<div class="line"><a name="l01666"></a><span class="lineno"> 1666</span>&#160;  }</div>
<div class="line"><a name="l01667"></a><span class="lineno"> 1667</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l01668"></a><span class="lineno"> 1668</span>&#160;    $size = $size / <a class="code" href="drush_8inc.html#a0a75d4291b848dda33fab74050e0ab14">DRUSH_KILOBYTE</a>; <span class="comment">// Convert bytes to kilobytes.</span></div>
<div class="line"><a name="l01669"></a><span class="lineno"> 1669</span>&#160;    $units = array(</div>
<div class="line"><a name="l01670"></a><span class="lineno"> 1670</span>&#160;      <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;@size KB&#39;</span>, array(), array(<span class="stringliteral">&#39;langcode&#39;</span> =&gt; $langcode)),</div>
<div class="line"><a name="l01671"></a><span class="lineno"> 1671</span>&#160;      <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;@size MB&#39;</span>, array(), array(<span class="stringliteral">&#39;langcode&#39;</span> =&gt; $langcode)),</div>
<div class="line"><a name="l01672"></a><span class="lineno"> 1672</span>&#160;      <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;@size GB&#39;</span>, array(), array(<span class="stringliteral">&#39;langcode&#39;</span> =&gt; $langcode)),</div>
<div class="line"><a name="l01673"></a><span class="lineno"> 1673</span>&#160;      <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;@size TB&#39;</span>, array(), array(<span class="stringliteral">&#39;langcode&#39;</span> =&gt; $langcode)),</div>
<div class="line"><a name="l01674"></a><span class="lineno"> 1674</span>&#160;      <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;@size PB&#39;</span>, array(), array(<span class="stringliteral">&#39;langcode&#39;</span> =&gt; $langcode)),</div>
<div class="line"><a name="l01675"></a><span class="lineno"> 1675</span>&#160;      <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;@size EB&#39;</span>, array(), array(<span class="stringliteral">&#39;langcode&#39;</span> =&gt; $langcode)),</div>
<div class="line"><a name="l01676"></a><span class="lineno"> 1676</span>&#160;      <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;@size ZB&#39;</span>, array(), array(<span class="stringliteral">&#39;langcode&#39;</span> =&gt; $langcode)),</div>
<div class="line"><a name="l01677"></a><span class="lineno"> 1677</span>&#160;      <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;@size YB&#39;</span>, array(), array(<span class="stringliteral">&#39;langcode&#39;</span> =&gt; $langcode)),</div>
<div class="line"><a name="l01678"></a><span class="lineno"> 1678</span>&#160;    );</div>
<div class="line"><a name="l01679"></a><span class="lineno"> 1679</span>&#160;    <span class="keywordflow">foreach</span> ($units as $unit) {</div>
<div class="line"><a name="l01680"></a><span class="lineno"> 1680</span>&#160;      <span class="keywordflow">if</span> (round($size, 2) &gt;= <a class="code" href="drush_8inc.html#a0a75d4291b848dda33fab74050e0ab14">DRUSH_KILOBYTE</a>) {</div>
<div class="line"><a name="l01681"></a><span class="lineno"> 1681</span>&#160;        $size = $size / <a class="code" href="drush_8inc.html#a0a75d4291b848dda33fab74050e0ab14">DRUSH_KILOBYTE</a>;</div>
<div class="line"><a name="l01682"></a><span class="lineno"> 1682</span>&#160;      }</div>
<div class="line"><a name="l01683"></a><span class="lineno"> 1683</span>&#160;      <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l01684"></a><span class="lineno"> 1684</span>&#160;        <span class="keywordflow">break</span>;</div>
<div class="line"><a name="l01685"></a><span class="lineno"> 1685</span>&#160;      }</div>
<div class="line"><a name="l01686"></a><span class="lineno"> 1686</span>&#160;    }</div>
<div class="line"><a name="l01687"></a><span class="lineno"> 1687</span>&#160;    <span class="keywordflow">return</span> str_replace(<span class="stringliteral">&#39;@size&#39;</span>, round($size, 2), $unit);</div>
<div class="line"><a name="l01688"></a><span class="lineno"> 1688</span>&#160;  }</div>
<div class="line"><a name="l01689"></a><span class="lineno"> 1689</span>&#160;}</div>
<div class="line"><a name="l01690"></a><span class="lineno"> 1690</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01691"></a><span class="lineno"> 1691</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01692"></a><span class="lineno"> 1692</span>&#160;<span class="comment"> * @} End of &quot;defgroup logging&quot;.</span></div>
<div class="line"><a name="l01693"></a><span class="lineno"> 1693</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01694"></a><span class="lineno"> 1694</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01695"></a><span class="lineno"> 1695</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01696"></a><span class="lineno"> 1696</span>&#160;<span class="comment"> * @defgroup errorhandling Managing errors that occur in the Drush framework.</span></div>
<div class="line"><a name="l01697"></a><span class="lineno"> 1697</span>&#160;<span class="comment"> * @{</span></div>
<div class="line"><a name="l01698"></a><span class="lineno"> 1698</span>&#160;<span class="comment"> * Functions that manage the current error status of the Drush framework.</span></div>
<div class="line"><a name="l01699"></a><span class="lineno"> 1699</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01700"></a><span class="lineno"> 1700</span>&#160;<span class="comment"> * These functions operate by maintaining a static variable that is a equal to the constant DRUSH_FRAMEWORK_ERROR if an</span></div>
<div class="line"><a name="l01701"></a><span class="lineno"> 1701</span>&#160;<span class="comment"> * error has occurred.</span></div>
<div class="line"><a name="l01702"></a><span class="lineno"> 1702</span>&#160;<span class="comment"> * This error code is returned at the end of program execution, and provide the shell or calling application with</span></div>
<div class="line"><a name="l01703"></a><span class="lineno"> 1703</span>&#160;<span class="comment"> * more information on how to diagnose any problems that may have occurred.</span></div>
<div class="line"><a name="l01704"></a><span class="lineno"> 1704</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01705"></a><span class="lineno"> 1705</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01706"></a><span class="lineno"> 1706</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01707"></a><span class="lineno"> 1707</span>&#160;<span class="comment"> * Set an error code for the error handling system.</span></div>
<div class="line"><a name="l01708"></a><span class="lineno"> 1708</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01709"></a><span class="lineno"> 1709</span>&#160;<span class="comment"> * @param error</span></div>
<div class="line"><a name="l01710"></a><span class="lineno"> 1710</span>&#160;<span class="comment"> *   A text string identifying the type of error.</span></div>
<div class="line"><a name="l01711"></a><span class="lineno"> 1711</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01712"></a><span class="lineno"> 1712</span>&#160;<span class="comment"> * @param message</span></div>
<div class="line"><a name="l01713"></a><span class="lineno"> 1713</span>&#160;<span class="comment"> *   Optional. Error message to be logged. If no message is specified, hook_drush_help will be consulted,</span></div>
<div class="line"><a name="l01714"></a><span class="lineno"> 1714</span>&#160;<span class="comment"> *   using a key of &#39;error:MY_ERROR_STRING&#39;.</span></div>
<div class="line"><a name="l01715"></a><span class="lineno"> 1715</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01716"></a><span class="lineno"> 1716</span>&#160;<span class="comment"> * @param $output_label</span></div>
<div class="line"><a name="l01717"></a><span class="lineno"> 1717</span>&#160;<span class="comment"> *   Optional. Label to prepend to the error message.</span></div>
<div class="line"><a name="l01718"></a><span class="lineno"> 1718</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01719"></a><span class="lineno"> 1719</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l01720"></a><span class="lineno"> 1720</span>&#160;<span class="comment"> *   Always returns FALSE, to allow you to return with false in the calling functions,</span></div>
<div class="line"><a name="l01721"></a><span class="lineno"> 1721</span>&#160;<span class="comment"> *   such as &lt;code&gt;return drush_set_error(&#39;DRUSH_FRAMEWORK_ERROR&#39;)&lt;/code&gt;</span></div>
<div class="line"><a name="l01722"></a><span class="lineno"> 1722</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01723"></a><span class="lineno"><a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4"> 1723</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__errorhandling.html#ga23fe9e1e8c1e5ade39256106044b6da4">drush_set_error</a>($error, $message = null, $output_label = <span class="stringliteral">&quot;&quot;</span>) {</div>
<div class="line"><a name="l01724"></a><span class="lineno"> 1724</span>&#160;  $error_code =&amp; <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_ERROR_CODE&#39;</span>, <a class="code" href="drush_8inc.html#af1fd588cf6b6a3d51e8055408ee86635">DRUSH_SUCCESS</a>);</div>
<div class="line"><a name="l01725"></a><span class="lineno"> 1725</span>&#160;  $error_code = <a class="code" href="drush_8inc.html#a7959436c0614636c05192a563bd6cfb5">DRUSH_FRAMEWORK_ERROR</a>;</div>
<div class="line"><a name="l01726"></a><span class="lineno"> 1726</span>&#160;</div>
<div class="line"><a name="l01727"></a><span class="lineno"> 1727</span>&#160;  $error_log =&amp; <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_ERROR_LOG&#39;</span>, array());</div>
<div class="line"><a name="l01728"></a><span class="lineno"> 1728</span>&#160;</div>
<div class="line"><a name="l01729"></a><span class="lineno"> 1729</span>&#160;  <span class="keywordflow">if</span> (is_numeric($error)) {</div>
<div class="line"><a name="l01730"></a><span class="lineno"> 1730</span>&#160;    $error = <span class="stringliteral">&#39;DRUSH_FRAMEWORK_ERROR&#39;</span>;</div>
<div class="line"><a name="l01731"></a><span class="lineno"> 1731</span>&#160;  }</div>
<div class="line"><a name="l01732"></a><span class="lineno"> 1732</span>&#160;</div>
<div class="line"><a name="l01733"></a><span class="lineno"> 1733</span>&#160;  $message = ($message) ? $message : <a class="code" href="includes_2command_8inc.html#a19eba9666aba673a64fbd78a2c5ef4f9">drush_command_invoke_all</a>(<span class="stringliteral">&#39;drush_help&#39;</span>, <span class="stringliteral">&#39;error:&#39;</span> . $error);</div>
<div class="line"><a name="l01734"></a><span class="lineno"> 1734</span>&#160;</div>
<div class="line"><a name="l01735"></a><span class="lineno"> 1735</span>&#160;  <span class="keywordflow">if</span> (is_array($message)) {</div>
<div class="line"><a name="l01736"></a><span class="lineno"> 1736</span>&#160;    $message = implode(<span class="stringliteral">&quot;\n&quot;</span>, $message);</div>
<div class="line"><a name="l01737"></a><span class="lineno"> 1737</span>&#160;  }</div>
<div class="line"><a name="l01738"></a><span class="lineno"> 1738</span>&#160;</div>
<div class="line"><a name="l01739"></a><span class="lineno"> 1739</span>&#160;  $error_log[$error][] = $message;</div>
<div class="line"><a name="l01740"></a><span class="lineno"> 1740</span>&#160;  <span class="keywordflow">if</span> (!<a class="code" href="backend_8inc.html#a38490210d77373f3d8492caf4e9a3190">drush_backend_packet</a>(<span class="stringliteral">&#39;set_error&#39;</span>, array(<span class="stringliteral">&#39;error&#39;</span> =&gt; $error, <span class="stringliteral">&#39;message&#39;</span> =&gt; $message))) {</div>
<div class="line"><a name="l01741"></a><span class="lineno"> 1741</span>&#160;    <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>(($message) ? $output_label . $message : $output_label . $error, <span class="stringliteral">&#39;error&#39;</span>, $error);</div>
<div class="line"><a name="l01742"></a><span class="lineno"> 1742</span>&#160;  }</div>
<div class="line"><a name="l01743"></a><span class="lineno"> 1743</span>&#160;</div>
<div class="line"><a name="l01744"></a><span class="lineno"> 1744</span>&#160;  <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l01745"></a><span class="lineno"> 1745</span>&#160;}</div>
<div class="line"><a name="l01746"></a><span class="lineno"> 1746</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01747"></a><span class="lineno"> 1747</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01748"></a><span class="lineno"> 1748</span>&#160;<span class="comment"> * Return the current error handling status</span></div>
<div class="line"><a name="l01749"></a><span class="lineno"> 1749</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01750"></a><span class="lineno"> 1750</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l01751"></a><span class="lineno"> 1751</span>&#160;<span class="comment"> *   The current aggregate error status</span></div>
<div class="line"><a name="l01752"></a><span class="lineno"> 1752</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01753"></a><span class="lineno"><a class="code" href="group__errorhandling.html#ga33fe8456b3dc49a0e28e7f63692a0d44"> 1753</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__errorhandling.html#ga33fe8456b3dc49a0e28e7f63692a0d44">drush_get_error</a>() {</div>
<div class="line"><a name="l01754"></a><span class="lineno"> 1754</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_ERROR_CODE&#39;</span>, <a class="code" href="drush_8inc.html#af1fd588cf6b6a3d51e8055408ee86635">DRUSH_SUCCESS</a>);</div>
<div class="line"><a name="l01755"></a><span class="lineno"> 1755</span>&#160;}</div>
<div class="line"><a name="l01756"></a><span class="lineno"> 1756</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01757"></a><span class="lineno"> 1757</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01758"></a><span class="lineno"> 1758</span>&#160;<span class="comment"> * Return the current list of errors that have occurred.</span></div>
<div class="line"><a name="l01759"></a><span class="lineno"> 1759</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01760"></a><span class="lineno"> 1760</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l01761"></a><span class="lineno"> 1761</span>&#160;<span class="comment"> *   An associative array of error messages indexed by the type of message.</span></div>
<div class="line"><a name="l01762"></a><span class="lineno"> 1762</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01763"></a><span class="lineno"><a class="code" href="group__errorhandling.html#gaf64f258413d1fed041c634581e39bff0"> 1763</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__errorhandling.html#gaf64f258413d1fed041c634581e39bff0">drush_get_error_log</a>() {</div>
<div class="line"><a name="l01764"></a><span class="lineno"> 1764</span>&#160;  <span class="keywordflow">return</span> <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_ERROR_LOG&#39;</span>, array());</div>
<div class="line"><a name="l01765"></a><span class="lineno"> 1765</span>&#160;}</div>
<div class="line"><a name="l01766"></a><span class="lineno"> 1766</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01767"></a><span class="lineno"> 1767</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01768"></a><span class="lineno"> 1768</span>&#160;<span class="comment"> * Check if a specific error status has been set.</span></div>
<div class="line"><a name="l01769"></a><span class="lineno"> 1769</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01770"></a><span class="lineno"> 1770</span>&#160;<span class="comment"> * @param error</span></div>
<div class="line"><a name="l01771"></a><span class="lineno"> 1771</span>&#160;<span class="comment"> *   A text string identifying the error that has occurred.</span></div>
<div class="line"><a name="l01772"></a><span class="lineno"> 1772</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l01773"></a><span class="lineno"> 1773</span>&#160;<span class="comment"> *   TRUE if the specified error has been set, FALSE if not</span></div>
<div class="line"><a name="l01774"></a><span class="lineno"> 1774</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01775"></a><span class="lineno"><a class="code" href="group__errorhandling.html#gafaa8004ee101cc91df57fae59e5d8956"> 1775</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__errorhandling.html#gafaa8004ee101cc91df57fae59e5d8956">drush_cmp_error</a>($error) {</div>
<div class="line"><a name="l01776"></a><span class="lineno"> 1776</span>&#160;  $error_log = <a class="code" href="group__errorhandling.html#gaf64f258413d1fed041c634581e39bff0">drush_get_error_log</a>();</div>
<div class="line"><a name="l01777"></a><span class="lineno"> 1777</span>&#160;</div>
<div class="line"><a name="l01778"></a><span class="lineno"> 1778</span>&#160;  <span class="keywordflow">if</span> (is_numeric($error)) {</div>
<div class="line"><a name="l01779"></a><span class="lineno"> 1779</span>&#160;    $error = <span class="stringliteral">&#39;DRUSH_FRAMEWORK_ERROR&#39;</span>;</div>
<div class="line"><a name="l01780"></a><span class="lineno"> 1780</span>&#160;  }</div>
<div class="line"><a name="l01781"></a><span class="lineno"> 1781</span>&#160;</div>
<div class="line"><a name="l01782"></a><span class="lineno"> 1782</span>&#160;  <span class="keywordflow">return</span> array_key_exists($error, $error_log);</div>
<div class="line"><a name="l01783"></a><span class="lineno"> 1783</span>&#160;}</div>
<div class="line"><a name="l01784"></a><span class="lineno"> 1784</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01785"></a><span class="lineno"> 1785</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01786"></a><span class="lineno"> 1786</span>&#160;<span class="comment"> * Clear error context.</span></div>
<div class="line"><a name="l01787"></a><span class="lineno"> 1787</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01788"></a><span class="lineno"><a class="code" href="group__errorhandling.html#ga7bc0a52d28467940b2bb9588a660ed8f"> 1788</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__errorhandling.html#ga7bc0a52d28467940b2bb9588a660ed8f">drush_clear_error</a>() {</div>
<div class="line"><a name="l01789"></a><span class="lineno"> 1789</span>&#160;  <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>(<span class="stringliteral">&#39;DRUSH_ERROR_CODE&#39;</span>, <a class="code" href="drush_8inc.html#af1fd588cf6b6a3d51e8055408ee86635">DRUSH_SUCCESS</a>);</div>
<div class="line"><a name="l01790"></a><span class="lineno"> 1790</span>&#160;}</div>
<div class="line"><a name="l01791"></a><span class="lineno"> 1791</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01792"></a><span class="lineno"> 1792</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01793"></a><span class="lineno"> 1793</span>&#160;<span class="comment"> * Exit due to user declining a confirmation prompt.</span></div>
<div class="line"><a name="l01794"></a><span class="lineno"> 1794</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01795"></a><span class="lineno"> 1795</span>&#160;<span class="comment"> * Usage:  return drush_user_abort();</span></div>
<div class="line"><a name="l01796"></a><span class="lineno"> 1796</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01797"></a><span class="lineno"><a class="code" href="group__errorhandling.html#ga366aaafdf8c774a58653c64a65b6d91c"> 1797</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__errorhandling.html#ga366aaafdf8c774a58653c64a65b6d91c">drush_user_abort</a>($msg = NULL) {</div>
<div class="line"><a name="l01798"></a><span class="lineno"> 1798</span>&#160;  <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>(<span class="stringliteral">&#39;DRUSH_USER_ABORT&#39;</span>, TRUE);</div>
<div class="line"><a name="l01799"></a><span class="lineno"> 1799</span>&#160;  <a class="code" href="group__logging.html#gad820f489a93518301794ada4ff7816b6">drush_log</a>($msg ? $msg : <a class="code" href="group__outputfunctions.html#ga1218abcb1e27dd3bb412113d1e344d96">dt</a>(<span class="stringliteral">&#39;Aborting.&#39;</span>), <span class="stringliteral">&#39;cancel&#39;</span>);</div>
<div class="line"><a name="l01800"></a><span class="lineno"> 1800</span>&#160;  <span class="keywordflow">return</span> FALSE;</div>
<div class="line"><a name="l01801"></a><span class="lineno"> 1801</span>&#160;}</div>
<div class="line"><a name="l01802"></a><span class="lineno"> 1802</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01803"></a><span class="lineno"> 1803</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01804"></a><span class="lineno"> 1804</span>&#160;<span class="comment"> * Turn PHP error handling off.</span></div>
<div class="line"><a name="l01805"></a><span class="lineno"> 1805</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01806"></a><span class="lineno"> 1806</span>&#160;<span class="comment"> * This is commonly used while bootstrapping Drupal for install</span></div>
<div class="line"><a name="l01807"></a><span class="lineno"> 1807</span>&#160;<span class="comment"> * or updates.</span></div>
<div class="line"><a name="l01808"></a><span class="lineno"> 1808</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01809"></a><span class="lineno"> 1809</span>&#160;<span class="comment"> * This also records the previous error_reporting setting, in</span></div>
<div class="line"><a name="l01810"></a><span class="lineno"> 1810</span>&#160;<span class="comment"> * case it wasn&#39;t recorded previously.</span></div>
<div class="line"><a name="l01811"></a><span class="lineno"> 1811</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01812"></a><span class="lineno"> 1812</span>&#160;<span class="comment"> * @see drush_errors_off()</span></div>
<div class="line"><a name="l01813"></a><span class="lineno"> 1813</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01814"></a><span class="lineno"><a class="code" href="group__errorhandling.html#ga4d3fc14a9eef57a06ac4bab523744462"> 1814</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__errorhandling.html#ga4d3fc14a9eef57a06ac4bab523744462">drush_errors_off</a>() {</div>
<div class="line"><a name="l01815"></a><span class="lineno"> 1815</span>&#160;  <a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_ERROR_REPORTING&#39;</span>, error_reporting(0));</div>
<div class="line"><a name="l01816"></a><span class="lineno"> 1816</span>&#160;  ini_set(<span class="stringliteral">&#39;display_errors&#39;</span>, FALSE);</div>
<div class="line"><a name="l01817"></a><span class="lineno"> 1817</span>&#160;}</div>
<div class="line"><a name="l01818"></a><span class="lineno"> 1818</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01819"></a><span class="lineno"> 1819</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01820"></a><span class="lineno"> 1820</span>&#160;<span class="comment"> * Turn PHP error handling on.</span></div>
<div class="line"><a name="l01821"></a><span class="lineno"> 1821</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01822"></a><span class="lineno"> 1822</span>&#160;<span class="comment"> * We default to error_reporting() here just in</span></div>
<div class="line"><a name="l01823"></a><span class="lineno"> 1823</span>&#160;<span class="comment"> * case drush_errors_on() is called before drush_errors_off() and</span></div>
<div class="line"><a name="l01824"></a><span class="lineno"> 1824</span>&#160;<span class="comment"> * the context is not yet set.</span></div>
<div class="line"><a name="l01825"></a><span class="lineno"> 1825</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01826"></a><span class="lineno"> 1826</span>&#160;<span class="comment"> * @arg $errors string</span></div>
<div class="line"><a name="l01827"></a><span class="lineno"> 1827</span>&#160;<span class="comment"> *   The default error level to set in drush. This error level will be</span></div>
<div class="line"><a name="l01828"></a><span class="lineno"> 1828</span>&#160;<span class="comment"> *   carried through further drush_errors_on()/off() calls even if not</span></div>
<div class="line"><a name="l01829"></a><span class="lineno"> 1829</span>&#160;<span class="comment"> *   provided in later calls.</span></div>
<div class="line"><a name="l01830"></a><span class="lineno"> 1830</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01831"></a><span class="lineno"> 1831</span>&#160;<span class="comment"> * @see error_reporting()</span></div>
<div class="line"><a name="l01832"></a><span class="lineno"> 1832</span>&#160;<span class="comment"> * @see drush_errors_off()</span></div>
<div class="line"><a name="l01833"></a><span class="lineno"> 1833</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01834"></a><span class="lineno"><a class="code" href="group__errorhandling.html#ga303bcdf8b73c31b19ba4de4f2f6ef41b"> 1834</a></span>&#160;<span class="keyword">function</span> <a class="code" href="group__errorhandling.html#ga303bcdf8b73c31b19ba4de4f2f6ef41b">drush_errors_on</a>($errors = null) {</div>
<div class="line"><a name="l01835"></a><span class="lineno"> 1835</span>&#160;  <span class="keywordflow">if</span> (!isset($errors)) {</div>
<div class="line"><a name="l01836"></a><span class="lineno"> 1836</span>&#160;    $errors = error_reporting();</div>
<div class="line"><a name="l01837"></a><span class="lineno"> 1837</span>&#160;  }</div>
<div class="line"><a name="l01838"></a><span class="lineno"> 1838</span>&#160;  <span class="keywordflow">else</span> {</div>
<div class="line"><a name="l01839"></a><span class="lineno"> 1839</span>&#160;    <a class="code" href="context_8inc.html#af983acfe90e7d7bbdbd67c57f93708ba">drush_set_context</a>(<span class="stringliteral">&#39;DRUSH_ERROR_REPORTING&#39;</span>, $errors);</div>
<div class="line"><a name="l01840"></a><span class="lineno"> 1840</span>&#160;  }</div>
<div class="line"><a name="l01841"></a><span class="lineno"> 1841</span>&#160;  error_reporting(<a class="code" href="context_8inc.html#ad25559f8d7d753f636fbeac347c29fc5">drush_get_context</a>(<span class="stringliteral">&#39;DRUSH_ERROR_REPORTING&#39;</span>, $errors));</div>
<div class="line"><a name="l01842"></a><span class="lineno"> 1842</span>&#160;  ini_set(<span class="stringliteral">&#39;display_errors&#39;</span>, TRUE);</div>
<div class="line"><a name="l01843"></a><span class="lineno"> 1843</span>&#160;}</div>
<div class="line"><a name="l01844"></a><span class="lineno"> 1844</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01845"></a><span class="lineno"> 1845</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01846"></a><span class="lineno"> 1846</span>&#160;<span class="comment"> * @} End of &quot;defgroup errorhandling&quot;.</span></div>
<div class="line"><a name="l01847"></a><span class="lineno"> 1847</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01848"></a><span class="lineno"> 1848</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01849"></a><span class="lineno"> 1849</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01850"></a><span class="lineno"> 1850</span>&#160;<span class="comment"> * Get the PHP memory_limit value in bytes.</span></div>
<div class="line"><a name="l01851"></a><span class="lineno"> 1851</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01852"></a><span class="lineno"><a class="code" href="drush_8inc.html#a78afaf6bac26a5964c39db973deb0783"> 1852</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a78afaf6bac26a5964c39db973deb0783">drush_memory_limit</a>() {</div>
<div class="line"><a name="l01853"></a><span class="lineno"> 1853</span>&#160;  $value = trim(ini_get(<span class="stringliteral">&#39;memory_limit&#39;</span>));</div>
<div class="line"><a name="l01854"></a><span class="lineno"> 1854</span>&#160;  $last = strtolower($value[strlen($value)-1]);</div>
<div class="line"><a name="l01855"></a><span class="lineno"> 1855</span>&#160;  <span class="keywordflow">switch</span> ($last) {</div>
<div class="line"><a name="l01856"></a><span class="lineno"> 1856</span>&#160;    <span class="keywordflow">case</span> <span class="charliteral">&#39;g&#39;</span>:</div>
<div class="line"><a name="l01857"></a><span class="lineno"> 1857</span>&#160;      $value *= <a class="code" href="drush_8inc.html#a0a75d4291b848dda33fab74050e0ab14">DRUSH_KILOBYTE</a>;</div>
<div class="line"><a name="l01858"></a><span class="lineno"> 1858</span>&#160;    <span class="keywordflow">case</span> <span class="charliteral">&#39;m&#39;</span>:</div>
<div class="line"><a name="l01859"></a><span class="lineno"> 1859</span>&#160;      $value *= <a class="code" href="drush_8inc.html#a0a75d4291b848dda33fab74050e0ab14">DRUSH_KILOBYTE</a>;</div>
<div class="line"><a name="l01860"></a><span class="lineno"> 1860</span>&#160;    <span class="keywordflow">case</span> <span class="charliteral">&#39;k&#39;</span>:</div>
<div class="line"><a name="l01861"></a><span class="lineno"> 1861</span>&#160;      $value *= <a class="code" href="drush_8inc.html#a0a75d4291b848dda33fab74050e0ab14">DRUSH_KILOBYTE</a>;</div>
<div class="line"><a name="l01862"></a><span class="lineno"> 1862</span>&#160;  }</div>
<div class="line"><a name="l01863"></a><span class="lineno"> 1863</span>&#160;</div>
<div class="line"><a name="l01864"></a><span class="lineno"> 1864</span>&#160;  <span class="keywordflow">return</span> $value;</div>
<div class="line"><a name="l01865"></a><span class="lineno"> 1865</span>&#160;}</div>
<div class="line"><a name="l01866"></a><span class="lineno"> 1866</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01867"></a><span class="lineno"> 1867</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01868"></a><span class="lineno"> 1868</span>&#160;<span class="comment"> * Unset the named key anywhere in the provided</span></div>
<div class="line"><a name="l01869"></a><span class="lineno"> 1869</span>&#160;<span class="comment"> * data structure.</span></div>
<div class="line"><a name="l01870"></a><span class="lineno"> 1870</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01871"></a><span class="lineno"><a class="code" href="drush_8inc.html#a168e5c4e0711c44cf1c54ea8c4ff2c75"> 1871</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a168e5c4e0711c44cf1c54ea8c4ff2c75">drush_unset_recursive</a>(&amp;$data, $unset_key) {</div>
<div class="line"><a name="l01872"></a><span class="lineno"> 1872</span>&#160;  <span class="keywordflow">if</span> (!empty($data) &amp;&amp; is_array($data)) {</div>
<div class="line"><a name="l01873"></a><span class="lineno"> 1873</span>&#160;    unset($data[$unset_key]);</div>
<div class="line"><a name="l01874"></a><span class="lineno"> 1874</span>&#160;    <span class="keywordflow">foreach</span> ($data as $key =&gt; $value) {</div>
<div class="line"><a name="l01875"></a><span class="lineno"> 1875</span>&#160;      <span class="keywordflow">if</span> (is_array($value)) {</div>
<div class="line"><a name="l01876"></a><span class="lineno"> 1876</span>&#160;        <a class="code" href="drush_8inc.html#a168e5c4e0711c44cf1c54ea8c4ff2c75">drush_unset_recursive</a>($data[$key], $unset_key);</div>
<div class="line"><a name="l01877"></a><span class="lineno"> 1877</span>&#160;      }</div>
<div class="line"><a name="l01878"></a><span class="lineno"> 1878</span>&#160;    }</div>
<div class="line"><a name="l01879"></a><span class="lineno"> 1879</span>&#160;  }</div>
<div class="line"><a name="l01880"></a><span class="lineno"> 1880</span>&#160;}</div>
<div class="line"><a name="l01881"></a><span class="lineno"> 1881</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01882"></a><span class="lineno"> 1882</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01883"></a><span class="lineno"> 1883</span>&#160;<span class="comment"> * Return a list of VCSs reserved files and directories.</span></div>
<div class="line"><a name="l01884"></a><span class="lineno"> 1884</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01885"></a><span class="lineno"><a class="code" href="drush_8inc.html#aa61cd59315f7a89a8c7df8649f480a31"> 1885</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#aa61cd59315f7a89a8c7df8649f480a31">drush_version_control_reserved_files</a>() {</div>
<div class="line"><a name="l01886"></a><span class="lineno"> 1886</span>&#160;  <span class="keyword">static</span> $files = FALSE;</div>
<div class="line"><a name="l01887"></a><span class="lineno"> 1887</span>&#160;</div>
<div class="line"><a name="l01888"></a><span class="lineno"> 1888</span>&#160;  <span class="keywordflow">if</span> (!$files) {</div>
<div class="line"><a name="l01889"></a><span class="lineno"> 1889</span>&#160;    <span class="comment">// Also support VCSs that are not drush vc engines.</span></div>
<div class="line"><a name="l01890"></a><span class="lineno"> 1890</span>&#160;    $files = array(<span class="stringliteral">&#39;.git&#39;</span>, <span class="stringliteral">&#39;.gitignore&#39;</span>, <span class="stringliteral">&#39;.hg&#39;</span>, <span class="stringliteral">&#39;.hgignore&#39;</span>, <span class="stringliteral">&#39;.hgrags&#39;</span>);</div>
<div class="line"><a name="l01891"></a><span class="lineno"> 1891</span>&#160;    $engine_info = <a class="code" href="engines_8inc.html#ae94a82d80d5e90cb126de1f16a7f8fe4">drush_get_engines</a>(<span class="stringliteral">&#39;version_control&#39;</span>);</div>
<div class="line"><a name="l01892"></a><span class="lineno"> 1892</span>&#160;    $vcs = array_keys($engine_info[<span class="stringliteral">&#39;engines&#39;</span>]);</div>
<div class="line"><a name="l01893"></a><span class="lineno"> 1893</span>&#160;    <span class="keywordflow">foreach</span> ($vcs as $name) {</div>
<div class="line"><a name="l01894"></a><span class="lineno"> 1894</span>&#160;      $version_control = <a class="code" href="engines_8inc.html#a91df31f18b0a1d05540ccaf85e6d9a88">drush_include_engine</a>(<span class="stringliteral">&#39;version_control&#39;</span>, $name);</div>
<div class="line"><a name="l01895"></a><span class="lineno"> 1895</span>&#160;      $files = array_merge($files, $version_control-&gt;reserved_files());</div>
<div class="line"><a name="l01896"></a><span class="lineno"> 1896</span>&#160;    }</div>
<div class="line"><a name="l01897"></a><span class="lineno"> 1897</span>&#160;  }</div>
<div class="line"><a name="l01898"></a><span class="lineno"> 1898</span>&#160;</div>
<div class="line"><a name="l01899"></a><span class="lineno"> 1899</span>&#160;  <span class="keywordflow">return</span> $files;</div>
<div class="line"><a name="l01900"></a><span class="lineno"> 1900</span>&#160;}</div>
<div class="line"><a name="l01901"></a><span class="lineno"> 1901</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01902"></a><span class="lineno"> 1902</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01903"></a><span class="lineno"> 1903</span>&#160;<span class="comment"> * Generate a random alphanumeric password.  Copied from user.module.</span></div>
<div class="line"><a name="l01904"></a><span class="lineno"> 1904</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01905"></a><span class="lineno"><a class="code" href="drush_8inc.html#a5684e71a8f8639ee7805a502c6e0cfc4"> 1905</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a5684e71a8f8639ee7805a502c6e0cfc4">drush_generate_password</a>($length = 10) {</div>
<div class="line"><a name="l01906"></a><span class="lineno"> 1906</span>&#160;  <span class="comment">// This variable contains the list of allowable characters for the</span></div>
<div class="line"><a name="l01907"></a><span class="lineno"> 1907</span>&#160;  <span class="comment">// password. Note that the number 0 and the letter &#39;O&#39; have been</span></div>
<div class="line"><a name="l01908"></a><span class="lineno"> 1908</span>&#160;  <span class="comment">// removed to avoid confusion between the two. The same is true</span></div>
<div class="line"><a name="l01909"></a><span class="lineno"> 1909</span>&#160;  <span class="comment">// of &#39;I&#39;, 1, and &#39;l&#39;.</span></div>
<div class="line"><a name="l01910"></a><span class="lineno"> 1910</span>&#160;  $allowable_characters = <span class="stringliteral">&#39;abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789&#39;</span>;</div>
<div class="line"><a name="l01911"></a><span class="lineno"> 1911</span>&#160;</div>
<div class="line"><a name="l01912"></a><span class="lineno"> 1912</span>&#160;  <span class="comment">// Zero-based count of characters in the allowable list:</span></div>
<div class="line"><a name="l01913"></a><span class="lineno"> 1913</span>&#160;  $len = strlen($allowable_characters) - 1;</div>
<div class="line"><a name="l01914"></a><span class="lineno"> 1914</span>&#160;</div>
<div class="line"><a name="l01915"></a><span class="lineno"> 1915</span>&#160;  <span class="comment">// Declare the password as a blank string.</span></div>
<div class="line"><a name="l01916"></a><span class="lineno"> 1916</span>&#160;  $pass = <span class="stringliteral">&#39;&#39;</span>;</div>
<div class="line"><a name="l01917"></a><span class="lineno"> 1917</span>&#160;</div>
<div class="line"><a name="l01918"></a><span class="lineno"> 1918</span>&#160;  <span class="comment">// Loop the number of times specified by $length.</span></div>
<div class="line"><a name="l01919"></a><span class="lineno"> 1919</span>&#160;  <span class="keywordflow">for</span> ($i = 0; $i &lt; $length; $i++) {</div>
<div class="line"><a name="l01920"></a><span class="lineno"> 1920</span>&#160;</div>
<div class="line"><a name="l01921"></a><span class="lineno"> 1921</span>&#160;    <span class="comment">// Each iteration, pick a random character from the</span></div>
<div class="line"><a name="l01922"></a><span class="lineno"> 1922</span>&#160;    <span class="comment">// allowable string and append it to the password:</span></div>
<div class="line"><a name="l01923"></a><span class="lineno"> 1923</span>&#160;    $pass .= $allowable_characters[mt_rand(0, $len)];</div>
<div class="line"><a name="l01924"></a><span class="lineno"> 1924</span>&#160;  }</div>
<div class="line"><a name="l01925"></a><span class="lineno"> 1925</span>&#160;</div>
<div class="line"><a name="l01926"></a><span class="lineno"> 1926</span>&#160;  <span class="keywordflow">return</span> $pass;</div>
<div class="line"><a name="l01927"></a><span class="lineno"> 1927</span>&#160;}</div>
<div class="line"><a name="l01928"></a><span class="lineno"> 1928</span>&#160;<span class="comment"></span></div>
<div class="line"><a name="l01929"></a><span class="lineno"> 1929</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01930"></a><span class="lineno"> 1930</span>&#160;<span class="comment"> * Form an associative array from a linear array.</span></div>
<div class="line"><a name="l01931"></a><span class="lineno"> 1931</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01932"></a><span class="lineno"> 1932</span>&#160;<span class="comment"> * This function walks through the provided array and constructs an associative</span></div>
<div class="line"><a name="l01933"></a><span class="lineno"> 1933</span>&#160;<span class="comment"> * array out of it. The keys of the resulting array will be the values of the</span></div>
<div class="line"><a name="l01934"></a><span class="lineno"> 1934</span>&#160;<span class="comment"> * input array. The values will be the same as the keys unless a function is</span></div>
<div class="line"><a name="l01935"></a><span class="lineno"> 1935</span>&#160;<span class="comment"> * specified, in which case the output of the function is used for the values</span></div>
<div class="line"><a name="l01936"></a><span class="lineno"> 1936</span>&#160;<span class="comment"> * instead.</span></div>
<div class="line"><a name="l01937"></a><span class="lineno"> 1937</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01938"></a><span class="lineno"> 1938</span>&#160;<span class="comment"> * @param $array</span></div>
<div class="line"><a name="l01939"></a><span class="lineno"> 1939</span>&#160;<span class="comment"> *   A linear array.</span></div>
<div class="line"><a name="l01940"></a><span class="lineno"> 1940</span>&#160;<span class="comment"> * @param $function</span></div>
<div class="line"><a name="l01941"></a><span class="lineno"> 1941</span>&#160;<span class="comment"> *   A name of a function to apply to all values before output.</span></div>
<div class="line"><a name="l01942"></a><span class="lineno"> 1942</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01943"></a><span class="lineno"> 1943</span>&#160;<span class="comment"> * @return</span></div>
<div class="line"><a name="l01944"></a><span class="lineno"> 1944</span>&#160;<span class="comment"> *   An associative array.</span></div>
<div class="line"><a name="l01945"></a><span class="lineno"> 1945</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01946"></a><span class="lineno"><a class="code" href="drush_8inc.html#ad847f03f1d1c046f9eb472aafa56137c"> 1946</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#ad847f03f1d1c046f9eb472aafa56137c">drush_map_assoc</a>($array, $function = NULL) {</div>
<div class="line"><a name="l01947"></a><span class="lineno"> 1947</span>&#160;  <span class="comment">// array_combine() fails with empty arrays:</span></div>
<div class="line"><a name="l01948"></a><span class="lineno"> 1948</span>&#160;  <span class="comment">// http://bugs.php.net/bug.php?id=34857.</span></div>
<div class="line"><a name="l01949"></a><span class="lineno"> 1949</span>&#160;  $array = !empty($array) ? array_combine($array, $array) : array();</div>
<div class="line"><a name="l01950"></a><span class="lineno"> 1950</span>&#160;  <span class="keywordflow">if</span> (is_callable($function)) {</div>
<div class="line"><a name="l01951"></a><span class="lineno"> 1951</span>&#160;    $array = array_map($function, $array);</div>
<div class="line"><a name="l01952"></a><span class="lineno"> 1952</span>&#160;  }</div>
<div class="line"><a name="l01953"></a><span class="lineno"> 1953</span>&#160;  <span class="keywordflow">return</span> $array;</div>
<div class="line"><a name="l01954"></a><span class="lineno"> 1954</span>&#160;}<span class="comment"></span></div>
<div class="line"><a name="l01955"></a><span class="lineno"> 1955</span>&#160;<span class="comment">/**</span></div>
<div class="line"><a name="l01956"></a><span class="lineno"> 1956</span>&#160;<span class="comment"> * Clears completion caches.</span></div>
<div class="line"><a name="l01957"></a><span class="lineno"> 1957</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01958"></a><span class="lineno"> 1958</span>&#160;<span class="comment"> * If called with no parameters the entire complete cache will be cleared.</span></div>
<div class="line"><a name="l01959"></a><span class="lineno"> 1959</span>&#160;<span class="comment"> * If called with just the $type parameter the global cache for that type will</span></div>
<div class="line"><a name="l01960"></a><span class="lineno"> 1960</span>&#160;<span class="comment"> * be cleared (in the site context, if any). If called with both $type and</span></div>
<div class="line"><a name="l01961"></a><span class="lineno"> 1961</span>&#160;<span class="comment"> * $command parameters the command cache of that type will be cleared  (in the</span></div>
<div class="line"><a name="l01962"></a><span class="lineno"> 1962</span>&#160;<span class="comment"> * site context, if any).</span></div>
<div class="line"><a name="l01963"></a><span class="lineno"> 1963</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01964"></a><span class="lineno"> 1964</span>&#160;<span class="comment"> * This is included in drush.inc as complete.inc is only loaded conditionally.</span></div>
<div class="line"><a name="l01965"></a><span class="lineno"> 1965</span>&#160;<span class="comment"> *</span></div>
<div class="line"><a name="l01966"></a><span class="lineno"> 1966</span>&#160;<span class="comment"> * @param $type</span></div>
<div class="line"><a name="l01967"></a><span class="lineno"> 1967</span>&#160;<span class="comment"> *   The completion type (optional).</span></div>
<div class="line"><a name="l01968"></a><span class="lineno"> 1968</span>&#160;<span class="comment"> * @param $command</span></div>
<div class="line"><a name="l01969"></a><span class="lineno"> 1969</span>&#160;<span class="comment"> *   The command name (optional), if command specific cache is to be cleared.</span></div>
<div class="line"><a name="l01970"></a><span class="lineno"> 1970</span>&#160;<span class="comment"> *   If specifying a command, $type is not optional.</span></div>
<div class="line"><a name="l01971"></a><span class="lineno"> 1971</span>&#160;<span class="comment"> */</span></div>
<div class="line"><a name="l01972"></a><span class="lineno"><a class="code" href="drush_8inc.html#a12acbc64b339bdd1b32371725edb2dcf"> 1972</a></span>&#160;<span class="keyword">function</span> <a class="code" href="drush_8inc.html#a12acbc64b339bdd1b32371725edb2dcf">drush_complete_cache_clear</a>($type = NULL, $command = NULL) {</div>
<div class="line"><a name="l01973"></a><span class="lineno"> 1973</span>&#160;  require_once DRUSH_BASE_PATH . <span class="stringliteral">&#39;/includes/complete.inc&#39;</span>;</div>
<div class="line"><a name="l01974"></a><span class="lineno"> 1974</span>&#160;  <span class="keywordflow">if</span> ($type) {</div>
<div class="line"><a name="l01975"></a><span class="lineno"> 1975</span>&#160;    <a class="code" href="includes_2cache_8inc.html#a320b19400992c01f88bd71db140da5bc">drush_cache_clear_all</a>(<a class="code" href="complete_8inc.html#a5cacfdc5ec07fac0d484c64c7368c511">drush_complete_cache_cid</a>($type, $command), <span class="stringliteral">&#39;complete&#39;</span>);</div>
<div class="line"><a name="l01976"></a><span class="lineno"> 1976</span>&#160;    <span class="keywordflow">return</span>;</div>
<div class="line"><a name="l01977"></a><span class="lineno"> 1977</span>&#160;  }</div>
<div class="line"><a name="l01978"></a><span class="lineno"> 1978</span>&#160;  <span class="comment">// No type or command, so clear the entire complete cache.</span></div>
<div class="line"><a name="l01979"></a><span class="lineno"> 1979</span>&#160;  <a class="code" href="includes_2cache_8inc.html#a320b19400992c01f88bd71db140da5bc">drush_cache_clear_all</a>(<span class="charliteral">&#39;*&#39;</span>, <span class="stringliteral">&#39;complete&#39;</span>, TRUE);</div>
<div class="line"><a name="l01980"></a><span class="lineno"> 1980</span>&#160;}</div>
</div><!-- fragment --></div><!-- contents -->
<!-- start footer part -->
<hr class="footer"/><address class="footer"><small>
Generated on Wed Oct 8 2014 09:04:54 for Drush by &#160;<a href="http://www.doxygen.org/index.html">
<img class="footer" src="doxygen.png" alt="doxygen"/>
</a> 1.8.1.2
</small></address>
</body>
</html>