/** * 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(); }
/** * Shutdown function for use while Drupal is bootstrapping and to return any * registered errors. * * The shutdown command checks whether certain options are set to reliably * detect and log some common Drupal initialization errors. * * If the command is being executed with the --backend option, the script * will return a json string containing the options and log information * used by the script. * * The command will exit with '1' if it was succesfully executed, and the * result of drush_get_error() if it wasn't. */ function drush_shutdown() { // Mysteriously make $user available during sess_write(). Avoids a NOTICE. global $user; if (!drush_get_context('DRUSH_EXECUTION_COMPLETED', FALSE)) { // We did not reach the end of the drush_main function, // this generally means somewhere in the code a call to exit(), // was made. We catch this, so that we can trigger an error in // those cases. drush_set_error("DRUSH_NOT_COMPLETED", dt("Drush command could not be completed.")); } $phase = drush_get_context('DRUSH_BOOTSTRAP_PHASE'); if (drush_get_context('DRUSH_BOOTSTRAPPING')) { switch ($phase) { case DRUSH_BOOTSTRAP_DRUPAL_FULL: ob_end_clean(); _drush_log_drupal_messages(); drush_set_error('DRUSH_DRUPAL_BOOTSTRAP_ERROR'); break; } } if (drush_get_context('DRUSH_BACKEND')) { drush_backend_output(); } elseif (drush_get_context('DRUSH_QUIET')) { ob_end_clean(); } // If we are in pipe mode, emit the compact representation of the command, if available. if (drush_get_context('DRUSH_PIPE')) { drush_pipe_output(); } exit(drush_get_error() ? DRUSH_FRAMEWORK_ERROR : DRUSH_SUCCESS); }
/** * Shutdown function for use while Drupal is bootstrapping and to return any * registered errors. * * The shutdown command checks whether certain options are set to reliably * detect and log some common Drupal initialization errors. * * If the command is being executed with the --backend option, the script * will return a json string containing the options and log information * used by the script. * * The command will exit with '1' if it was successfully executed, and the * result of drush_get_error() if it wasn't. */ function drush_shutdown() { // Mysteriously make $user available during sess_write(). Avoids a NOTICE. global $user; if (!drush_get_context('DRUSH_EXECUTION_COMPLETED', FALSE) && !drush_get_context('DRUSH_USER_ABORT', FALSE)) { $php_error_message = ''; if ($error = error_get_last()) { $php_error_message = "\n" . dt('Error: !message in !file, line !line', array('!message' => $error['message'], '!file' => $error['file'], '!line' => $error['line'])); } // We did not reach the end of the drush_main function, // this generally means somewhere in the code a call to exit(), // was made. We catch this, so that we can trigger an error in // those cases. drush_set_error("DRUSH_NOT_COMPLETED", dt("Drush command terminated abnormally due to an unrecoverable error.!message", array('!message' => $php_error_message))); // Attempt to give the user some advice about how to fix the problem _drush_postmortem(); } $phase = drush_get_context('DRUSH_BOOTSTRAP_PHASE'); if (drush_get_context('DRUSH_BOOTSTRAPPING')) { switch ($phase) { case DRUSH_BOOTSTRAP_DRUPAL_FULL: ob_end_clean(); _drush_log_drupal_messages(); drush_set_error('DRUSH_DRUPAL_BOOTSTRAP_ERROR'); break; } } if (drush_get_context('DRUSH_BACKEND')) { drush_backend_output(); } elseif (drush_get_context('DRUSH_QUIET')) { ob_end_clean(); } // If we are in pipe mode, emit the compact representation of the command, if available. if (drush_get_context('DRUSH_PIPE')) { drush_pipe_output(); } /** * For now, drush skips end of page processing on D7. Doing so could write * cache entries to module_implements and lookup_cache that don't match web requests. */ // if (drush_drupal_major_version() >= 7 && function_exists('drupal_page_footer')) { // drupal_page_footer(); // } // this way drush_return_status will always be the last shutdown function (unless other shutdown functions register shutdown functions...) // and won't prevent other registered shutdown functions (IE from numerous cron methods) from running by calling exit() before they get a chance. register_shutdown_function('drush_return_status'); }
/** * Shutdown function for use while Drupal is bootstrapping and to return any * registered errors. * * The shutdown command checks whether certain options are set to reliably * detect and log some common Drupal initialization errors. * * If the command is being executed with the --backend option, the script * will return a json string containing the options and log information * used by the script. * * The command will exit with '1' if it was succesfully executed, and the * result of drush_get_error() if it wasn't. */ function drush_shutdown() { // Mysteriously make $user available during sess_write(). Avoids a NOTICE. global $user; if (!drush_get_context('DRUSH_EXECUTION_COMPLETED', FALSE)) { // We did not reach the end of the drush_main function, // this generally means somewhere in the code a call to exit(), // was made. We catch this, so that we can trigger an error in // those cases. drush_set_error("DRUSH_NOT_COMPLETED", dt("Drush command could not be completed.")); } $phase = drush_get_context('DRUSH_BOOTSTRAP_PHASE'); if (drush_get_context('DRUSH_BOOTSTRAPPING')) { switch ($phase) { case DRUSH_BOOTSTRAP_DRUPAL_FULL: ob_end_clean(); _drush_log_drupal_messages(); drush_set_error('DRUSH_DRUPAL_BOOTSTRAP_ERROR'); break; } } if (drush_get_context('DRUSH_BACKEND')) { drush_backend_output(); } elseif (drush_get_context('DRUSH_QUIET')) { ob_end_clean(); } // If we are in pipe mode, emit the compact representation of the command, if available. if (drush_get_context('DRUSH_PIPE')) { drush_pipe_output(); } // this way drush_return_status will always be the last shutdown function (unless other shutdown functions register shutdown functions...) // and won't prevent other registered shutdown functions (IE from numerous cron methods) from running by calling exit() before they get a chance. register_shutdown_function('drush_return_status'); }