Commit 29bf9e89 authored by catch's avatar catch

Issue #2166703 by alexpott: Config SchemaStorage uses InstallStorage.

parent 93206c30
......@@ -93,6 +93,7 @@ services:
arguments: ['@database', config_snapshot]
config.storage.schema:
class: Drupal\Core\Config\Schema\SchemaStorage
arguments: ['@config.storage']
config.storage.installer:
class: Drupal\Core\Config\InstallStorage
config.typed:
......
......@@ -30,6 +30,12 @@ function config_uninstall_default_config($type, $name) {
foreach ($config_names as $config_name) {
\Drupal::config($config_name)->delete();
}
$schema_dir = drupal_get_path($type, $name) . '/config/schema';
if (is_dir($schema_dir)) {
// Refresh the schema cache if uninstalling an extension that provides
// configuration schema.
\Drupal::service('config.typed')->clearCachedDefinitions();
}
}
/**
......
......@@ -374,7 +374,8 @@ function install_begin_request(&$install_state) {
$container->register('config.storage', 'Drupal\Core\Config\InstallStorage');
$container->register('config.storage.schema', 'Drupal\Core\Config\Schema\SchemaStorage');
$container->register('config.storage.schema', 'Drupal\Core\Config\Schema\SchemaStorage')
->addArgument(new Reference('config.storage'));
$container->register('config.typed', 'Drupal\Core\Config\TypedConfigManager')
->addArgument(new Reference('config.storage'))
......
......@@ -75,13 +75,18 @@ public function __construct(ConfigFactory $config_factory, StorageInterface $act
*/
public function installDefaultConfig($type, $name) {
// Get all default configuration owned by this extension.
$source_storage = new ExtensionInstallStorage();
$source_storage = new ExtensionInstallStorage($this->activeStorage);
$config_to_install = $source_storage->listAll($name . '.');
// Work out if this extension provides default configuration for any other
// enabled extensions.
$config_dir = drupal_get_path($type, $name) . '/config';
if (is_dir($config_dir)) {
if (is_dir($config_dir . '/schema')) {
// Refresh the schema cache if installing default configuration and the
// extension has a configuration schema directory.
$this->typedConfig->clearCachedDefinitions();
}
$default_storage = new FileStorage($config_dir);
$other_module_config = array_filter($default_storage->listAll(), function ($value) use ($name) {
return !preg_match('/^' . $name . '\./', $value);
......
......@@ -15,18 +15,54 @@
*/
class ExtensionInstallStorage extends InstallStorage {
/**
* The active configuration store.
*
* @var \Drupal\Core\Config\StorageInterface
*/
protected $configStorage;
/**
* Overrides \Drupal\Core\Config\InstallStorage::__construct().
*
* @param \Drupal\Core\Config\StorageInterface $config_storage
* The active configuration store where the list of enabled modules and
* themes is stored.
*/
public function __construct(StorageInterface $config_storage) {
$this->configStorage = $config_storage;
}
/**
* Resets the static cache.
*/
public function reset() {
$this->folders = NULL;
}
/**
* Returns a map of all config object names and their folders.
*
* The list is based on enabled modules and themes.
* The list is based on enabled modules and themes. The active configuration
* storage is used rather than \Drupal\Core\Extension\ModuleHandler and
* \Drupal\Core\Extension\ThemeHandler in order to resolve circular
* dependencies between these services and \Drupal\Core\Config\ConfigInstaller
* and \Drupal\Core\Config\TypedConfigManager.
*
* @return array
* An array mapping config object names with directories.
*/
protected function getAllFolders() {
if (!isset($this->folders)) {
$this->folders = $this->getComponentNames('module', array_keys(\Drupal::moduleHandler()->getModuleList()));
$this->folders += $this->getComponentNames('theme', array_keys(array_filter(list_themes(), function ($theme) {return $theme->status;})));
$this->folders = array();
$modules = $this->configStorage->read('system.module');
if (isset($modules['enabled'])) {
$this->folders += $this->getComponentNames('module', array_keys($modules['enabled']));
}
$themes = $this->configStorage->read('system.theme');
if (isset($themes['enabled'])) {
$this->folders += $this->getComponentNames('theme', array_keys($themes['enabled']));
}
}
return $this->folders;
}
......
......@@ -7,13 +7,13 @@
namespace Drupal\Core\Config\Schema;
use Drupal\Core\Config\InstallStorage;
use Drupal\Core\Config\ExtensionInstallStorage;
use Drupal\Core\Config\StorageException;
/**
* Defines the file storage controller for metadata files.
*/
class SchemaStorage extends InstallStorage {
class SchemaStorage extends ExtensionInstallStorage {
/**
* Implements \Drupal\Core\Config\StorageInterface::exists().
......@@ -56,4 +56,32 @@ public function rename($name, $new_name) {
throw new StorageException('Rename operation is not allowed for config schema storage.');
}
/**
* Returns a map of all config object names and their folders.
*
* The list is based on enabled modules and themes.
*
* @return array
* An array mapping config object names with directories.
*/
protected function getAllFolders() {
if (!isset($this->folders)) {
parent::getAllFolders();
$this->folders += $this->getBaseDataTypeSchema();
}
return $this->folders;
}
/**
* Gets the base data types for configuration schema.
*
* @return array
* The file containing the base data types for configuration schema.
*/
protected function getBaseDataTypeSchema() {
return array(
'core.data_types.schema' => 'core/lib/Drupal/Core/Config/Schema'
);
}
}
......@@ -199,6 +199,7 @@ public function getDefinitions() {
*/
public function clearCachedDefinitions() {
$this->definitions = NULL;
$this->schemaStorage->reset();
$this->cache->delete($this::CACHE_ID);
}
......
......@@ -7,12 +7,15 @@
namespace Drupal\Core\Config;
use Drupal\Component\Plugin\Discovery\CachedDiscoveryInterface;
use Drupal\Component\Plugin\PluginManagerInterface;
/**
* Defines an interface for typed configuration manager.
*
* @package Drupal\Core\Config
*/
Interface TypedConfigManagerInterface {
Interface TypedConfigManagerInterface extends PluginManagerInterface, CachedDiscoveryInterface {
/**
* Checks if the configuration schema with the given config name exists.
......@@ -24,4 +27,5 @@
* TRUE if configuration schema exists, FALSE otherwise.
*/
public function hasConfigSchema($name);
}
......@@ -723,12 +723,12 @@ public function uninstall(array $module_list, $uninstall_dependents = TRUE) {
$this->invoke($module, 'uninstall');
drupal_uninstall_schema($module);
// Remove all configuration belonging to the module.
config_uninstall_default_config('module', $module);
// Remove the module's entry from the config.
$module_config->clear("enabled.$module")->save();
// Remove all configuration belonging to the module.
config_uninstall_default_config('module', $module);
// Update the module handler to remove the module.
// The current ModuleHandler instance is obsolete with the kernel rebuild
// below.
......
......@@ -2,7 +2,7 @@
/**
* @file
* Definition of Drupal\config\Tests\ConfigInstallTest.
* Contains \Drupal\config\Tests\ConfigInstallTest.
*/
namespace Drupal\config\Tests;
......@@ -42,10 +42,17 @@ function testModuleInstallation() {
$config = \Drupal::config($default_configuration_entity);
$this->assertIdentical($config->isNew(), TRUE);
// Ensure that schema provided by modules that are not installed is not
// available.
$this->assertFalse(\Drupal::service('config.typed')->hasConfigSchema('config_test.schema_in_install'), 'Configuration schema for config_test.schema_in_install does not exist.');
// Install the test module.
$this->enableModules(array('config_test'));
$this->installConfig(array('config_test'));
// After module installation the new schema should exist.
$this->assertTrue(\Drupal::service('config.typed')->hasConfigSchema('config_test.schema_in_install'), 'Configuration schema for config_test.schema_in_install exists.');
// Verify that default module config exists.
\Drupal::configFactory()->reset($default_config);
\Drupal::configFactory()->reset($default_configuration_entity);
......@@ -62,5 +69,15 @@ function testModuleInstallation() {
$this->assertFalse(isset($GLOBALS['hook_config_test']['update']));
$this->assertFalse(isset($GLOBALS['hook_config_test']['predelete']));
$this->assertFalse(isset($GLOBALS['hook_config_test']['delete']));
// Ensure that data type casting is applied during config installation.
$config = \Drupal::config('config_test.schema_in_install');
$this->assertIdentical($config->get('integer'), 1);
// Test that uninstalling configuration removes configuration schema.
\Drupal::config('system.module')->set('enabled', array())->save();
config_uninstall_default_config('module', 'config_test');
$this->assertFalse(\Drupal::service('config.typed')->hasConfigSchema('config_test.schema_in_install'), 'Configuration schema for config_test.schema_in_install does not exist.');
}
}
......@@ -132,6 +132,14 @@ config_test.schema_data_types:
sequence:
- type: boolean
config_test.schema_in_install:
label: 'Schema test data with parenting'
type: mapping
mapping:
integer:
type: integer
label: 'Integer'
config_test.types:
type: mapping
label: 'Configuration type'
......
......@@ -16,6 +16,13 @@
*/
class MigrateActionConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('action');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateAggregatorConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('aggregator');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateBookConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('book');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateContactConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('contact');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateDblogConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('dblog');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateFileConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('file');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateForumConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('forum');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateLocaleConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('locale');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateMenuConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('menu');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateSearchConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('search');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateSimpletestConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('simpletest');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateStatisticsConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('statistics');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateSyslogConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('syslog');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateTaxonomyConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('taxonomy');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateTextConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('text');
/**
* {@inheritdoc}
*/
......
......@@ -16,6 +16,13 @@
*/
class MigrateUpdateConfigsTest extends MigrateDrupalTestBase {
/**
* Modules to enable.
*
* @var array
*/
public static $modules = array('update');
/**
* {@inheritdoc}
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment