123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256 |
- <?php
- if (!drush_verify_cli()) {
- die('drush is designed to run via the command line.');
- }
- define('DRUSH_MINIMUM_PHP', '5.2.0');
- if (version_compare(phpversion(), DRUSH_MINIMUM_PHP) < 0) {
- die('Your command line PHP installation is too old. Drush requires at least PHP ' . DRUSH_MINIMUM_PHP . "\n");
- }
- define('DRUSH_BASE_PATH', dirname(__FILE__));
- define('DRUSH_REQUEST_TIME', microtime(TRUE));
- require_once DRUSH_BASE_PATH . '/includes/environment.inc';
- require_once DRUSH_BASE_PATH . '/includes/command.inc';
- require_once DRUSH_BASE_PATH . '/includes/drush.inc';
- require_once DRUSH_BASE_PATH . '/includes/backend.inc';
- require_once DRUSH_BASE_PATH . '/includes/batch.inc';
- require_once DRUSH_BASE_PATH . '/includes/context.inc';
- require_once DRUSH_BASE_PATH . '/includes/sitealias.inc';
- drush_set_context('argc', $GLOBALS['argc']);
- drush_set_context('argv', $GLOBALS['argv']);
- set_error_handler('drush_error_handler');
- register_shutdown_function('drush_shutdown');
- exit(drush_main());
- function drush_verify_cli() {
- return (php_sapi_name() == 'cli' || (is_numeric($_SERVER['argc']) && $_SERVER['argc'] > 0));
- }
- function drush_main() {
- $phases = _drush_bootstrap_phases(FALSE, TRUE);
- drush_set_context('DRUSH_BOOTSTRAP_PHASE', DRUSH_BOOTSTRAP_NONE);
-
- drush_parse_args();
- _drush_bootstrap_global_options();
- $return = '';
- $command_found = FALSE;
- foreach ($phases as $phase) {
- if (drush_bootstrap_to_phase($phase)) {
- $command = drush_parse_command();
-
- if (drush_remote_command()) {
- $command_found = TRUE;
- break;
- }
- 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;
-
- $return = drush_dispatch($command);
-
- 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) {
-
- $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)));
- }
-
- $errors = drush_get_context('DRUSH_BOOTSTRAP_ERRORS', array());
- foreach ($errors as $code => $message) {
- drush_set_error($code, $message);
- }
- }
-
- drush_set_context("DRUSH_EXECUTION_COMPLETED", TRUE);
-
-
- return $return;
- }
- function drush_shutdown() {
-
- 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']));
- }
-
-
-
-
- drush_set_error("DRUSH_NOT_COMPLETED", dt("Drush command terminated abnormally due to an unrecoverable error.!message", array('!message' => $php_error_message)));
-
- _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 (drush_get_context('DRUSH_PIPE')) {
- drush_pipe_output();
- }
-
-
-
-
-
-
- register_shutdown_function('drush_return_status');
- }
- function drush_return_status() {
- exit((drush_get_error()) ? DRUSH_FRAMEWORK_ERROR : DRUSH_SUCCESS);
- }
- 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;
- }
|