Example #1
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;
 }
Example #2
0
 function add_logger()
 {
     // If we're running on Drupal 8 or later, we provide a logger which will send
     // output to drush_log(). This should catch every message logged through every
     // channel.
     $container = \Drupal::getContainer();
     $parser = $container->get('logger.log_message_parser');
     $drushLogger = \Drush::logger();
     $logger = new \Drush\Log\DrushLog($parser, $drushLogger);
     $container->get('logger.factory')->addLogger($logger);
 }
Example #3
0
 /**
  * Validate the DRUSH_BOOTSTRAP_DRUPAL_ROOT phase.
  *
  * In this function, we will check if a valid Drupal directory is available.
  * We also determine the value that will be stored in the DRUSH_DRUPAL_ROOT
  * context and DRUPAL_ROOT constant if it is considered a valid option.
  */
 function bootstrap_drupal_root_validate()
 {
     $drupal_root = \Drush::bootstrapManager()->getRoot();
     if (empty($drupal_root)) {
         return drush_bootstrap_error('DRUSH_NO_DRUPAL_ROOT', dt("A Drupal installation directory could not be found"));
     }
     if (!($signature = drush_valid_root($drupal_root))) {
         return drush_bootstrap_error('DRUSH_INVALID_DRUPAL_ROOT', dt("The directory !drupal_root does not contain a valid Drupal installation", array('!drupal_root' => $drupal_root)));
     }
     $version = drush_drupal_version($drupal_root);
     $major_version = drush_drupal_major_version($drupal_root);
     if ($major_version <= 6) {
         return drush_set_error('DRUSH_DRUPAL_VERSION_UNSUPPORTED', dt('Drush !drush_version does not support Drupal !major_version.', array('!drush_version' => \Drush::getMajorVersion(), '!major_version' => $major_version)));
     }
     drush_bootstrap_value('drupal_root', $drupal_root);
     define('DRUSH_DRUPAL_SIGNATURE', $signature);
     return TRUE;
 }
Example #4
0
 /**
  * Parse Drupal core status.
  *
  * @return DrupalCoreStatus
  *   The parsed Drupal core status information fetched via 'drush core-status').
  *
  * @throws \Exception
  */
 protected static function parseStatus()
 {
     // Load from cache (if exists).
     if ($status = static::parseStatusCache()) {
         return $status;
     }
     // Custom output capture to ensure no output at all.
     ob_start();
     // Load Drupal core status via Drush.
     $output = Drush::exec()->arg('core-status')->option('format=json')->run()->getMessage();
     // End custom output capture.
     ob_end_clean();
     // Unable to parse Drupal core status JSON.
     if (!($status = @json_decode($output))) {
         print $output;
         throw new \Exception(__CLASS__ . ' - Unable to parse Drupal status.');
     }
     // Cast status.
     $status = new DrupalCoreStatus((object) $status);
     // Save to cache (if bootstrapped).
     if (static::statusIsBootstrapped($status)) {
         static::parseStatusCache($status);
     }
     return $status;
 }
Example #5
0
 function bootstrap_drupal_full()
 {
     drush_log(dt('About to bootstrap the Drupal 8 Kernel.'), LogLevel::DEBUG);
     // TODO: do we need to do ob_start any longer?
     if (!drush_get_context('DRUSH_QUIET', FALSE)) {
         ob_start();
     }
     $this->kernel->invalidateContainer();
     $this->kernel->boot();
     $this->kernel->prepareLegacyRequest($this->request);
     if (!drush_get_context('DRUSH_QUIET', FALSE)) {
         ob_end_clean();
     }
     drush_log(dt('Finished bootstraping the Drupal 8 Kernel.'), LogLevel::DEBUG);
     parent::bootstrap_drupal_full();
     // Get a list of the modules to ignore
     $ignored_modules = drush_get_option_list('ignored-modules', array());
     // We have to get the service command list from the container, because
     // it is constructed in an indirect way during the container initialization.
     // The upshot is that the list of console commands is not available
     // until after $kernel->boot() is called.
     $container = \Drupal::getContainer();
     $serviceCommandlist = $container->get('drush.service.consolecommands');
     foreach ($serviceCommandlist->getCommandList() as $command) {
         if (!$this->commandIgnored($command, $ignored_modules)) {
             drush_log(dt('Add a command: !name', ['!name' => $command->getName()]), LogLevel::DEBUG);
             drush_add_command_to_application(\Drush::getContainer(), $command);
         }
     }
     // Do the same thing with the annotation commands.
     $serviceCommandlist = $container->get('drush.service.consolidationcommands');
     foreach ($serviceCommandlist->getCommandList() as $commandhandler) {
         if (!$this->commandIgnored($commandhandler, $ignored_modules)) {
             drush_log(dt('Add a commandhandler: !name', ['!name' => get_class($commandhandler)]), LogLevel::DEBUG);
             drush_create_commands_from_command_instance(\Drush::getContainer(), $commandhandler);
         }
     }
 }