a656dc17dfe450eb00b05e2b0f0782bae00502a5
[yaffs-website] / vendor / drush / drush / includes / command.inc
1 <?php
2
3 use Consolidation\AnnotatedCommand\AnnotatedCommand;
4 use Drush\Drush;
5 use Drush\Log\LogLevel;
6 use Webmozart\PathUtil\Path;
7 use Consolidation\AnnotatedCommand\AnnotationData;
8 use Drush\Command\DrushInputAdapter;
9 use Drush\SiteAlias\AliasRecord;
10 use Consolidation\AnnotatedCommand\CommandData;
11 use Symfony\Component\Console\Output\ConsoleOutput;
12
13 /**
14  * @defgroup dispatching Command dispatching functions.
15  * @{
16  *
17  * These functions handle command dispatching, and can
18  * be used to programmatically invoke Drush commands in
19  * different ways.
20  */
21
22 /**
23  * Invoke a command in a new process, targeting the site specified by
24  * the provided site alias record.
25  *
26  * @param array|string $site_alias_record
27  *  The site record to execute the command on.  Use '@self' to run on the current site.
28  * @param string $command_name
29  *  The command to invoke.
30  * @param array $commandline_args
31  *  The arguments to pass to the command.
32  * @param array $commandline_options
33  *  The options (e.g. --select) to provide to the command.
34  * @param mixed $backend_options
35  *   TRUE - integrate errors
36  *   FALSE - do not integrate errors
37  *   array - @see drush_backend_invoke_concurrent
38  *     There are also several options that _only_ work when set in
39  *     this parameter.  They include:
40  *      'invoke-multiple'
41  *        If $site_alias_record represents a single site, then 'invoke-multiple'
42  *        will cause the _same_ command with the _same_ arguments and options
43  *        to be invoked concurrently (e.g. for running concurrent batch processes).
44  *      'concurrency'
45  *        Limits the number of concurrent processes that will run at the same time.
46  *        Defaults to '4'.
47  *      'override-simulated'
48  *        Forces the command to run, even in 'simulated' mode. Useful for
49  *        commands that do not change any state on the machine, e.g. to fetch
50  *        database information for sql-sync via sql-conf.
51  *      'interactive'
52  *        Overrides the backend invoke process to run commands interactively.
53  *      'fork'
54  *        Overrides the backend invoke process to run non blocking commands in
55  *        the background. Forks a new process by adding a '&' at the end of the
56  *        command. The calling process does not receive any output from the child
57  *        process. The fork option is used to spawn a process that outlives its
58  *        parent.
59  *
60  * @return
61  *   If the command could not be completed successfully, FALSE.
62  *   If the command was completed, this will return an associative
63  *   array containing the results of the API call.
64  *   @see drush_backend_get_result()
65  *
66  * Do not change the signature of this function!  drush_invoke_process
67  * is one of the key Drush APIs.  See http://drupal.org/node/1152908
68  */
69 function drush_invoke_process($site_alias_record, $command_name, $commandline_args = [], $commandline_options = [], $backend_options = TRUE) {
70   if ($site_alias_record instanceof AliasRecord) {
71     $site_alias_record = $site_alias_record->legacyRecord();
72   }
73
74   $invocations[] = [
75     'site' => $site_alias_record,
76     'command' => $command_name,
77     'args' => $commandline_args
78   ];
79   $invoke_multiple = drush_get_option_override($backend_options, 'invoke-multiple', 0);
80   if ($invoke_multiple) {
81     $invocations = array_fill(0, $invoke_multiple, $invocations[0]);
82   }
83
84   return drush_backend_invoke_concurrent($invocations, $commandline_options, $backend_options);
85 }
86
87 /**
88  * Substrings to ignore during commandfile and site alias searching.
89  * TODO: Do we do any searching in the new code that should be filtered like this?
90  */
91 function drush_filename_blacklist() {
92   $blacklist = ['.', '..', 'drush_make', 'examples', 'tests', 'disabled', 'gitcache', 'cache'];
93   for ($v=4; $v<=(DRUSH_MAJOR_VERSION)+3; ++$v) {
94     if ($v != DRUSH_MAJOR_VERSION) {
95       $blacklist[] = 'drush' . $v;
96     }
97   }
98   $blacklist = array_merge($blacklist, drush_get_option_list('exclude'));
99   return $blacklist;
100 }