Exemple #1
0
/**
 * The main Drush function.
 *
 * - Runs "early" option code, if set (see global options).
 * - Parses the command line arguments, configuration files and environment.
 * - Prepares and executes a Drupal bootstrap, if possible,
 * - Dispatches the given command.
 *
 * function_exists('drush_main') may be used by modules to detect whether
 * they are being called from Drush.  See http://drupal.org/node/1181308
 * and http://drupal.org/node/827478
 *
 * @return mixed
 *   Whatever the given command returns.
 */
function drush_main()
{
    // Load Drush core include files, and parse command line arguments.
    require dirname(__FILE__) . '/includes/preflight.inc';
    if (drush_preflight_prepare() === FALSE) {
        return 1;
    }
    // Start code coverage collection.
    if ($coverage_file = drush_get_option('drush-coverage', FALSE)) {
        drush_set_context('DRUSH_CODE_COVERAGE', $coverage_file);
        xdebug_start_code_coverage(XDEBUG_CC_UNUSED | XDEBUG_CC_DEAD_CODE);
        register_shutdown_function('drush_coverage_shutdown');
    }
    // Load the global Drush configuration files, and global Drush commands.
    // Find the selected site based on --root, --uri or cwd
    // Preflight the selected site, and load any configuration and commandfiles associated with it.
    // Select and return the bootstrap class.
    $bootstrap = drush_preflight();
    // Reset our bootstrap phase to the beginning
    drush_set_context('DRUSH_BOOTSTRAP_PHASE', DRUSH_BOOTSTRAP_NONE);
    $return = '';
    if (!drush_get_error()) {
        if ($file = drush_get_option('early', FALSE)) {
            require_once $file;
            $function = 'drush_early_' . basename($file, '.inc');
            if (function_exists($function)) {
                if ($return = $function()) {
                    // If the function returns FALSE, we continue and attempt to bootstrap
                    // as normal. Otherwise, we exit early with the returned output.
                    if ($return === TRUE) {
                        $return = '';
                    }
                }
            }
        } else {
            // Do any necessary preprocessing operations on the command,
            // perhaps handling immediately.
            $command_handled = drush_preflight_command_dispatch();
            if (!$command_handled) {
                $return = $bootstrap->bootstrap_and_dispatch();
            }
        }
    }
    // TODO: Get rid of global variable access here, and just trust
    // the bootstrap object returned from drush_preflight().  This will
    // require some adjustments to Drush bootstrapping.
    // See: https://github.com/drush-ops/drush/pull/1303
    if ($bootstrap = drush_get_bootstrap_object()) {
        $bootstrap->terminate();
    }
    drush_postflight();
    // How strict are we?  If we are very strict, turn 'ok' into 'error'
    // if there are any warnings in the log.
    if ($return == 0 && drush_get_option('strict') > 1 && drush_log_has_errors()) {
        $return = 1;
    }
    // After this point the drush_shutdown function will run,
    // exiting with the correct exit code.
    return $return;
}
Exemple #2
0
 /**
  * Minimally bootstrap drush
  *
  * This is equivalent to the level DRUSH_BOOTSTRAP_NONE, as we
  * haven't run drush_bootstrap() yet. To do anything, you'll need to
  * bootstrap to some level using drush_bootstrap().
  *
  * @see drush_bootstrap()
  */
 public static function setUpBeforeClass()
 {
     parent::setUpBeforeClass();
     require_once __DIR__ . '/../../includes/preflight.inc';
     drush_preflight_prepare();
     // Need to set DRUSH_COMMAND so that drush will be called and not phpunit
     define('DRUSH_COMMAND', UNISH_DRUSH);
 }
 /**
  * @param Event $event
  */
 public static function drushCommand(Event $event)
 {
     $options = self::getOptions($event);
     $composer = $event->getComposer();
     $drushDir = realpath($composer->getConfig()->get('vendor-dir') . '/drush/drush');
     $targetDir = realpath($options['drupal-root']);
     $argv = $GLOBALS['argv'];
     // Remove the composer argument which triggered this function.
     array_shift($argv);
     $argv[] = '--root=' . $targetDir;
     $GLOBALS['argc'] = count($argv);
     $GLOBALS['argv'] = $argv;
     require $drushDir . '/includes/preflight.inc';
     if (drush_preflight_prepare() === FALSE) {
         exit(1);
     }
     $event->getIO()->write(self::drushMain());
 }
Exemple #4
0
#!/usr/bin/env php
<?php 
/**
 * @file
 * drush is a PHP script implementing a command line shell for Drupal.
 *
 * @requires PHP CLI 5.3.0, or newer.
 */
require dirname(__FILE__) . '/includes/preflight.inc';
if (drush_preflight_prepare() === FALSE) {
    exit(1);
}
exit(drush_main());
/**
 * The main Drush function.
 *
 * - Runs "early" option code, if set (see global options).
 * - Parses the command line arguments, configuration files and environment.
 * - Prepares and executes a Drupal bootstrap, if possible,
 * - Dispatches the given command.
 *
 * function_exists('drush_main') may be used by modules to detect whether
 * they are being called from Drush.  See http://drupal.org/node/1181308
 * and http://drupal.org/node/827478
 *
 * @return mixed
 *   Whatever the given command returns.
 */
function drush_main()
{
    $return = '';