diff -u b/core/includes/bootstrap.inc b/core/includes/bootstrap.inc --- b/core/includes/bootstrap.inc +++ b/core/includes/bootstrap.inc @@ -2437,13 +2437,16 @@ // requests. $container = new ContainerBuilder(); - $container->register('config.storage.file', 'Drupal\Core\Config\FileStorage'); + $container->register('config.storage.active', 'Drupal\Core\Config\FileStorage') + ->addArgument(config_get_config_directory()); + $container->register('config.storage.staging', 'Drupal\Core\Config\FileStorage') + ->addArgument(config_get_config_directory(CONFIG_STAGING_DIRECTORY)); $container->register('config.cache') ->setFactoryClass('Drupal\Core\Cache\CacheFactory') ->setFactoryMethod('get') ->addArgument('config'); - $container->register('config.storage.active', 'Drupal\Core\Config\CachedStorage') - ->addArgument(new Reference('config.storage.file')) + $container->register('config.storage', 'Drupal\Core\Config\CachedStorage') + ->addArgument(new Reference('config.storage.active')) ->addArgument(new Reference('config.cache')); $container->register('config.subscriber.globalconf', 'Drupal\Core\EventSubscriber\ConfigGlobalOverrideSubscriber'); diff -u b/core/includes/config.inc b/core/includes/config.inc --- b/core/includes/config.inc +++ b/core/includes/config.inc @@ -22,7 +22,7 @@ $config_dir = drupal_get_path($type, $name) . '/config'; if (is_dir($config_dir)) { $source_storage = new FileStorage($config_dir); - $target_storage = drupal_container()->get('config.storage.active'); + $target_storage = drupal_container()->get('config.storage'); $null_storage = new NullStorage(); // Upon installation, only new config objects need to be created. @@ -45,7 +45,7 @@ * @see Drupal\Core\Config\StorageInterface::listAll() */ function config_get_storage_names_with_prefix($prefix = '') { - return drupal_container()->get('config.storage.active')->listAll($prefix); + return drupal_container()->get('config.storage')->listAll($prefix); } /** @@ -137,7 +137,7 @@ function config_import() { // Retrieve a list of differences between staging and the active store. $source_storage = drupal_container()->get('config.storage.staging'); - $target_storage = drupal_container()->get('config.storage.active'); + $target_storage = drupal_container()->get('config.storage'); $config_changes = config_sync_get_changes($source_storage, $target_storage); if (empty($config_changes)) { @@ -217,7 +217,7 @@ */ function config_export() { // Retrieve a list of differences between the active store and staging. - $source_storage = drupal_container()->get('config.storage.active'); + $source_storage = drupal_container()->get('config.storage'); $target_storage = drupal_container()->get('config.storage.staging'); $config_changes = config_sync_get_changes($source_storage, $target_storage); diff -u b/core/includes/install.core.inc b/core/includes/install.core.inc --- b/core/includes/install.core.inc +++ b/core/includes/install.core.inc @@ -302,9 +302,9 @@ $container->register('dispatcher', 'Symfony\Component\EventDispatcher\EventDispatcher'); - $container->register('config.storage.active', 'Drupal\Core\Config\InstallStorage'); + $container->register('config.storage', 'Drupal\Core\Config\InstallStorage'); $container->register('config.factory', 'Drupal\Core\Config\ConfigFactory') - ->addArgument(new Reference('config.storage.active')) + ->addArgument(new Reference('config.storage')) ->addArgument(new Reference('dispatcher')); drupal_container($container); diff -u b/core/includes/install.inc b/core/includes/install.inc --- b/core/includes/install.inc +++ b/core/includes/install.inc @@ -313,9 +313,10 @@ if (!isset($config_directories[$type])) { return FALSE; } - // config_get_config_directory() throws an exception when there is a prepared - // settings.php that defines $config_directories already and the directories - // do not exist yet. + // config_get_config_directory() throws an exception when the $type passed + // it doesn't exist yet in $config_directories. This can happen if there is + // a prepared settings.php that defines $config_directories already and the + // directories do not exist yet. try { $config_directory = config_get_config_directory($type); if (is_dir($config_directory) && is_writable($config_directory)) { diff -u b/core/includes/module.inc b/core/includes/module.inc --- b/core/includes/module.inc +++ b/core/includes/module.inc @@ -616,7 +616,7 @@ $module_list = array_keys($module_list); } - $storage = drupal_container()->get('config.storage.active'); + $storage = drupal_container()->get('config.storage'); foreach ($module_list as $module) { // Uninstall the module. module_load_install($module); diff -u b/core/lib/Drupal/Core/Config/CachedStorage.php b/core/lib/Drupal/Core/Config/CachedStorage.php --- b/core/lib/Drupal/Core/Config/CachedStorage.php +++ b/core/lib/Drupal/Core/Config/CachedStorage.php @@ -10,34 +10,27 @@ use Drupal\Core\Cache\CacheBackendInterface; /** - * Defines the Cache storage controller. + * Defines the cached storage controller. * - * This storage controller essentially just bridges the configuration system - * storage to a backend of the cache system. All StorageInterface method calls - * are forwarded to the corresponding CacheBackendInterface methods. - * - * @see Drupal\Core\Cache\CacheBackendInterface - * - * While this causes a level of indirection and the functionality could - * technically be embedded into a configuration storage controller directly, - * a separate bridge is architecturally cleaner and also allows for alternative - * setups. - * - * By default, the configuration system uses this controller in the - * CachedFileStorage implementation. - * - * @see Drupal\Core\Config\CachedFileStorage + * The class gets another storage and a cache backend injected. It tries to + * read from the cache and if it misses, delegates the read. It also handles + * cache invalidation. */ class CachedStorage implements StorageInterface { - protected $options; + /** + * The storage to be cached. + * + * @var Drupal\Core\Config\StorageInterface + */ + protected $delegate; /** * The instantiated Cache backend. * * @var Drupal\Core\Cache\CacheBackendInterface */ - protected $storage; + protected $cache; /** * Implements Drupal\Core\Config\StorageInterface::__construct(). diff -u b/core/lib/Drupal/Core/Config/DatabaseStorage.php /dev/null --- b/core/lib/Drupal/Core/Config/DatabaseStorage.php +++ /dev/null @@ -1,153 +0,0 @@ - 'default', - 'target' => 'default', - ); - $this->options = $options; - } - - /** - * Returns the database connection to use. - */ - protected function getConnection() { - return Database::getConnection($this->options['target'], $this->options['connection']); - } - - /** - * Implements Drupal\Core\Config\StorageInterface::exists(). - */ - public function exists($name) { - return (bool) $this->getConnection()->queryRange('SELECT 1 FROM {config} WHERE name = :name', 0, 1, array( - ':name' => $name, - ), $this->options)->fetchField(); - } - - /** - * Implements Drupal\Core\Config\StorageInterface::read(). - * - * @throws PDOException - * @throws Drupal\Core\Database\DatabaseExceptionWrapper - * Only thrown in case $this->options['throw_exception'] is TRUE. - */ - public function read($name) { - $data = FALSE; - // There are situations, like in the installer, where we may attempt a - // read without actually having the database available. In this case, - // catch the exception and just return an empty array so the caller can - // handle it if need be. - try { - $raw = $this->getConnection()->query('SELECT data FROM {config} WHERE name = :name', array(':name' => $name), $this->options)->fetchField(); - if ($raw !== FALSE) { - $data = $this->decode($raw); - } - } - catch (Exception $e) { - } - return $data; - } - - /** - * Implements Drupal\Core\Config\StorageInterface::write(). - * - * @throws PDOException - * - * @todo Ignore slave targets for data manipulation operations. - */ - public function write($name, array $data) { - $data = $this->encode($data); - $options = array('return' => Database::RETURN_AFFECTED) + $this->options; - return (bool) $this->getConnection()->merge('config', $options) - ->key(array('name' => $name)) - ->fields(array('data' => $data)) - ->execute(); - } - - /** - * Implements Drupal\Core\Config\StorageInterface::delete(). - * - * @throws PDOException - * - * @todo Ignore slave targets for data manipulation operations. - */ - public function delete($name) { - $options = array('return' => Database::RETURN_AFFECTED) + $this->options; - return (bool) $this->getConnection()->delete('config', $options) - ->condition('name', $name) - ->execute(); - } - - - /** - * Implements Drupal\Core\Config\StorageInterface::rename(). - * - * @throws PDOException - */ - public function rename($name, $new_name) { - $options = array('return' => Database::RETURN_AFFECTED) + $this->options; - return (bool) $this->getConnection()->update('config', $options) - ->fields(array('name' => $new_name)) - ->condition('name', $name) - ->execute(); - } - - /** - * Implements Drupal\Core\Config\StorageInterface::encode(). - */ - public static function encode($data) { - return serialize($data); - } - - /** - * Implements Drupal\Core\Config\StorageInterface::decode(). - * - * @throws ErrorException - * unserialize() triggers E_NOTICE if the string cannot be unserialized. - */ - public static function decode($raw) { - $data = @unserialize($raw); - return is_array($data) ? $data : FALSE; - } - - /** - * Implements Drupal\Core\Config\StorageInterface::listAll(). - * - * @throws PDOException - * @throws Drupal\Core\Database\DatabaseExceptionWrapper - * Only thrown in case $this->options['throw_exception'] is TRUE. - */ - public function listAll($prefix = '') { - return $this->getConnection()->query('SELECT name FROM {config} WHERE name LIKE :name', array( - ':name' => db_like($prefix) . '%', - ), $this->options)->fetchCol(); - } -} diff -u b/core/lib/Drupal/Core/Config/FileStorage.php b/core/lib/Drupal/Core/Config/FileStorage.php --- b/core/lib/Drupal/Core/Config/FileStorage.php +++ b/core/lib/Drupal/Core/Config/FileStorage.php @@ -15,21 +15,16 @@ class FileStorage implements StorageInterface { /** - * Configuration options for this storage controller. + * The filesystem path for configuration objects. * - * - directory: The filesystem path for configuration objects. - * - * @var array + * @var string */ - protected $options; + protected $directory = ''; /** * Implements Drupal\Core\Config\StorageInterface::__construct(). */ - public function __construct($directory = '') { - if (empty($directory)) { - $directory = config_get_config_directory(); - } + public function __construct($directory) { $this->directory = $directory; } diff -u b/core/lib/Drupal/Core/Config/InstallStorage.php b/core/lib/Drupal/Core/Config/InstallStorage.php --- b/core/lib/Drupal/Core/Config/InstallStorage.php +++ b/core/lib/Drupal/Core/Config/InstallStorage.php @@ -15,19 +15,9 @@ class InstallStorage extends FileStorage { /** - * Configuration options for this storage controller. - * - * @var array - */ - protected $options; - - /** - * Implements Drupal\Core\Config\StorageInterface::__construct(). + * Overrides Drupal\Core\Config\FileStorage::__construct(). */ - public function __construct(array $options = array()) { - // Intentionally not calling FileStorage's constructor, since that calls - // into config_get_config_directory(), which is not functional yet. - $this->options = $options; + public function __construct() { } /** @@ -73,7 +63,7 @@ * @throws Drupal\Core\Config\StorageException */ public function write($name, array $data) { - throw new StorageException('Write operations are not allowed.'); + throw new StorageException('Write operation is not allowed during install.'); } /** @@ -82,7 +72,7 @@ * @throws Drupal\Core\Config\StorageException */ public function delete($name) { - throw new StorageException('Write operations are not allowed.'); + throw new StorageException('Delete operation is not allowed during install.'); } /** @@ -91,7 +81,7 @@ * @throws Drupal\Core\Config\StorageException */ public function rename($name, $new_name) { - throw new StorageException('Write operations are not allowed.'); + throw new StorageException('Rename operation is not allowed during install.'); } /** @@ -101,5 +91,5 @@ */ public function listAll($prefix = '') { - throw new StorageException('List operation is not supported.'); + throw new StorageException('List operation is not allowed during install.'); } } reverted: --- b/core/lib/Drupal/Core/CoreBundle.php +++ a/core/lib/Drupal/Core/CoreBundle.php @@ -51,8 +51,6 @@ ->setFactoryClass('Drupal\Core\Database\Database') ->setFactoryMethod('getConnection') ->addArgument('slave'); - $container->register('config.storage.staging', 'Drupal\Core\Config\FileStorage') - ->addArgument(config_get_config_directory(CONFIG_STAGING_DIRECTORY)); // @todo Replace below lines with the commented out block below it when it's // performant to do so: http://drupal.org/node/1706064. diff -u b/core/modules/config/lib/Drupal/config/ConfigStorageController.php b/core/modules/config/lib/Drupal/config/ConfigStorageController.php --- b/core/modules/config/lib/Drupal/config/ConfigStorageController.php +++ b/core/modules/config/lib/Drupal/config/ConfigStorageController.php @@ -155,7 +155,7 @@ // Load all of the configuration entities. if ($ids === NULL) { - $names = drupal_container()->get('config.storage.active')->listAll($prefix); + $names = drupal_container()->get('config.storage')->listAll($prefix); $result = array(); foreach ($names as $name) { $config = config($name); diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigCRUDTest.php @@ -25,7 +25,7 @@ * Tests CRUD operations. */ function testCRUD() { - $storage = $this->container->get('config.storage.active'); + $storage = $this->container->get('config.storage'); $name = 'config_test.crud'; $config = config($name); diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigFileContentTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigFileContentTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigFileContentTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigFileContentTest.php @@ -26,7 +26,7 @@ * Tests setting, writing, and reading of a configuration setting. */ function testReadWriteConfig() { - $storage = $this->container->get('config.storage.active'); + $storage = $this->container->get('config.storage'); $name = 'foo.bar'; $key = 'foo'; @@ -62,8 +62,8 @@ $this->assertEqual($config->get(), array(), t('New config object is empty.')); // Verify nothing was saved. - $db_data = $storage->read($name); - $this->assertIdentical($db_data, FALSE); + $data = $storage->read($name); + $this->assertIdentical($data, FALSE); // Add a top level value $config = config($name); @@ -89,8 +89,8 @@ $config->save(); // Verify the database entry exists. - $db_data = $storage->read($name); - $this->assertTrue($db_data); + $data = $storage->read($name); + $this->assertTrue($data); // Read top level value $config = config($name); @@ -147,8 +147,8 @@ $config->set($key, $value)->save(); // Verify the database entry exists from a chained save. - $db_data = $storage->read($chained_name); - $this->assertEqual($db_data, $config->get()); + $data = $storage->read($chained_name); + $this->assertEqual($data, $config->get()); // Get file listing for all files starting with 'foo'. Should return // two elements. @@ -175,8 +175,8 @@ $config->delete(); // Verify the database entry no longer exists. - $db_data = $storage->read($name); - $this->assertIdentical($db_data, FALSE); + $data = $storage->read($name); + $this->assertIdentical($data, FALSE); } /** @@ -200,7 +200,7 @@ ); // Encode and write, and reload and decode the configuration data. - $filestorage = new FileStorage(); + $filestorage = new FileStorage(config_get_config_directory()); $filestorage->write($name, $config_data); $config_parsed = $filestorage->read($name); diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php @@ -62,7 +62,7 @@ function testDeleted() { $name = 'config_test.system'; $dynamic_name = 'config_test.dynamic.default'; - $storage = $this->container->get('config.storage.active'); + $storage = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); // Verify the default configuration values exist. @@ -108,7 +108,7 @@ function testNew() { $name = 'config_test.new'; $dynamic_name = 'config_test.dynamic.new'; - $storage = $this->container->get('config.storage.active'); + $storage = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); // Export. @@ -164,7 +164,7 @@ function testUpdated() { $name = 'config_test.system'; $dynamic_name = 'config_test.dynamic.default'; - $storage = $this->container->get('config.storage.active'); + $storage = $this->container->get('config.storage'); $staging = $this->container->get('config.storage.staging'); // Export. diff -u b/core/modules/config/lib/Drupal/config/Tests/Storage/DatabaseStorageTest.php /dev/null --- b/core/modules/config/lib/Drupal/config/Tests/Storage/DatabaseStorageTest.php +++ /dev/null @@ -1,72 +0,0 @@ - 'DatabaseStorage controller operations', - 'description' => 'Tests DatabaseStorage controller operations.', - 'group' => 'Configuration', - ); - } - - function setUp() { - parent::setUp(); - - $schema['config'] = array( - 'description' => 'Default active store for the configuration system.', - 'fields' => array( - 'name' => array( - 'description' => 'The identifier for the configuration entry, such as module.example (the name of the file, minus the file extension).', - 'type' => 'varchar', - 'length' => 255, - 'not null' => TRUE, - 'default' => '', - ), - 'data' => array( - 'description' => 'The raw data for this configuration entry.', - 'type' => 'blob', - 'not null' => TRUE, - 'size' => 'big', - 'translatable' => TRUE, - ), - ), - 'primary key' => array('name'), - ); - db_create_table('config', $schema['config']); - - $this->storage = new DatabaseStorage(); - $this->invalidStorage = new DatabaseStorage(array('connection' => 'invalid')); - - // ::listAll() verifications require other configuration data to exist. - $this->storage->write('system.performance', array()); - } - - protected function read($name) { - $data = db_query('SELECT data FROM {config} WHERE name = :name', array(':name' => $name))->fetchField(); - return unserialize($data); - } - - protected function insert($name, $data) { - db_insert('config')->fields(array('name' => $name, 'data' => $data))->execute(); - } - - protected function update($name, $data) { - db_update('config')->fields(array('data' => $data))->condition('name', $name)->execute(); - } - - protected function delete($name) { - db_delete('config')->condition('name', $name)->execute(); - } -} diff -u b/core/modules/config/lib/Drupal/config/Tests/Storage/FileStorageTest.php b/core/modules/config/lib/Drupal/config/Tests/Storage/FileStorageTest.php --- b/core/modules/config/lib/Drupal/config/Tests/Storage/FileStorageTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/Storage/FileStorageTest.php @@ -24,7 +24,7 @@ function setUp() { parent::setUp(); - $this->storage = new FileStorage(); + $this->storage = new FileStorage(config_get_config_directory()); $this->invalidStorage = new FileStorage($this->configDirectories[CONFIG_ACTIVE_DIRECTORY] . '/nonexisting'); // FileStorage::listAll() requires other configuration data to exist. diff -u b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php --- b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php +++ b/core/modules/system/lib/Drupal/system/Tests/Module/ModuleTestBase.php @@ -8,7 +8,6 @@ namespace Drupal\system\Tests\Module; use Drupal\Core\Database\Database; -use Drupal\Core\Config\DatabaseStorage; use Drupal\Core\Config\FileStorage; use Drupal\simpletest\WebTestBase; diff -u b/core/modules/system/system.install b/core/modules/system/system.install --- b/core/modules/system/system.install +++ b/core/modules/system/system.install @@ -1550,8 +1550,8 @@ * Creates {cache_config} cache table for the new configuration system. */ function system_update_8003() { - $schema['cache'] = array( - 'description' => 'Generic cache table for caching things not separated out into their own tables. Contributed modules may also use this to store cached items.', + $cache_update = array( + 'description' => 'Cache table for configuration data.', 'fields' => array( 'cid' => array( 'description' => 'Primary Key: Unique cache ID.', @@ -1603,7 +1603,7 @@ ), 'primary key' => array('cid'), ); - db_create_table('cache_config', $schema['cache']); + db_create_table('cache_config', $cache_update); } /** only in patch2: unchanged: --- a/core/includes/cache.inc +++ b/core/includes/cache.inc @@ -1,5 +1,7 @@