public function ascii($string, $color = NULL, $style = NULL, $background = NULL) { if (drush_get_context('DRUSH_NOCOLOR')) { return $string; } return $this->color->color($color, $style, $background) . $string . $this->color->color('reset'); }
/** * Print druplicon as post-command output. * * @hook post-command * * @option druplicon Shows the druplicon as glorious ASCII art. * @todo hidden is not yet part of annotated-command project. It is recognized by Drush's annotation_adapter.inc * @hidden-option druplicon */ public function druplicon($result, CommandData $commandData) { // If one command does a drush_invoke to another command, // then this hook will be called multiple times. Only print // once. (n.b. If drush_invoke_process passes along the // --druplicon option, then we will still get mulitple output) if ($this->printed) { return; } $this->printed = true; $annotationData = $commandData->annotationData(); $commandName = $annotationData['command']; // For some reason, Drush help uses drush_invoke_process to call helpsingle if ($commandName == 'helpsingle') { return; } if ($commandData->input()->getOption('druplicon')) { $this->logger()->debug(dt('Displaying Druplicon for "!command" command.', array('!command' => $commandName))); $misc_dir = DRUSH_BASE_PATH . '/misc'; if (drush_get_context('DRUSH_NOCOLOR')) { $content = file_get_contents($misc_dir . '/druplicon-no_color.txt'); } else { $content = file_get_contents($misc_dir . '/druplicon-color.txt'); } // @todo: `$commandData->output->writeln($content)` after $output hooked up to backend invoke drush_print($content); } }
/** * Implements \SiteAudit\Check\Abstract\calculateScore(). */ public function calculateScore() { $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT'); $handle = opendir($drupal_root . '/sites/'); $this->registry['multisites'] = array(); while (FALSE !== ($entry = readdir($handle))) { if (!in_array($entry, array( '.', '..', 'default', 'all', 'example.sites.php', 'README.txt', '.svn', ))) { if (is_dir($drupal_root . '/sites/' . $entry)) { $this->registry['multisites'][] = $entry; } } } closedir($handle); if (!empty($this->registry['multisites'])) { if (drush_get_option('vendor') == 'pantheon') { return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL; } return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO; } return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS; }
function bootstrap_and_dispatch() { $phases = _drush_bootstrap_phases(FALSE, TRUE); $return = ''; $command_found = FALSE; _drush_bootstrap_output_prepare(); foreach ($phases as $phase) { if (drush_bootstrap_to_phase($phase)) { $command = drush_parse_command(); if (is_array($command)) { $bootstrap_result = drush_bootstrap_to_phase($command['bootstrap']); drush_enforce_requirement_bootstrap_phase($command); drush_enforce_requirement_core($command); drush_enforce_requirement_drupal_dependencies($command); drush_enforce_requirement_drush_dependencies($command); if ($bootstrap_result && empty($command['bootstrap_errors'])) { drush_log(dt("Found command: !command (commandfile=!commandfile)", array('!command' => $command['command'], '!commandfile' => $command['commandfile'])), 'bootstrap'); $command_found = TRUE; // Dispatch the command(s). $return = drush_dispatch($command); // Prevent a '1' at the end of the output. if ($return === TRUE) { $return = ''; } if (drush_get_context('DRUSH_DEBUG') && !drush_get_context('DRUSH_QUIET')) { // @todo Create version independant wrapper around Drupal timers. Use it. drush_print_timers(); } break; } } } else { break; } } if (!$command_found) { // If we reach this point, command doesn't fit requirements or we have not // found either a valid or matching command. // If no command was found check if it belongs to a disabled module. if (!$command) { $command = drush_command_belongs_to_disabled_module(); } // Set errors related to this command. $args = implode(' ', drush_get_arguments()); if (isset($command) && is_array($command)) { foreach ($command['bootstrap_errors'] as $key => $error) { drush_set_error($key, $error); } drush_set_error('DRUSH_COMMAND_NOT_EXECUTABLE', dt("The drush command '!args' could not be executed.", array('!args' => $args))); } elseif (!empty($args)) { drush_set_error('DRUSH_COMMAND_NOT_FOUND', dt("The drush command '!args' could not be found. Run `drush cache-clear drush` to clear the commandfile cache if you have installed new extensions.", array('!args' => $args))); } // Set errors that occurred in the bootstrap phases. $errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', array()); foreach ($errors as $code => $message) { drush_set_error($code, $message); } } return $return; }
/** * Implements \SiteAudit\Check\Abstract\calculateScore(). */ public function calculateScore() { $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT'); $handle = opendir($drupal_root . '/sites/'); $this->registry['superfluous'] = array(); while (FALSE !== ($entry = readdir($handle))) { if (!in_array($entry, array( '.', '..', 'default', 'all', 'example.sites.php', 'README.txt', ))) { if (is_file($drupal_root . '/sites/' . $entry)) { // Support multi-site directory aliasing for non-Pantheon sites. if ($entry != 'sites.php' || drush_get_option('vendor') == 'pantheon') { $this->registry['superfluous'][] = $entry; } } } } closedir($handle); if (!empty($this->registry['superfluous'])) { return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN; } return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS; }
function bootstrap_and_dispatch() { $phases = $this->bootstrap_init_phases(); $return = ''; $command_found = FALSE; _drush_bootstrap_output_prepare(); foreach ($phases as $phase) { if (drush_bootstrap_to_phase($phase)) { $command = drush_parse_command(); if (is_array($command)) { $command += $this->command_defaults(); // Insure that we have bootstrapped to a high enough // phase for the command prior to enforcing requirements. $bootstrap_result = drush_bootstrap_to_phase($command['bootstrap']); $this->enforce_requirement($command); if ($bootstrap_result && empty($command['bootstrap_errors'])) { $this->logger->log(LogLevel::BOOTSTRAP, dt("Found command: !command (commandfile=!commandfile)", array('!command' => $command['command'], '!commandfile' => $command['commandfile']))); $command_found = TRUE; // Dispatch the command(s). $return = drush_dispatch($command); if (drush_get_context('DRUSH_DEBUG') && !drush_get_context('DRUSH_QUIET')) { // @todo Create version independant wrapper around Drupal timers. Use it. drush_print_timers(); } break; } } } else { break; } } // TODO: If we could not find a legacy Drush command, try running a // command via the Symfony application. See also drush_main() in preflight.inc; // ultimately, the Symfony application should be called from there. if (!$command_found && isset($command)) { $container = \Drush::getContainer(); $application = $container->get('application'); $args = drush_get_arguments(); if (count($args)) { $name = $args[0]; if ($this->hasRegisteredSymfonyCommand($application, $name)) { $command_found = true; $input = drush_symfony_input(); $this->logger->log(LogLevel::BOOTSTRAP, dt("Dispatching with Symfony application as a fallback, since no native Drush command was found. (Set DRUSH_SYMFONY environment variable to skip Drush dispatch.)")); $application->run($input); } } } if (!$command_found) { // If we reach this point, command doesn't fit requirements or we have not // found either a valid or matching command. $this->report_command_error($command); } // Prevent a '1' at the end of the output. if ($return === TRUE) { $return = ''; } return $return; }
function setUp() { // Bootstrap to ensure the Console_Table library is present and included. drush_bootstrap(DRUSH_BOOTSTRAP_DRUSH); $this->original_columns = drush_get_context('DRUSH_COLUMNS'); // Some table data we reuse between tests. $this->numbers = array(array('1', '12', '123'), array('1234', '12345', '123456'), array('1234567', '12345678', '123456789')); $this->words = array(array('Drush is a command line shell', 'scripting interface', 'for Drupal'), array('A veritable', 'Swiss Army knife', 'designed to make life easier for us')); }
public function listTables() { $current = drush_get_context('DRUSH_SIMULATE'); drush_set_context('DRUSH_SIMULATE', FALSE); $return = $this->query('SHOW TABLES;'); $tables = drush_shell_exec_output(); drush_set_context('DRUSH_SIMULATE', $current); return $tables; }
function setUp() { // Bootstrap to ensure the auto-loaded is running so that Console_Table is found. drush_preflight(); $this->original_columns = drush_get_context('DRUSH_COLUMNS'); // Some table data we reuse between tests. $this->numbers = array(array('1', '12', '123'), array('1234', '12345', '123456'), array('1234567', '12345678', '123456789')); $this->words = array(array('Drush is a command line shell', 'scripting interface', 'for Drupal'), array('A veritable', 'Swiss Army knife', 'designed to make life easier for us')); }
/** * Setup before each test. */ public function setup() { $this->log = array(); // Set ourselves as the log receiver. deployotron_log_proxy($this); // Save previous value. $this->prevLog = drush_get_context('DRUSH_LOG_CALLBACK', NULL); // Hook into drush_log. drush_set_context('DRUSH_LOG_CALLBACK', 'deployotron_log_proxy'); }
/** * Calls a Drush command. * * This is an exact copy of drush_main from drush.php, but that file * cannot be loaded because it produces side effects. * * @see drush_main * * @return int|string */ protected static function drushMain() { $return = ''; // Start code coverage collection. if ($coverage_file = drush_get_option('drush-coverage', false)) { drush_set_context('DRUSH_CODE_COVERAGE', $coverage_file); xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE); register_shutdown_function('drush_coverage_shutdown'); } /* Set up bootstrap object, so that * - 'early' files can bootstrap when needed. * - bootstrap constants are available. */ $bootstrap_class = drush_get_option('bootstrap_class', 'Drush\\Boot\\DrupalBoot'); $bootstrap = new $bootstrap_class(); drush_set_context('DRUSH_BOOTSTRAP_OBJECT', $bootstrap); $bootstrap->preflight(); // Process initial global options such as --debug. _drush_preflight_global_options(); $return = ''; drush_preflight(); if (!drush_get_error()) { if ($file = drush_get_option('early', false)) { require_once $file; $function = 'drush_early_' . basename($file, '.inc'); if (function_exists($function)) { if ($return = $function()) { // If the function returns FALSE, we continue and attempt to bootstrap // as normal. Otherwise, we exit early with the returned output. if ($return === TRUE) { $return = ''; } } } } else { // Do any necessary preprocessing operations on the command, // perhaps handling immediately. $command_handled = drush_preflight_command_dispatch(); if (!$command_handled) { $bootstrap = drush_get_context('DRUSH_BOOTSTRAP_OBJECT'); $return = $bootstrap->bootstrap_and_dispatch(); } } } drush_postflight(); // How strict are we? If we are very strict, turn 'ok' into 'error' // if there are any warnings in the log. if ($return == 0 && drush_get_option('strict') > 1 && drush_log_has_errors()) { $return = 1; } // After this point the drush_shutdown function will run, // exiting with the correct exit code. return $return; }
/** * Implements \SiteAudit\Check\Abstract\calculateScore(). */ public function calculateScore() { $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT'); exec('du -s -k -x ' . $drupal_root, $result); $this->registry['size_all_kb'] = trim($result[0]); if (!$this->registry['size_all_kb']) { $this->abort = TRUE; return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL; } return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO; }
/** * Implements \SiteAudit\Check\Abstract\calculateScore(). */ public function calculateScore() { $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT'); if (is_dir($drupal_root . '/sites/all')) { if (is_link($drupal_root . '/sites/all')) { return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_WARN; } return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS; } return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL; }
function bootstrap_drupal_full() { if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_start(); } drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_end_clean(); } parent::bootstrap_drupal_full(); }
function bootstrap_drupal_full() { if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_start(); } $this->kernel->boot(); $this->kernel->prepareLegacyRequest($this->request); if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_end_clean(); } parent::bootstrap_drupal_full(); }
/** * Implements \SiteAudit\Check\Abstract\calculateScore(). */ public function calculateScore() { $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT'); exec('du -s -k -x ' . $drupal_root . '/' . variable_get('file_public_path', conf_path() . '/files') . '/', $result); $size_files_kb_exploded = explode("\t", trim($result[0])); $this->registry['size_files_kb'] = $size_files_kb_exploded[0]; if (!$this->registry['size_files_kb']) { $this->abort = TRUE; return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL; } return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO; }
/** * Print druplicon as post-command output. * * @hook post-command * * @option $druplicon Shows the druplicon as glorious ASCII art. */ public function druplicon() { if (drush_get_option('druplicon')) { $misc_dir = DRUSH_BASE_PATH . '/misc'; if (drush_get_context('DRUSH_NOCOLOR')) { $content = file_get_contents($misc_dir . '/druplicon-no_color.txt'); } else { $content = file_get_contents($misc_dir . '/druplicon-color.txt'); } drush_print($content); } }
/** * @todo document */ public function printAsset($asset) { if (is_string($asset)) { $asset = isset($this->assets[$asset]) ? $this->assets[$asset] : FALSE; } if ($asset instanceof Asset) { $width = drush_get_context('DRUSH_COLUMNS', 80); if ($width > 80) { $width = 80; } drush_print(dt("@name\n!separator\n!table", array('@name' => $asset->getName(), '!separator' => str_repeat('_', $width), '!table' => $asset->table()))); } }
function bootstrap_drupal_full() { if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_start(); } drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL); if (!drush_get_context('DRUSH_QUIET', FALSE)) { ob_end_clean(); } // Unset drupal error handler and restore drush's one. restore_error_handler(); parent::bootstrap_drupal_full(); }
/** * Implements \SiteAudit\Check\Abstract\calculateScore(). */ public function calculateScore() { $this->registry['extensions_missing'] = array(); $drupal_root = drush_get_context('DRUSH_SELECTED_DRUPAL_ROOT'); $result = db_select('system')->fields('system', array('name', 'filename'))->condition('status', '1', '=')->execute(); foreach ($result as $row) { if (!file_exists($drupal_root . '/' . $row->filename)) { $this->registry['extensions_missing'][] = $row->name; } } if (!empty($this->registry['extensions_missing'])) { return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL; } return SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS; }
function bootstrap_and_dispatch() { $phases = $this->bootstrap_init_phases(); $return = ''; $command_found = FALSE; _drush_bootstrap_output_prepare(); foreach ($phases as $phase) { if (drush_bootstrap_to_phase($phase)) { $command = drush_parse_command(); if (is_array($command)) { $command += $this->command_defaults(); // Insure that we have bootstrapped to a high enough // phase for the command prior to enforcing requirements. $bootstrap_result = drush_bootstrap_to_phase($command['bootstrap']); $this->enforce_requirement($command); if ($bootstrap_result && empty($command['bootstrap_errors'])) { drush_log(dt("Found command: !command (commandfile=!commandfile)", array('!command' => $command['command'], '!commandfile' => $command['commandfile'])), 'bootstrap'); $command_found = TRUE; // Dispatch the command(s). $return = drush_dispatch($command); // Prevent a '1' at the end of the output. if ($return === TRUE) { $return = ''; } if (drush_get_context('DRUSH_DEBUG') && !drush_get_context('DRUSH_QUIET')) { // @todo Create version independant wrapper around Drupal timers. Use it. drush_print_timers(); } break; } } } else { break; } } if (!$command_found) { // If we reach this point, command doesn't fit requirements or we have not // found either a valid or matching command. $this->report_command_error($command); } return $return; }
/** * 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; }
/** * Display current ration in progress bar * * @param float $ratio */ protected function display($ratio) { $percentage = $this->getValue($ratio) . '%'; $columns = drush_get_context('DRUSH_COLUMNS', 80); $output = ''; $suffix = ''; if ($this->withEta) { if ($eta = $this->computeEtaFromRatio($ratio)) { if ($eta[1]) { $suffix = sprintf('%s, eta: %s', self::formatDuration($eta[0], self::FORMAT_TIME_FULL), self::formatDuration($eta[1], self::FORMAT_TIME_FULL)); } else { $suffix = sprintf('elapsed: %s', self::formatDuration($eta[0], self::FORMAT_TIME_FULL)); } } else { $suffix = dt("Computing..."); } } // Subtract 8 characters for the percentage, brackets, spaces and arrow. $progress_columns = $columns - 8 - strlen($suffix) - 1; // If ratio is 1 (complete), the > becomes a = to make a full bar. $arrow = $ratio < 1 ? '>' : '='; // Print a new line if ratio is 1 (complete). Otherwise, use a CR. $line_ending = "\r"; // Determine the current length of the progress string. $current_length = floor($ratio * $progress_columns); $progress_string = str_pad('', $current_length, '='); $output .= str_pad('', 4 - strlen($percentage)) . $percentage; $output .= ' ['; $output .= $progress_string . $arrow; $output .= str_pad('', $progress_columns - $current_length); $output .= '] '; $output .= $suffix; $output .= $line_ending; print $output; }
/** * Check to see if a '@self' record was created during bootstrap. * If not, make one now. * * @see drush_sitealias_create_self_alias() */ protected function create_self_alias() { $self_record = drush_sitealias_get_record('@self'); if (!array_key_exists('root', $self_record) && !array_key_exists('remote-host', $self_record)) { $backdrop_root = drush_get_context('DRUSH_SELECTED_BACKDROP_ROOT'); $uri = drush_get_context('DRUSH_SELECTED_URI'); if (!empty($backdrop_root) && !empty($uri)) { // Create an alias '@self' _drush_sitealias_cache_alias('@self', array('root' => $backdrop_root, 'uri' => $uri)); } } }
/** * Implements \SiteAudit\Check\Abstract\getResultPass(). */ public function getResultPass() { $items = array(); foreach ($this->registry['requirements'] as $requirement) { // Reduce verbosity. if (!drush_get_option('detail') && $requirement['severity'] < REQUIREMENT_WARNING) { continue; } // Title: severity - value. if ($requirement['severity'] == REQUIREMENT_INFO) { $class = 'info'; $severity = 'Info'; } elseif ($requirement['severity'] == REQUIREMENT_OK) { $severity = 'Ok'; $class = 'success'; } elseif ($requirement['severity'] == REQUIREMENT_WARNING) { $severity = 'Warning'; $class = 'warning'; } elseif ($requirement['severity'] == REQUIREMENT_ERROR) { $severity = 'Error'; $class = 'error'; } if (drush_get_option('html')) { $value = isset($requirement['value']) && $requirement['value'] ? $requirement['value'] : ' '; $uri = drush_get_context('DRUSH_URI'); // Unknown URI - strip all links, but leave formatting. if ($uri == 'http://default') { $value = strip_tags($value, '<em><i><b><strong><span>'); } // Convert relative links to absolute. else { $value = preg_replace("#(<\s*a\s+[^>]*href\s*=\s*[\"'])(?!http)([^\"'>]+)([\"'>]+)#", '$1' . $uri . '$2$3', $value); } $item = array( 'title' => $requirement['title'], 'severity' => $severity, 'value' => $value, 'class' => $class, ); } else { $item = strip_tags($requirement['title']) . ': ' . $severity; if (isset($requirement['value']) && $requirement['value']) { $item .= ' - ' . dt('@value', array( '@value' => strip_tags($requirement['value']), )); } } $items[] = $item; } if (drush_get_option('html')) { $ret_val = '<table class="table table-condensed">'; $ret_val .= '<thead><tr><th>Title</th><th>Severity</th><th>Value</th></thead>'; $ret_val .= '<tbody>'; foreach ($items as $item) { $ret_val .= '<tr class="' . $item['class'] . '">'; $ret_val .= '<td>' . $item['title'] . '</td>'; $ret_val .= '<td>' . $item['severity'] . '</td>'; $ret_val .= '<td>' . $item['value'] . '</td>'; $ret_val .= '</tr>'; } $ret_val .= '</tbody>'; $ret_val .= '</table>'; } else { $separator = PHP_EOL; if (!drush_get_option('json')) { $separator .= str_repeat(' ', 4); } $ret_val = implode($separator, $items); } return $ret_val; }
/** * Execute a SQL query. * * Note: This is an API function. Try to avoid using drush_get_option() and instead * pass params in. If you don't want to query results to print during --debug then * provide a $result_file whose value can be drush_bit_bucket(). * * @param string $query * The SQL to be executed. Should be NULL if $input_file is provided. * @param string $input_file * A path to a file containing the SQL to be executed. * @param string $result_file * A path to save query results to. Can be drush_bit_bucket() if desired. * * @return * TRUE on success, FALSE on failure */ public function query($query, $input_file = NULL, $result_file = '') { $input_file_original = $input_file; if ($input_file && drush_file_is_tarball($input_file)) { if (drush_shell_exec('gunzip %s', $input_file)) { $input_file = trim($input_file, '.gz'); } else { return drush_set_error(dt('Failed to gunzip input file.')); } } // Save $query to a tmp file if needed. We will redirect it in. if (!$input_file) { $query = $this->query_prefix($query); $query = $this->query_format($query); $input_file = drush_save_data_to_temp_file($query); } $parts = array($this->command(), $this->creds(), $this->silent(), drush_get_option('extra', $this->query_extra), $this->query_file, drush_escapeshellarg($input_file)); $exec = implode(' ', $parts); if ($result_file) { $exec .= ' > ' . drush_escapeshellarg($result_file); } // In --verbose mode, drush_shell_exec() will show the call to mysql/psql/sqlite, // but the sql query itself is stored in a temp file and not displayed. // We show the query when --debug is used and this function created the temp file. if ((drush_get_context('DRUSH_DEBUG') || drush_get_context('DRUSH_SIMULATE')) && empty($input_file_original)) { drush_log('sql-query: ' . $query, LogLevel::NOTICE); } $success = drush_shell_exec($exec); if ($success && drush_get_option('file-delete')) { drush_op('drush_delete_dir', $input_file); } return $success; }
/** * Called by bootstrap_drupal_site to do the main work * of the drush drupal site bootstrap. */ function bootstrap_do_drupal_site() { $drush_uri = drush_get_context('DRUSH_SELECTED_URI'); drush_set_context('DRUSH_URI', $drush_uri); $site = drush_set_context('DRUSH_DRUPAL_SITE', drush_bootstrap_value('site')); $conf_path = drush_set_context('DRUSH_DRUPAL_SITE_ROOT', drush_bootstrap_value('conf_path')); drush_log(dt("Initialized Drupal site !site at !site_root", array('!site' => $site, '!site_root' => $conf_path))); _drush_preflight_global_options(); }
/** * */ function cmsRootPath($scriptFilename = NULL) { $cmsRoot = $valid = NULL; if (!is_null($scriptFilename)) { $path = $scriptFilename; } else { $path = $_SERVER['SCRIPT_FILENAME']; } if (function_exists('drush_get_context')) { // drush anyway takes care of multisite install etc return drush_get_context('DRUSH_DRUPAL_ROOT'); } // CRM-7582 $pathVars = explode('/', str_replace('//', '/', str_replace('\\', '/', $path))); //lets store first var, //need to get back for windows. $firstVar = array_shift($pathVars); //lets remove sript name to reduce one iteration. array_pop($pathVars); //CRM-7429 --do check for upper most 'includes' dir, //which would effectually work for multisite installation. do { $cmsRoot = $firstVar . '/' . implode('/', $pathVars); $cmsIncludePath = "{$cmsRoot}/includes"; //stop as we found bootstrap. if (@opendir($cmsIncludePath) && file_exists("{$cmsIncludePath}/bootstrap.inc")) { $valid = TRUE; break; } //remove one directory level. array_pop($pathVars); } while (count($pathVars)); return $valid ? $cmsRoot : NULL; }
/** * Check if the given command belongs to a disabled module * * @return * Array with a command-like bootstrap error or FALSE if Drupal was not * bootstrapped fully or the command does not belong to a diabled module. */ function drush_command_belongs_to_disabled_module() { if (drush_has_boostrapped(DRUSH_BOOTSTRAP_DRUPAL_FULL)) { _drush_find_commandfiles(DRUSH_BOOTSTRAP_DRUPAL_SITE, DRUSH_BOOTSTRAP_DRUPAL_CONFIGURATION); $commands = drush_get_commands(); $arguments = drush_get_arguments(); $command_name = array_shift($arguments); if (isset($commands[$command_name])) { // We found it. Load its module name and set an error. if (is_array($commands[$command_name]['drupal dependencies']) && count($commands[$command_name]['drupal dependencies'])) { $modules = implode(', ', $commands[$command_name]['drupal dependencies']); } else { // The command does not define Drupal dependencies. Derive them. $command_files = drush_get_context('DRUSH_COMMAND_FILES', array()); $command_path = $commands[$command_name]['path'] . DIRECTORY_SEPARATOR . $commands[$command_name]['commandfile'] . '.drush.inc'; $modules = array_search($command_path, $command_files); } return array('bootstrap_errors' => array('DRUSH_COMMAND_DEPENDENCY_ERROR' => dt('Command !command needs the following module(s) enabled to run: !dependencies.', array('!command' => $command_name, '!dependencies' => $modules)))); } } return FALSE; }
/** * Automatically download project dependencies at pm-enable time. * Use a pre-pm_enable hook to download before your module is enabled, * or a post-pm_enable hook (drush_hook_post_pm_enable) to run after * your module is enabled. * * Your hook will be called every time pm-enable is executed; you should * only download dependencies when your module is being enabled. Respect * the --skip flag, and take no action if it is present. */ function drush_hook_pre_pm_enable() { // Get the list of modules being enabled; only download dependencies if our module name appears in the list $modules = drush_get_context('PM_ENABLE_MODULES'); if (in_array('hook', $modules) && !drush_get_option('skip')) { $url = 'http://server.com/path/MyLibraryName.tgz'; $path = drush_get_context('DRUSH_DRUPAL_ROOT'); if (module_exists('libraries')) { $path .= '/' . libraries_get_path('MyLibraryName') . '/MyLibraryName.tgz'; } else { $path .= '/' . drupal_get_path('module', 'hook') . '/MyLibraryName.tgz'; } drush_download_file($url, $path) && drush_tarball_extract($path); } }