$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_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 ocurred in the bootstrap phases. $errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', array()); foreach ($errors as $code => $message) { drush_set_error($code, $message); } } // We set this context to let the shutdown function know we reached the end of drush_main(); drush_set_context("DRUSH_EXECUTION_COMPLETED", TRUE); // After this point the drush_shutdown function will run, // exiting with the correct exit code. 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; 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; } /** * This is tweaked to not use stderr. **/ /** * Display the log message * * By default, only warnings and errors will be displayed, if 'verbose' is specified, it will also display notices. * * @param * The associative array for the entry. * * @return * False in case of an error or failed type, True in all other cases. */ function _drushd_print_log($entry) { if (drush_get_context('DRUSH_NOCOLOR')) { $red = "[%s]"; $yellow = "[%s]"; $green = "[%s]"; } else { $red = "\033[31;40m\033[1m[%s]\033[0m"; $yellow = "\033[1;33;40m\033[1m[%s]\033[0m"; $green = "\033[1;32;40m\033[1m[%s]\033[0m"; } $verbose = drush_get_context('DRUSH_VERBOSE'); $debug = drush_get_context('DRUSH_DEBUG'); $return = TRUE; switch ($entry['type']) { case 'warning' : case 'cancel' : $type_msg = sprintf($yellow, $entry['type']); break; case 'failed' : case 'error' : $type_msg = sprintf($red, $entry['type']); $return = FALSE; break; case 'ok' : case 'completed' : case 'success' : case 'status': $type_msg = sprintf($green, $entry['type']); break; case 'notice' : case 'message' : case 'info' : if (!$verbose) { // print nothing. exit cleanly. return TRUE; } $type_msg = sprintf("[%s]", $entry['type']); break; default : if (!$debug) { // print nothing. exit cleanly. return TRUE; } $type_msg = sprintf("[%s]", $entry['type']); break; } // When running in backend mode, log messages are not displayed, as they will // be returned in the JSON encoded associative array. In quiet mode, we // just drop log messages. if (drush_get_context('DRUSH_BACKEND') || drush_get_context('DRUSH_QUIET')) { return $return; } $columns = drush_get_context('DRUSH_COLUMNS', 80); $width[1] = 11; // Append timer and memory values. if ($debug) { $timer = sprintf('[%s sec, %s]', round($entry['timestamp']-DRUSH_REQUEST_TIME, 2), drush_format_size($entry['memory'])); $entry['message'] = $entry['message'] . ' ' . $timer; } $width[0] = ($columns - 11); $format = sprintf("%%-%ds%%%ds", $width[0], $width[1]); // Place the status message right aligned with the top line of the error message. $message = wordwrap($entry['message'], $width[0]); $lines = explode("\n", $message); $lines[0] = sprintf($format, $lines[0], $type_msg); $message = implode("\n", $lines); drush_print($message, 0); return $return; }