Skip to content

Commit

Permalink
[console] Validate table 'sessions' exists. Fix #3572 (#3598)
Browse files Browse the repository at this point in the history
* [console] Validate table 'key_value' exists. Fix #3572

* [console] Relocate validation to shouldRedirectToDrupalCore method.

* [console] Fix typo.

* [console] Validate using only sesssions table as Drupal does.

* [console] Apply PSR-2 code style.
  • Loading branch information
jmolivas authored Nov 18, 2017
1 parent 5c34670 commit 5995a90
Showing 1 changed file with 51 additions and 11 deletions.
62 changes: 51 additions & 11 deletions src/Bootstrap/Drupal.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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 {
Expand Down Expand Up @@ -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()
Expand All @@ -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 = [
Expand All @@ -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');
}
}

0 comments on commit 5995a90

Please sign in to comment.