Esempio n. 1
0
 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;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
File: drush.php Progetto: redb/MNPP
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;
}
Esempio n. 4
0
 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;
 }
Esempio n. 5
0
/**
 * The main Drush function.
 *
 * - Parses the command line arguments, configuration files and environment.
 * - Prepares and executes a Drupal bootstrap, if possible,
 * - Dispatches the given command.
 *
 * @return
 *   Whatever the given command returns.
 */
function drush_main()
{
    $phases = _drush_bootstrap_phases(FALSE, TRUE);
    drush_set_context('DRUSH_BOOTSTRAP_PHASE', DRUSH_BOOTSTRAP_NONE);
    // We need some global options processed at this early stage. Namely --debug.
    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();
            // Process a remote command if 'remote-host' option is set.
            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;
                    // 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;
}
Esempio n. 6
0
 /**
  * Initializes Drush which boostraps Drupal core
  */
 public function initializeDrush()
 {
     define('DRUSH_BASE_PATH', sprintf('%s/../drush', $this->root));
     define('DRUSH_REQUEST_TIME', microtime(TRUE));
     require_once DRUSH_BASE_PATH . '/includes/bootstrap.inc';
     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';
     require_once DRUSH_BASE_PATH . '/includes/exec.inc';
     require_once DRUSH_BASE_PATH . '/includes/drupal.inc';
     require_once DRUSH_BASE_PATH . '/includes/output.inc';
     require_once DRUSH_BASE_PATH . '/includes/cache.inc';
     require_once DRUSH_BASE_PATH . '/includes/filesystem.inc';
     require_once DRUSH_BASE_PATH . '/includes/dbtng.inc';
     $drush_info = drush_read_drush_info();
     define('DRUSH_VERSION', $drush_info['drush_version']);
     $version_parts = explode('.', DRUSH_VERSION);
     define('DRUSH_MAJOR_VERSION', $version_parts[0]);
     define('DRUSH_MINOR_VERSION', $version_parts[1]);
     $GLOBALS['argv'][0] = 'default';
     drush_set_context('arguments', array('default', 'help'));
     drush_set_context('argc', $GLOBALS['argc']);
     drush_set_context('argv', $GLOBALS['argv']);
     drush_set_option('root', $this->root);
     // make sure the default path point to the correct instance
     $currentDirectory = getcwd();
     chdir($this->root);
     $phases = _drush_bootstrap_phases(FALSE, TRUE);
     drush_set_context('DRUSH_BOOTSTRAP_PHASE', DRUSH_BOOTSTRAP_NONE);
     // We need some global options processed at this early stage. Namely --debug.
     _drush_bootstrap_global_options();
     $return = '';
     $command_found = FALSE;
     foreach ($phases as $phase) {
         drush_bootstrap_to_phase($phase);
     }
     chdir($currentDirectory);
 }