/** * Invoke the desired commands. * * @param array $commands * The commands to invoke. * * @return bool * FALSE if a command fails. */ private function execCommands(array $commands) { // Pass the drushrc file through to drush_invoke_process. $default_options = []; if ($config = drush_get_option('config-file')) { $default_options['config'] = $config; } foreach ($commands as $command => &$info) { $info = (array) $info; // Set some default values for each command. $info += ['alias' => '@self', 'arguments' => [], 'options' => []]; $info['options'] += $default_options; // Tell the user we are invoking the command. drush_print($this->formatHeading("✗") . ' ' . $this->formatCommand($command, $info)); // Invoke the command. if (!drush_invoke_process($info['alias'], $command, $info['arguments'], $info['options'])) { return drush_set_error('COMMAND_FAILED', dt("Failed to execute drush command @command.", ['@command' => $command])); } drush_print(); } }
/** * Covers the following target responsibilities. * - Insures that drush_invoke_process() called with fork backend set is able * to invoke a non-blocking process. */ function testBackendFork() { // Ensure that file that will be created by forked process does not exist // before invocation. $test_file = UNISH_SANDBOX . '/fork_test.txt'; if (file_exists($test_file)) { unlink($test_file); } // Sleep for a millisecond, then create the file $ev_php = "usleep(1000);fopen('{$test_file}','a');"; drush_invoke_process("@none", "ev", array($ev_php), array(), array("fork" => TRUE)); // Test file does not exist immediate after process forked $this->assertEquals(file_exists($test_file), FALSE); // Check every 100th of a second for up to 4 seconds to see if the file appeared $repetitions = 400; while (!file_exists($test_file) && $repetitions > 0) { usleep(10000); } // Assert that the file did finally appear $this->assertEquals(file_exists($test_file), TRUE); }
/** * Display a link to a given path or open link in a browser. * * @todo Document new @handle-remote-commands and @bootstrap annotations. * * @param string|null $path Path to open. If omitted, the site front page will be opened. * @option string $browser Specify a particular browser (defaults to operating system default). Use --no-browser to suppress opening a browser. * @todo conflicts with global option: @option integer $redirect-port The port that the web server is redirected to (e.g. when running within a Vagrant environment). * @usage drush browse * Open default web browser (if configured or detected) to the site front page. * @usage drush browse node/1 * Open web browser to the path node/1. * @usage drush @example.prod * Open a browser to the web site specified in a site alias. * @usage drush browse --browser=firefox admin * Open Firefox web browser to the path 'admin'. * @todo not used AFAIK @bootstrap DRUSH_BOOTSTRAP_NONE * @todo not used @handle-remote-commands true * @complete \Drush\CommandFiles\core\BrowseCommands::complete */ public function browse($path = '', $options = ['browser' => NULL]) { // Redispatch if called against a remote-host so a browser is started on the // the *local* machine. $alias = drush_get_context('DRUSH_TARGET_SITE_ALIAS'); if (drush_sitealias_is_remote_site($alias)) { $site_record = drush_sitealias_get_record($alias); $return = drush_invoke_process($site_record, 'browse', func_get_args(), drush_redispatch_get_options(), array('integrate' => TRUE)); if ($return['error_status']) { return drush_set_error('Unable to execute browse command on remote alias.'); } else { $link = $return['object']; } } else { if (!drush_bootstrap(DRUSH_BOOTSTRAP_DRUPAL_FULL)) { // Fail gracefully if unable to bootstrap Drupal. drush_bootstrap() has // already logged an error. return FALSE; } $link = drush_url($path, array('absolute' => TRUE)); } drush_start_browser($link); return $link; }
if (!drush_get_option('exec')) { echo "Usage: install.php --exec --project=<project_name> --site-alias=<site_alias>"; exit; } $config = (require_once 'install.config.inc'); $common_modules = $config['common']['modules']; if (($project_type = drush_get_option('project')) && $project_type) { $project_modules = isset($config[$project_type]['modules']) ? $config[$project_type]['modules'] : []; } if (!($site_alias = drush_get_option('site-alias'))) { $site_alias = '@self'; } //download common modules foreach ($common_modules as $module_cfg) { drush_invoke_process($site_alias, 'pm-download', $module_cfg['download'], ['yes' => TRUE]); } //enable modules foreach ($common_modules as $module_cfg) { drush_invoke_process($site_alias, 'pm-enable', $module_cfg['enable'], ['yes' => TRUE]); } foreach ($project_modules as $module_cfg) { drush_invoke_process($site_alias, 'pm-download', $module_cfg['download'], ['yes' => TRUE]); } foreach ($project_modules as $module_cfg) { if (!is_array($module_cfg['enable']) && $module_cfg['enable'] == 'none') { continue; } drush_invoke_process($site_alias, 'pm-enable', $module_cfg['enable'], ['yes' => TRUE]); } drush_invoke_process($site_alias, 'updb');
<?php $valuesUsingAlias = drush_invoke_process("@dev", "unit-return-argv", array(), array(), array("dispatch-using-alias" => TRUE)); $valuesWithoutAlias = drush_invoke_process("@dev", "unit-return-argv", array(), array(), array()); return array('with' => $valuesUsingAlias['object'], 'without' => $valuesWithoutAlias['object']);
/** * {@inheritdoc} */ protected function execute(InputInterface $input, OutputInterface $output) { $args = $input->getArguments(); $first = array_shift($args); // If the first argument is an alias, assign the next argument as the // command. if (strpos($first, '@') === 0) { $alias = $first; $command = array_shift($args); } else { $alias = '@self'; $command = $first; } $options = $input->getOptions(); // Force the 'backend' option to TRUE. $options['backend'] = TRUE; $return = drush_invoke_process($alias, $command, array_values($args), $options, ['interactive' => TRUE]); if ($return['error_status'] > 0) { foreach ($return['error_log'] as $error_type => $errors) { $output->write($errors); } // Add a newline after so the shell returns on a new line. $output->writeln(''); } else { $output->page(drush_backend_get_result()); } }