/** * 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(); } }
/** * {@inheritdoc} */ public function run($name, $time_limit = 0) { $worker = $this->workerManager->createInstance($name); $end = time() + $time_limit; $queue = $this->getQueue($name); $count = 0; while ((!$time_limit || time() < $end) && ($item = $queue->claimItem())) { try { drush_log(dt('Processing item @id from @name queue.', array('@name' => $name, 'id' => $item->item_id)), 'info'); $worker->processItem($item->data); $queue->deleteItem($item); $count++; } catch (SuspendQueueException $e) { // If the worker indicates there is a problem with the whole queue, // release the item and skip to the next queue. $queue->releaseItem($item); drush_set_error('DRUSH_SUSPEND_QUEUE_EXCEPTION', $e->getMessage()); } catch (\Exception $e) { // In case of any other kind of exception, log it and leave the item // in the queue to be processed again later. drush_set_error('DRUSH_QUEUE_EXCEPTION', $e->getMessage()); } } return $count; }
/** * Constructor; loads and executes checks based on the name of this report. */ public function __construct() { global $conf; $base_class_name = 'SiteAuditCheck' . $this->getReportName(); $percent_override = NULL; $checks_to_skip = array(); if (drush_get_option('skip')) { $checks_to_skip = explode(',', drush_get_option('skip')); } $checks_to_perform = $this->getCheckNames(); foreach ($checks_to_perform as $key => $check_name) { if (in_array($this->getReportName() . $check_name, $checks_to_skip)) { unset($checks_to_perform[$key]); } } if (empty($checks_to_perform)) { // No message for audit_all. $command = drush_parse_command(); if ($command['command'] == 'audit_all') { return FALSE; } return drush_set_error('SITE_AUDIT_NO_CHECKS', dt('No checks are available!')); } foreach ($checks_to_perform as $check_name) { $class_name = $base_class_name . $check_name; $check = new $class_name($this->registry, isset($conf['site_audit']['opt_out'][$this->getReportName() . $check_name])); // Calculate score. if ($check->getScore() != SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO) { // Mark if there's a major failure. if ($check->getScore() == SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_FAIL) { $this->hasFail = TRUE; } // Total. $this->scoreTotal += $check->getScore(); // Maximum. $this->scoreMax += SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_PASS; } // Allow Report percentage to be overridden. if ($check->getPercentOverride()) { $percent_override = $check->getPercentOverride(); } // Combine registry. $this->registry = array_merge($this->registry, $check->getRegistry()); // Store all checks. $this->checks[$class_name] = $check; // Abort the loop if the check says to bail. if ($check->shouldAbort()) { break; } } if ($percent_override) { $this->percent = $percent_override; } else { if ($this->scoreMax != 0) { $this->percent = round($this->scoreTotal / $this->scoreMax * 100); } else { $this->percent = SiteAuditCheckAbstract::AUDIT_CHECK_SCORE_INFO; } } }
/** * Class constructor. * * @param CommandBase $command * The current instance of the command. */ public function __construct(CommandBase $command) { $this->command = $command; // Determine if the "path" option has been set. $this->path = drush_get_option('path'); if ($this->path && !file_exists($this->path)) { return drush_set_error('DRUSH_LWG_INVALID_PATH', dt("The specified project path does not exist:\n!path", array('!path' => $this->path))); } else { if (!$this->path) { $this->path = drush_cwd(); } } // Ensure the path is writable. if (!is_writable($this->path)) { return drush_set_error('DRUSH_LWG_PATH_NOT_WRITABLE', dt("The specified project path is not writable:\n!path", array('!path' => $this->path))); } foreach (drush_scan_directory($this->path, '/\\.info(\\.yml)?/') as $file) { if ($this->info = drush_drupal_parse_info_file($file->filename)) { $this->name = $file->name; break; } } if (!$this->getInfo('name')) { return drush_set_error('DRUSH_LWG_NOT_PROJECT', dt('Project info not found. Please navigate to a valid project directory or specify one with the --path option.')); } // Indicate that this is a valid project. $this->valid = TRUE; }
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; }
/** * Parse a URI or partial URI (including just a port, host IP or path). * * @param string $uri * String that can contain partial URI. * * @return array * URI array as returned by parse_url. */ function runserver_parse_uri($uri) { if (empty($uri)) { return array(); } if ($uri[0] == ':') { // ':port/path' shorthand, insert a placeholder hostname to allow parsing. $uri = 'placeholder-hostname' . $uri; } // FILTER_VALIDATE_IP expects '[' and ']' to be removed from IPv6 addresses. // We check for colon from the right, since IPv6 addresses contain colons. $to_path = trim(substr($uri, 0, strpos($uri, '/')), '[]'); $to_port = trim(substr($uri, 0, strrpos($uri, ':')), '[]'); if (filter_var(trim($uri, '[]'), FILTER_VALIDATE_IP) || filter_var($to_path, FILTER_VALIDATE_IP) || filter_var($to_port, FILTER_VALIDATE_IP)) { // 'IP', 'IP/path' or 'IP:port' shorthand, insert a schema to allow parsing. $uri = 'http://' . $uri; } $uri = parse_url($uri); if (empty($uri)) { return drush_set_error('RUNSERVER_INVALID_ADDRPORT', dt('Invalid argument - should be in the "host:port/path" format, numeric (port only) or non-numeric (path only).')); } if (count($uri) == 1 && isset($uri['path'])) { if (is_numeric($uri['path'])) { // Port only shorthand. $uri['port'] = $uri['path']; unset($uri['path']); } } if (isset($uri['host']) && $uri['host'] == 'placeholder-hostname') { unset($uri['host']); } return $uri; }
public function validateDrushParams($args) { $values = array('num' => array_shift($args), 'kill' => drush_get_option('kill'), 'title_length' => 12); if ($this->isNumber($values['num']) == FALSE) { return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid number of vocabularies: !num.', array('!num' => $values['num']))); } return $values; }
/** * Downloads release info xml from update service. * * @param array $request * A request array. * @param int $cache_duration * Cache lifetime. * * @return \Drush\UpdateService\Project */ public static function getInstance(array $request, $cache_duration = ReleaseInfo::CACHE_LIFETIME) { $url = self::buildFetchUrl($request); drush_log(dt('Downloading release history from !url', array('!url' => $url))); $path = drush_download_file($url, drush_tempnam($request['name']), $cache_duration); $xml = simplexml_load_file($path); if (!$xml) { $error = dt('Failed to get available update data from !url', array('!url' => $url)); return drush_set_error('DRUSH_RELEASE_INFO_ERROR', $error); } return new Project($xml); }
public function downloadCore() { $www_dir = $this->getProjectDir() . '/' . $this->getDocumentRoot(); if (!is_file($www_dir . '/misc/drupal.js')) { $core_version = $this->getCoreVersion(); $core = "drupal-" . $core_version . ".x"; drush_log(dt('Downloading Drupal core...'), 'status'); drush_set_option('backend', TRUE); drush_set_option('destination', $this->getProjectDir()); drush_set_option('drupal-project-rename', $this->getDocumentRoot()); if (drush_invoke('pm-download', array($core)) === FALSE) { return drush_set_error('', 'Drupal core download/extract failed.'); } drush_set_option('backend', FALSE); } else { drush_log(dt('Drupal already downloaded and unpacked for this project.')); } }
function report_command_error($command) { // 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); } }
/** * {@inheritdoc} */ public function run($name, $time_limit = 0) { $info = $this->getInfo($name); $function = $info['worker callback']; $end = time() + $time_limit; $queue = $this->getQueue($name); $count = 0; while ((!$time_limit || time() < $end) && ($item = $queue->claimItem())) { try { drush_log(dt('Processing item @id from @name queue.', array('@name' => $name, 'id' => $item->item_id)), LogLevel::INFO); $function($item->data); $queue->deleteItem($item); $count++; } catch (\Exception $e) { // In case of exception log it and leave the item in the queue // to be processed again later. drush_set_error('DRUSH_QUEUE_EXCEPTION', $e->getMessage()); } } return $count; }
/** * Class constructor. * * @param LWG $command * The current instance of the command. * @param array|object $input * The input parameter accepts an array. * @param int $flags * Flags to control the behaviour of the ArrayObject object. * @param string $iterator_class * Specify the class that will be used for iteration of the ArrayObject * object. ArrayIterator is the default class used. */ public function __construct(LWG $command, array $input = array(), $flags = 0, $iterator_class = "ArrayIterator") { $this->command = $command; $this->exchangeArray($input); $project = $command->getProject(); $filename = $this->getFilename(); $this->file = $project->getPath() . "/{$filename}"; $this->cache = new Cache($project->getName() . ':notice'); $cache = $this->cache->get(); if (!file_exists($this->file)) { $prompt = dt("An existing !filename file was not found in @project.\nWould you like to create one?", array('!filename' => $filename, '@project' => $project->getInfo('name') ?: 'this project')); if (drush_confirm($prompt)) { if (!$this->save()) { return drush_set_error('DRUSH_LWG_CREATE_FILE', dt("Unable to create the specified project file:\n!file", array('!file' => $this->file))); } } else { $this->file = FALSE; return $this; } } if (!is_writable($this->file)) { return drush_set_error('DRUSH_LWG_FILE_NOT_WRITABLE', dt("The specified project file is not writable:\n!file", array('!file' => $this->file))); } if (file_exists($this->file)) { $array = array(); // Convert each entry into an Asset object. foreach (Yaml::parse($this->file) ?: array() as $name => $data) { if (is_array($data)) { $array[$name] = new Asset($command, $name, $data); } } if (!$this->cache->exists()) { $this->cache->set($array); } $this->exchangeArray($array); $this->exists = 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; }
public function validateDrushParams($args) { $link_types = array('node', 'front', 'external'); $values = array('num_menus' => array_shift($args), 'num_links' => array_shift($args), 'kill' => drush_get_option('kill'), 'pipe' => drush_get_option('pipe'), 'link_types' => array_combine($link_types, $link_types)); $max_depth = array_shift($args); $max_width = array_shift($args); $values['max_depth'] = $max_depth ? $max_depth : 3; $values['max_width'] = $max_width ? $max_width : 8; $values['existing_menus']['__new-menu__'] = TRUE; if ($this->isNumber($values['num_menus']) == FALSE) { return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid number of menus')); } if ($this->isNumber($values['num_links']) == FALSE) { return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid number of links')); } if ($this->isNumber($values['max_depth']) == FALSE || $values['max_depth'] > 9 || $values['max_depth'] < 1) { return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid maximum link depth. Use a value between 1 and 9')); } if ($this->isNumber($values['max_width']) == FALSE || $values['max_width'] < 1) { return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid maximum menu width. Use a positive numeric value.')); } return $values; }
/** * Execute the BackdropBoot::BOOTSTRAP_LOGIN phase. * * Log into the bootstrapped Backdrop site with a specific user name or ID. */ function bootstrap_backdrop_login() { $uid_or_name = drush_set_context('DRUSH_USER', drush_get_option('user', 0)); if (is_numeric($uid_or_name)) { $account = user_load($uid_or_name); } if (!$account) { $account = user_load_by_name($uid_or_name); } if ($account) { $GLOBALS['user'] = $account; // @todo: Convert Backdrop messages to drush output. //_drush_log_drupal_messages(); } else { if (is_numeric($uid_or_name)) { $message = dt('Could not login with user ID !user.', array('!user' => $uid_or_name)); if ($uid_or_name === 0) { $message .= ' ' . dt('This is typically caused by importing a MySQL database dump from a faulty tool which re-numbered the anonymous user ID in the users table. See !link for help recovering from this situation.', array('!link' => 'http://drupal.org/node/1029506')); } } else { $message = dt('Could not login with user account `!user\'.', array('!user' => $uid_or_name)); } return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message); } }
/** * 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; }
/** * Log into the bootstrapped Drupal site with a specific * username or user id. */ function bootstrap_drupal_login() { $uid_or_name = drush_set_context('DRUSH_USER', drush_get_option('user', 0)); $userversion = drush_user_get_class(); if (!($account = $userversion->load_by_uid($uid_or_name))) { if (!($account = $userversion->load_by_name($uid_or_name))) { if (is_numeric($uid_or_name)) { $message = dt('Could not login with user ID !user.', array('!user' => $uid_or_name)); if ($uid_or_name === 0) { $message .= ' ' . dt('This is typically caused by importing a MySQL database dump from a faulty tool which re-numbered the anonymous user ID in the users table. See !link for help recovering from this situation.', array('!link' => 'http://drupal.org/node/1029506')); } } else { $message = dt('Could not login with user account `!user\'.', array('!user' => $uid_or_name)); } return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message); } } $userversion->setCurrentUser($account); _drush_log_drupal_messages(); }
/** * Log the given user in to a bootstrapped Drupal site. * * @param mixed * Numeric user id or user name. * * @return boolean * TRUE if user was logged in, otherwise FALSE. */ function drush_drupal_login($drush_user) { global $user; if (drush_drupal_major_version() >= 7) { $user = is_numeric($drush_user) ? user_load($drush_user) : user_load_by_name($drush_user); } else { $user = user_load(is_numeric($drush_user) ? array('uid' => $drush_user) : array('name' => $drush_user)); } if (empty($user)) { if (is_numeric($drush_user)) { $message = dt('Could not login with user ID #!user.', array('!user' => $drush_user)); } else { $message = dt('Could not login with user account `!user\'.', array('!user' => $drush_user)); } return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message); } else { $name = $user->name ? $user->name : variable_get('anonymous', t('Anonymous')); drush_log(dt('Successfully logged into Drupal as !name', array('!name' => $name . " (uid={$user->uid})")), 'bootstrap'); } return TRUE; }
public function tearDown() { $errors = drush_get_error_log(); if (!empty($errors)) { foreach ($errors as $error) { drush_set_error(dt($error)); } return FALSE; } return TRUE; }
# $command_specific['core-cli'] = array('override' => 'help,dd,sa'); // Provide a default directory to run on drush casperjs. # $command_specific['casperjs']['test-root'] = str_replace('drush', 'tests/casperjs', dirname(__FILE__)); /** * Load local development override configuration, if available. * * Use drushrc.local.php to override Drush configuration on secondary (staging, * development, etc) installations of this site. * * Keep this code block at the end of this file to take full effect. */ // Read JSON configuration file from conf/ and pre-configure drush commands $json_path = dirname(__FILE__) . '/../conf/config.json'; $cfg = (object) array('variables' => (object) array('environment' => 'production')); if (file_exists($json_path)) { if ($cfg = json_decode(file_get_contents($json_path))) { $db_url = sprintf('mysql://%s:%s@%s:%s/%s', $cfg->db->username, $cfg->db->password, $cfg->db->host, $cfg->db->port, $cfg->db->database); $command_specific['site-install'] = array('db-url' => $db_url, 'account-mail' => $cfg->admin->email, 'account-name' => $cfg->admin->username, 'account-pass' => $cfg->admin->password, 'db-su' => $cfg->db->root_username, 'db-su-pw' => $cfg->db->root_password); } else { drush_set_error('Error detected in config.json, please fix them and try again'); } } $options['init-modules'] = array('ctools', 'entity', 'aggregator', 'memcache_storage', 'varnish', 'elysia_cron', 'locale', 'entity_translation', 'i18n', 'i18n_string', 'i18n_taxonomy', 'variable', 'email', 'views', 'views_ui', 'views_bulk_operations', 'date_views', 'better_exposed_filters', 'mailsystem', 'htmlmail', 'taxonomy_access_fix', 'date', 'migrate', 'migrate_ui', 'features', 'field_group', 'entityreference', 'entityreference_view_widget', 'link', 'title', 'wysiwyg', 'pathauto', 'redirect', 'file_entity', 'media', 'media_wysiwyg', 'languagefield', 'image_field_caption', 'tmgmt', 'tmgmt_local', 'tmgmt_locale', 'tmgmt_entity', 'tmgmt_entity_ui', 'tmgmt_ui', 'tmgmt_file', 'tmgmt_i18n_string', 'blockgroup', 'i18n_menu', 'i18n_block', 'strongarm', 'exclude_node_title', 'metatag', 'metatag_dc', 'pdf_to_image', 'doc_to_imagefield', 'special_menu_items', 'menu_block', 'menuimage', 'lang_dropdown', 'multiple_selects', 'imce_wysiwyg', 'wysiwyg_accordion', 'nodequeue', 'fe_block', 'fe_nodequeue', 'views_slideshow', 'views_slideshow_cycle', 'custom_formatters', 'taxonomy_manager', 'term_reference_tree', 'node_export', 'mpac', 'linkit', 'pathologic', 'scanner', 'search_and_replace', 'nodeblock', 'quicktabs', 'context', 'context_ui', 'context_block_visibility', 'site_map', 'xmlsitemap', 'xmlsitemap_node', 'xmlsitemap_menu', 'xmlsitemap_i18n', 'smart_trim', 'menu_attributes', 'menu_item_visibility', 'shs', 'smtp', 'uuid', 'uuid_features', 'path_breadcrumbs', 'path_breadcrumbs_ui', 'path_breadcrumbs_i18n', 'jquery_update', 'responsive_menus', 'workbench', 'workbench_access', 'workbench_moderation', 'print', 'print_ui', 'print_pdf_tcpdf', 'print_pdf', 'youtube', 'flickr', 'flickr_block', 'flickrfield', 'chosen', 'eu_cookie_compliance', 'piwik', 'googleanalytics', 'calendar', 'date_popup', 'feeds', 'feeds_import', 'feeds_ui', 'feeds_tamper', 'feeds_tamper_ui', 'views_php', 'views_json', 'comment_allow_anonymous', 'twitter_block', 'contact', 'field_collection', 'webform', 'webform_localization', 'fapi_validation', 'osha_taxonomies', 'osha', 'osha_migration', 'osha_news', 'osha_note_to_editor', 'osha_nodequeue', 'osha_publication', 'osha_calls', 'osha_blog', 'osha_infographics', 'osha_tmgmt', 'osha_highlight', 'osha_press_contact', 'osha_press_release', 'osha_homepage', 'osha_menu', 'osha_job_vacancies', 'osha_wiki', 'osha_workflow', 'osha_blocks', 'osha_breadcrumbs', 'osha_legislation', 'osha_short_messages', 'osha_resources', 'osha_slideshare', 'osha_events', 'osha_alert_service', 'osha_contact', 'osha_fop_page', 'osha_authentication', 'osha_sitemap', 'linkchecker', 'osha_linkchecker', 'osha_reminders', 'facetapi', 'search_api_facetapi', 'search_autocomplete', 'search_api_et', 'search_api_et_solr', 'search_api_views', 'search_api_attachments', 'osha_search', 'osha_content', 'osha_lingua_tools', 'dvs', 'entity_collection', 'entity_collection_db', 'osha_newsletter', 'captcha', 'recaptcha', 'image_captcha', 'spamspan', 'addtoany', 'on_the_web', 'menu_position', 'r4032login', 'devel', 'devel_node_access', 'diff', 'securepages', 'update'); $options['init-themes'] = array('osha_admin', 'osha_frontend'); $options['disable-modules'] = array('varnish', 'memcache_storage'); // Add specific settings for development or demo. $command_specific['devify'] = array('enable-modules' => array('reroute_email', 'simpletest', 'devel', 'devel_node_access', 'stage_file_proxy'), 'delete-variables' => array('googleanalytics_account', 'piwik_site_id', 'piwik_url_http', 'piwik_url_https'), 'reset-variables' => array_merge(array('reroute_email_enable_message' => TRUE, 'reroute_email_enable' => TRUE, 'stage_file_proxy_origin' => 'https://ncw.osha.europa.eu', 'stage_file_proxy_use_imagecache_root' => TRUE, 'stage_file_proxy_hotlink' => FALSE, 'reroute_email_address' => $cfg->variables->site_mail, 'smtp_from' => $cfg->variables->site_mail, 'smtp_fromname' => $cfg->variables->site_name), (array) $cfg->variables)); $command_specific['devify_solr'] = array('solr_server' => (array) $cfg->solr_server); if (file_exists(dirname(__FILE__) . '/drushrc.local.php')) { include dirname(__FILE__) . '/drushrc.local.php'; }
return; } foreach (array_keys($result['message']) as $mid) { $i++; // Load the message. $message = message_load($mid); $tokens = array('message:field-node-reference:url', 'message:field-node-reference:title'); $save_message = FALSE; foreach ($tokens as $token) { // Check that the token is not hard coded. if (isset($message->arguments['@{' . $token . '}'])) { continue; } $save_message = TRUE; // Creating a hard coded value for the toekn. $token_options = message_get_property_values($message, 'data', 'token options'); $context = array('message' => $message); $message->arguments['@{' . $token . '}'] = token_replace('[' . $token . ']', $context, $token_options); } if ($save_message) { $param = array('@mid' => $mid, '@tokens' => implode(' ', $tokens)); drush_log(dt($mid . '\\ ' . $max . ') Processing the @tokens in the message @mid', $param), 'success'); // Saving the message and the display message for the user. message_save($message); // The script taking to much memory. Stop it and display message. if (round(memory_get_usage() / 1048576) >= $memory_limit) { return drush_set_error('OS_ACTIVITY OUT_OF_MEMORY', dt('Stopped before out of memory. Last message ID was @mid', array('@mid' => $mid))); } } } }
/** * Log the given user in to a bootstrapped Drupal site. * * @param mixed * Numeric user id or user name. * * @return boolean * TRUE if user was logged in, otherwise FALSE. */ function drush_drupal_login($drush_user) { global $user; if (drush_drupal_major_version() >= 7) { $user = is_numeric($drush_user) ? user_load($drush_user) : user_load_by_name($drush_user); } else { $user = user_load(is_numeric($drush_user) ? array('uid' => $drush_user) : array('name' => $drush_user)); } if (empty($user)) { if (is_numeric($drush_user)) { $message = dt('Could not login with user ID #%user.', array('%user' => $drush_user)); } else { $message = dt('Could not login with user account `%user\'.', array('%user' => $drush_user)); } return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message); } return TRUE; }
/** * {@inheritdoc} */ public function validateDrushParams($args) { $add_language = drush_get_option('languages'); if (!empty($add_language)) { $add_language = explode(',', str_replace(' ', '', $add_language)); // Intersect with the enabled languages to make sure the language args // passed are actually enabled. $values['values']['add_language'] = array_intersect($add_language, array_keys($this->languageManager->getLanguages(LanguageInterface::STATE_ALL))); } $values['kill'] = drush_get_option('kill'); $values['title_length'] = drush_get_option('title_length', 6); $values['num'] = array_shift($args); $selected_bundles = _convert_csv_to_array(drush_get_option('bundles', [])); if (empty($selected_bundles)) { return drush_set_error('DEVEL_GENERATE_NO_MEDIA_BUNDLES', dt('No media bundles available')); } $values['media_bundles'] = array_combine($selected_bundles, $selected_bundles); return $values; }
/** * Log the given user in to a bootstrapped Drupal site. * * @param mixed * Numeric user id or user name. * * @return boolean * TRUE if user was logged in, otherwise FALSE. */ function drush_drupal_login($drush_user) { global $user; if (drush_drupal_major_version() >= 7) { $user = is_numeric($drush_user) ? user_load($drush_user) : user_load_by_name($drush_user); } else { $user = user_load(is_numeric($drush_user) ? array('uid' => $drush_user) : array('name' => $drush_user)); } if (empty($user)) { if (is_numeric($drush_user)) { $message = dt('Could not login with user ID #!user.', array('!user' => $drush_user)); if ($drush_user === 0) { $message .= ' ' . dt('This is typically caused by importing a MySQL database dump from a faulty tool which re-numbered the anonymous user ID in the users table. See !link for help recovering from this situation.', array('!link' => 'http://drupal.org/node/1029506')); } } else { $message = dt('Could not login with user account `!user\'.', array('!user' => $drush_user)); } return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message); } else { $name = $user->name ? $user->name : variable_get('anonymous', t('Anonymous')); drush_log(dt('Successfully logged into Drupal as !name', array('!name' => $name . " (uid={$user->uid})")), 'bootstrap'); } return TRUE; }
public function validateDrushParams($args) { $vname = array_shift($args); $values = array('num' => array_shift($args), 'kill' => drush_get_option('kill'), 'title_length' => 12); // Try to convert machine name to a vocab ID if (!($vocab = entity_load('taxonomy_vocabulary', $vname))) { return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid vocabulary name: !name', array('!name' => $vname))); } if ($this->isNumber($values['num']) == FALSE) { return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Invalid number of terms: !num', array('!num' => $values['num']))); } $values['vids'] = array($vocab->id()); return $values; }
/** * {@inheritdoc} */ public function validateDrushParams($args) { $add_language = drush_get_option('languages'); if (!empty($add_language)) { $add_language = explode(',', str_replace(' ', '', $add_language)); // Intersect with the enabled languages to make sure the language args // passed are actually enabled. $values['values']['add_language'] = array_intersect($add_language, array_keys(locale_language_list())); } $values['kill'] = drush_get_option('kill'); $values['title_length'] = 6; $values['num'] = array_shift($args); $values['max_comments'] = array_shift($args); $all_types = array_keys(node_type_get_names()); $default_types = array_intersect(array('page', 'article'), $all_types); $selected_types = _convert_csv_to_array(drush_get_option('types', $default_types)); if (empty($selected_types)) { return drush_set_error('DEVEL_GENERATE_NO_CONTENT_TYPES', dt('No content types available')); } $values['node_types'] = array_combine($selected_types, $selected_types); $node_types = array_filter($values['node_types']); if (!empty($values['kill']) && empty($node_types)) { return drush_set_error('DEVEL_GENERATE_INVALID_INPUT', dt('Please provide content type (--types) in which you want to delete the content.')); } return $values; }
function _drush_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')) { drush_print_timers(); } drush_log(dt('Peak memory usage was !peak', array('!peak' => drush_format_size(memory_get_peak_usage()))), 'memory'); break; } } } else { break; } } if (!$command_found) { // If we reach this point, we have not found either a valid or matching 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.", 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; }
/** * Log the given user in to a bootstrapped Drupal site. * * @param mixed * Numeric user id or user name. * * @return boolean * TRUE if user was logged in, otherwise FALSE. */ function drush_drupal_login($drush_user) { global $user; $user = module_invoke('user', 'load', is_numeric($drush_user) ? array('uid' => $drush_user) : array('name' => $drush_user)); if (empty($user)) { if (is_numeric($drush_user)) { $message = dt('Could not login with user ID #%user.', array('%user' => $drush_user)); } else { $message = dt('Could not login with user account `%user\'.', array('%user' => $drush_user)); } return drush_set_error('DRUPAL_USER_LOGIN_FAILED', $message); } return TRUE; }
/** * Download a backup. * * @param array $backup * An array from apiGetSiteEnvBackups(). * @param string $destination * The path to the destination. * * @return string * The full path to the downloaded backup. */ public function apiDownloadBackup($backup, $destination) { // See Drush's package_handler_download_project(). $destination_path = $destination . DIRECTORY_SEPARATOR . $backup['filename']; $path = _drush_download_file($backup['url'], $destination_path, 31556926); if ($path || drush_get_context('DRUSH_SIMULATE')) { return $destination_path; } else { return drush_set_error('SWITCHBOARD_PANTHEON_BACKUP_DL_FAIL', dt('Unable to download!')); } }
/** * Select the most appropriate release for a project, based on a strategy. * * @param Array &$request * A request array. * The array will be expanded with the project type. * @param String $restrict_to * One of: * 'dev': Forces choosing a -dev release. * 'version': Forces choosing a point release. * '': No restriction. * Default is ''. * @param String $select * Strategy for selecting a release, should be one of: * - auto: Try to select the latest release, if none found allow the user * to choose. * - always: Force the user to choose a release. * - never: Try to select the latest release, if none found then fail. * - ignore: Ignore and return NULL. * If no supported release is found, allow to ask the user to choose one. * @param Boolean $all * In case $select = TRUE this indicates that all available releases will be * offered the user to choose. * * @return array * The selected release. */ public function selectReleaseBasedOnStrategy($request, $restrict_to = '', $select = 'never', $all = FALSE, $version = NULL) { if (!in_array($select, array('auto', 'never', 'always', 'ignore'))) { return drush_set_error('DRUSH_PM_UNKNOWN_SELECT_STRATEGY', dt("Error: select strategy must be one of: auto, never, always, ignore", array())); } $project_release_info = $this->get($request); if (!$project_release_info) { return FALSE; } if ($select != 'always') { if (isset($request['version'])) { $release = $project_release_info->getSpecificRelease($request['version']); if ($release === FALSE) { return drush_set_error('DRUSH_PM_COULD_NOT_FIND_VERSION', dt("Could not locate !project version !version.", array('!project' => $request['name'], '!version' => $request['version']))); } } if ($restrict_to == 'dev') { // If you specified a specific release AND --dev, that is either // redundant (okay), or contradictory (error). if (!empty($release)) { if ($release['version_extra'] != 'dev') { return drush_set_error('DRUSH_PM_COULD_NOT_FIND_VERSION', dt("You requested both --dev and !project version !version, which is not a '-dev' release.", array('!project' => $request['name'], '!version' => $request['version']))); } } else { $release = $project_release_info->getDevRelease(); if ($release === FALSE) { return drush_set_error('DRUSH_PM_NO_DEV_RELEASE', dt('There is no development release for project !project.', array('!project' => $request['name']))); } } } // If there was no specific release requested, try to identify the most appropriate release. if (empty($release)) { $release = $project_release_info->getRecommendedOrSupportedRelease(); } if ($release) { return $release; } else { $message = dt('There are no stable releases for project !project.', array('!project' => $request['name'])); if ($select == 'never') { return drush_set_error('DRUSH_PM_NO_STABLE_RELEASE', $message); } drush_log($message, 'warning'); if ($select == 'ignore') { return NULL; } } } // At this point the only chance is to ask the user to choose a release. if ($restrict_to == 'dev') { $filter = 'dev'; } elseif ($all) { $filter = 'all'; } else { $filter = ''; } $releases = $project_release_info->filterReleases($filter, $version); $options = array(); foreach ($releases as $release) { $options[$release['version']] = array($release['version'], '-', gmdate('Y-M-d', $release['date']), '-', implode(', ', $release['release_status'])); } $choice = drush_choice($options, dt('Choose one of the available releases for !project:', array('!project' => $request['name']))); if (!$choice) { return drush_user_abort(); } return $releases[$choice]; }