diff --git a/core/core.services.yml b/core/core.services.yml index d9e265f..b98dcff 100644 --- a/core/core.services.yml +++ b/core/core.services.yml @@ -79,8 +79,8 @@ services: class: Drupal\Core\Config\ConfigInstaller arguments: ['@config.factory', '@config.storage', '@config.typed', '@config.manager', '@event_dispatcher'] config.storage: - alias: config.storage.uncached - config.storage.uncached: + alias: config.storage.active + config.storage.active: class: Drupal\Core\Config\DatabaseStorage arguments: ['@database', 'config'] config.storage.staging: diff --git a/core/includes/install.inc b/core/includes/install.inc index ab818ba..358b259 100644 --- a/core/includes/install.inc +++ b/core/includes/install.inc @@ -479,6 +479,8 @@ function drupal_install_config_directories() { ); // Rewrite settings.php, which also sets the value as global variable. drupal_rewrite_settings($settings); + + \Drupal::service('config.storage.active')->createStorage(); } // Ensure the config directories exist or can be created, and are writable. diff --git a/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php b/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php index bf65660..1df8f07 100644 --- a/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php +++ b/core/lib/Drupal/Core/Config/BootstrapConfigStorageFactory.php @@ -27,8 +27,7 @@ public static function get() { return call_user_func($drupal_bootstrap_config_storage); } else { - $storage = new DatabaseStorage(Database::getConnection(), 'config'); - return $storage->createStorage(); + return new DatabaseStorage(Database::getConnection(), 'config'); } } diff --git a/core/lib/Drupal/Core/Config/DatabaseStorage.php b/core/lib/Drupal/Core/Config/DatabaseStorage.php index f649682..a2ba289 100644 --- a/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ b/core/lib/Drupal/Core/Config/DatabaseStorage.php @@ -57,7 +57,12 @@ public function __construct(Connection $connection, $table, array $options = arr * {@inheritdoc} */ public function createStorage() { - $this->ensureTableExists(); + try { + $this->connection->schema()->createTable($this->table, static::schemaDefinition()); + } + catch (\Exception $e) { + throw new StorageException($e->getMessage(), NULL, $e); + } return $this; } @@ -133,37 +138,9 @@ public function write($name, array $data) { } /** - * Check if the config table exists and create it if not. - * - * @return bool - * TRUE if the table was created, FALSE otherwise. - * - * @throws \Drupal\Core\Config\StorageException - * If a database error occurs. - */ - protected function ensureTableExists() { - try { - if (!$this->connection->schema()->tableExists($this->table)) { - $this->connection->schema()->createTable($this->table, static::schemaDefinition()); - return TRUE; - } - } - // If another process has already created the config table, attempting to - // recreate it will throw an exception. In this case just catch the - // exception and do nothing. - catch (SchemaObjectExistsException $e) { - return TRUE; - } - catch (\Exception $e) { - throw new StorageException($e->getMessage(), NULL, $e); - } - return FALSE; - } - - /** * Defines the schema for the configuration table. */ - public static function schemaDefinition() { + protected function schemaDefinition() { $schema = array( 'description' => 'The base table for configuration data.', 'fields' => array( diff --git a/core/lib/Drupal/Core/Config/StorageInterface.php b/core/lib/Drupal/Core/Config/StorageInterface.php index 929ed33..7d5e0fc 100644 --- a/core/lib/Drupal/Core/Config/StorageInterface.php +++ b/core/lib/Drupal/Core/Config/StorageInterface.php @@ -16,13 +16,12 @@ interface StorageInterface { /** - * Ensure that the back-end for this storage exists (idempotent). + * Creates the storage for this backend. * - * @return \Drupal\Core\Config\StorageInterface - * The called object. + * @return $this * * @throws \Drupal\Core\Config\StorageException - * If the back-end storage does not exist and cannot be created. + * If the storage cannot be created. */ public function createStorage(); diff --git a/core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php b/core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php index 9a47b1d..4239d64 100644 --- a/core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php +++ b/core/lib/Drupal/Core/DependencyInjection/UpdateServiceProvider.php @@ -29,9 +29,10 @@ public function register(ContainerBuilder $container) { ->register('lock', 'Drupal\Core\Lock\NullLockBackend'); // Prevent config from being accessed via a cache wrapper by removing - // any existing definition and setting an alias to the un-cached service. + // any existing definition and setting an alias to the actual storage. $container->removeDefinition('config.storage'); - $container->setAlias('config.storage', 'config.storage.uncached'); + $container->setAlias('config.storage', 'config.storage.active'); + $container->register('module_handler', 'Drupal\Core\Extension\UpdateModuleHandler') ->addArgument('%container.modules%'); $container diff --git a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php index 1c111b9..4535358 100644 --- a/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php +++ b/core/modules/simpletest/lib/Drupal/simpletest/DrupalUnitTestBase.php @@ -138,6 +138,9 @@ protected function setUp() { \Drupal::state()->set('system.module.files', $this->moduleFiles); \Drupal::state()->set('system.theme.files', $this->themeFiles); + // Create the active configuration storage (required to boot DrupalKernel). + $this->container->get('config.storage.active')->createStorage(); + // Bootstrap the kernel. // No need to dump it; this test runs in-memory. $this->kernel = new DrupalKernel('unit_testing', drupal_classloader(), FALSE); @@ -225,7 +228,7 @@ public function containerBuild(ContainerBuilder $container) { $container->register('cache_factory', 'Drupal\Core\Cache\MemoryBackendFactory'); $container - ->register('config.storage.uncached', 'Drupal\Core\Config\DatabaseStorage') + ->register('config.storage.active', 'Drupal\Core\Config\DatabaseStorage') ->addArgument(Database::getConnection()) ->addArgument('config');