Skip to content

Commit

Permalink
Issue #3103529 by alexpott, mcdruid, Chris Burge, greg.1.anderson, rf…
Browse files Browse the repository at this point in the history
…ay, catch, anavarre, Gábor Hojtsy, jungle: Drupal 8.8.1+ and 9 can fail to install in the web browser due to cache pollution
  • Loading branch information
alexpott committed Mar 17, 2020
1 parent c305eed commit 424781f
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 5 deletions.
14 changes: 14 additions & 0 deletions lib/Drupal/Core/DrupalKernel.php
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,20 @@ public function discoverServiceProviders() {
// Retrieve enabled modules and register their namespaces.
if (!isset($this->moduleList)) {
$extensions = $this->getConfigStorage()->read('core.extension');
// If core.extension configuration does not exist and we're not in the
// installer itself, then we need to put the kernel into a pre-installer
// mode. The container should not be dumped because Drupal is yet to be
// installed. The installer service provider is registered to ensure that
// cache and other automatically created tables are not created if
// database settings are available. None of this is required when the
// installer is running because the installer has its own kernel and
// manages the addition of its own service providers.
// @see install_begin_request()
if ($extensions === FALSE && !InstallerKernel::installationAttempted()) {
$this->allowDumping = FALSE;
$this->containerNeedsDumping = FALSE;
$GLOBALS['conf']['container_service_providers']['InstallerServiceProvider'] = 'Drupal\Core\Installer\InstallerServiceProvider';
}
$this->moduleList = isset($extensions['module']) ? $extensions['module'] : [];
}
$module_filenames = $this->getModuleFileNames();
Expand Down
6 changes: 6 additions & 0 deletions modules/simpletest/src/KernelTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,9 @@ protected function setUp() {
if (file_exists($directory . '/settings.testing.php')) {
Settings::initialize(DRUPAL_ROOT, $site_path, $class_loader);
}
// Set the module list upfront to avoid setting the kernel into the
// pre-installer mode.
$this->kernel->updateModules([], []);
$this->kernel->boot();

// Ensure database install tasks have been run.
Expand All @@ -231,6 +234,9 @@ protected function setUp() {
// prevents any services created during the first boot from having stale
// database connections, for example, \Drupal\Core\Config\DatabaseStorage.
$this->kernel->shutdown();
// Set the module list upfront to avoid setting the kernel into the
// pre-installer mode.
$this->kernel->updateModules([], []);
$this->kernel->boot();

// Save the original site directory path, so that extensions in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ protected function prepareEnvironment() {
mkdir($this->settings['settings']['config_sync_directory']->value, 0777, TRUE);
}

/**
* Visits the interactive installer.
*/
protected function visitInstaller() {
// Should redirect to the installer.
$this->drupalGet($GLOBALS['base_url']);
// Ensure no database tables have been created yet.
$this->assertSame([], Database::getConnection()->schema()->findTables('%'));
$this->assertSession()->addressEquals($GLOBALS['base_url'] . '/core/install.php');
}

/**
* {@inheritdoc}
*/
Expand Down
11 changes: 6 additions & 5 deletions tests/Drupal/KernelTests/KernelTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -348,11 +348,12 @@ private function bootKernel() {
// Bootstrap the kernel. Do not use createFromRequest() to retain Settings.
$kernel = new DrupalKernel('testing', $this->classLoader, FALSE);
$kernel->setSitePath($this->siteDirectory);
// Boot a new one-time container from scratch. Ensure to set the module list
// upfront to avoid a subsequent rebuild.
if ($modules && $extensions = $this->getExtensionsForModules($modules)) {
$kernel->updateModules($extensions, $extensions);
}
// Boot a new one-time container from scratch. Set the module list upfront
// to avoid a subsequent rebuild or setting the kernel into the
// pre-installer mode.
$extensions = $modules ? $this->getExtensionsForModules($modules) : [];
$kernel->updateModules($extensions, $extensions);

// DrupalKernel::boot() is not sufficient as it does not invoke preHandle(),
// which is required to initialize legacy global variables.
$request = Request::create('/');
Expand Down

0 comments on commit 424781f

Please sign in to comment.