3 use Consolidation\AnnotatedCommand\AnnotatedCommand;
5 use Drush\Log\LogLevel;
6 use Webmozart\PathUtil\Path;
7 use Consolidation\AnnotatedCommand\AnnotationData;
8 use Drush\Command\DrushInputAdapter;
9 use Consolidation\SiteAlias\AliasRecord;
10 use Consolidation\AnnotatedCommand\CommandData;
11 use Symfony\Component\Console\Output\ConsoleOutput;
14 * @defgroup dispatching Command dispatching functions.
17 * These functions handle command dispatching, and can
18 * be used to programmatically invoke Drush commands in
23 * Invoke a command in a new process, targeting the site specified by
24 * the provided site alias record.
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:
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).
45 * Limits the number of concurrent processes that will run at the same time.
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.
52 * Overrides the backend invoke process to run commands interactively.
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
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()
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
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();
75 'site' => $site_alias_record,
76 'command' => $command_name,
77 'args' => $commandline_args
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]);
84 return drush_backend_invoke_concurrent($invocations, $commandline_options, $backend_options);
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?
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;
98 $blacklist = array_merge($blacklist, drush_get_option_list('exclude'));