diff --git a/src/Bootstrap/Drupal.php b/src/Bootstrap/Drupal.php index 664c965b2..6c99707d7 100644 --- a/src/Bootstrap/Drupal.php +++ b/src/Bootstrap/Drupal.php @@ -7,7 +7,7 @@ use Symfony\Component\Console\Output\ConsoleOutput; use Symfony\Component\HttpFoundation\Request; use Drupal\Component\FileCache\FileCacheFactory; -use Drupal\Core\Site\Settings; +use Drupal\Core\Database\Database; use Drupal\Console\Core\Style\DrupalStyle; use Drupal\Console\Core\Utils\ArgvInputReader; use Drupal\Console\Core\Bootstrap\DrupalConsoleCore; @@ -35,6 +35,11 @@ public function __construct($autoload, DrupalFinder $drupalFinder) $this->drupalFinder = $drupalFinder; } + /** + * Boot the Drupal object + * + * @return \Symfony\Component\DependencyInjection\ContainerBuilder + */ public function boot() { $output = new ConsoleOutput(); @@ -54,11 +59,8 @@ public function boot() if (!class_exists('Drupal\Core\DrupalKernel')) { $io->error('Class Drupal\Core\DrupalKernel does not exist.'); - $drupal = new DrupalConsoleCore( - $this->drupalFinder->getComposerRoot(), - $this->drupalFinder->getDrupalRoot() - ); - return $drupal->boot(); + + return $this->bootDrupalConsoleCore(); } try { @@ -161,6 +163,13 @@ public function boot() $container = $drupalKernel->getContainer(); + if ($this->shouldRedirectToDrupalCore($container)) { + $container = $this->bootDrupalConsoleCore(); + $container->set('class_loader', $this->autoload); + + return $container; + } + $container->set( 'console.root', $this->drupalFinder->getComposerRoot() @@ -187,11 +196,7 @@ public function boot() return $container; } catch (\Exception $e) { - $drupal = new DrupalConsoleCore( - $this->drupalFinder->getComposerRoot(), - $this->drupalFinder->getDrupalRoot() - ); - $container = $drupal->boot(); + $container = $this->bootDrupalConsoleCore(); $container->set('class_loader', $this->autoload); $notifyErrorCodes = [ @@ -213,4 +218,39 @@ public function boot() return $container; } } + + /** + * Builds and boot a DrupalConsoleCore object + * + * @return \Symfony\Component\DependencyInjection\ContainerBuilder + */ + protected function bootDrupalConsoleCore() + { + $drupal = new DrupalConsoleCore( + $this->drupalFinder->getComposerRoot(), + $this->drupalFinder->getDrupalRoot() + ); + + return $drupal->boot(); + } + + /** + * Validate if flow should redirect to DrupalCore + * + * @param $container + * @return bool + */ + protected function shouldRedirectToDrupalCore($container) + { + if (!Database::getConnectionInfo()) { + return true; + } + + if (!$container->has('database')) { + return true; + } + + + return !$container->get('database')->schema()->tableExists('sessions'); + } }