From dfd537fe1a497ff69ad718cebaa9bb2df8be2c13 Mon Sep 17 00:00:00 2001 From: catch Date: Mon, 28 Oct 2013 11:51:33 +0000 Subject: [PATCH] Issue #2095489 by tayzlor, beejeebus: Separate out module install config code from import code. --- core/includes/config.inc | 49 ++++++++++++------- .../Drupal/Core/Config/ConfigInstaller.php | 33 ------------- .../Core/Config/ExtensionInstallStorage.php | 29 +---------- .../ExtensionInstallStorageComparer.php | 38 -------------- .../Drupal/config/Tests/ConfigInstallTest.php | 4 -- 5 files changed, 32 insertions(+), 121 deletions(-) delete mode 100644 core/lib/Drupal/Core/Config/ConfigInstaller.php delete mode 100644 core/lib/Drupal/Core/Config/ExtensionInstallStorageComparer.php diff --git a/core/includes/config.inc b/core/includes/config.inc index 2857c686dc..6f55e61521 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -3,11 +3,10 @@ use Drupal\Component\Utility\Unicode; use Drupal\Core\Config\Config; use Drupal\Core\Config\ConfigException; -use Drupal\Core\Config\ConfigInstaller; use Drupal\Core\Config\ExtensionInstallStorage; +use Drupal\Core\Config\Context\FreeConfigContext; use Drupal\Core\Config\FileStorage; use Drupal\Core\Config\StorageInterface; -use Drupal\Core\Config\ExtensionInstallStorageComparer; use Symfony\Component\Yaml\Dumper; /** @@ -37,8 +36,6 @@ * The name of the module or theme to install default configuration for. * * @see \Drupal\Core\Config\ExtensionInstallStorage - * @see \Drupal\Core\Config\ExtensionInstallStorageComparer - * @see \Drupal\Core\Config\ConfigInstaller */ function config_install_default_config($type, $name) { // Get all default configuration owned by this extension. @@ -66,20 +63,36 @@ function ($value) use ($name) { $config_to_install = array_merge($config_to_install, $other_module_config); } if (!empty($config_to_install)) { - $storage_comparer = new ExtensionInstallStorageComparer($source_storage, \Drupal::service('config.storage')); - $storage_comparer->setSourceNames($config_to_install); - // Only import new config. Changed config is from previous enables and - // should not be overwritten. - $storage_comparer->addChangelistCreate(); - $installer = new ConfigInstaller( - $storage_comparer, - \Drupal::service('event_dispatcher'), - \Drupal::service('config.factory'), - \Drupal::entityManager(), - \Drupal::lock(), - \Drupal::service('uuid') - ); - $installer->import(); + $entity_manager = Drupal::service('entity.manager'); + $config_factory = Drupal::service('config.factory'); + $context = new FreeConfigContext(Drupal::service('event_dispatcher'), Drupal::service('uuid')); + $target_storage = Drupal::service('config.storage'); + $config_factory->enterContext($context); + foreach ($config_to_install as $name) { + // Only import new config. + if ($target_storage->exists($name)) { + continue; + } + + $new_config = new Config($name, $target_storage, $context); + $data = $source_storage->read($name); + if ($data !== FALSE) { + $new_config->setData($data); + } + if ($entity_type = config_get_entity_type_by_name($name)) { + $entity_manager + ->getStorageController($entity_type) + ->create($new_config->get()) + ->save(); + } + else { + $new_config->save(); + } + + // Reset static cache on the config factory. + $config_factory->reset($name); + } + $config_factory->leaveContext(); } } diff --git a/core/lib/Drupal/Core/Config/ConfigInstaller.php b/core/lib/Drupal/Core/Config/ConfigInstaller.php deleted file mode 100644 index 11622b2dc5..0000000000 --- a/core/lib/Drupal/Core/Config/ConfigInstaller.php +++ /dev/null @@ -1,33 +0,0 @@ -folders; } - - /** - * {@inheritdoc} - * - * @throws \Drupal\Core\Config\StorageException - */ - public function write($name, array $data) { - throw new StorageException('Write operation is not allowed for config extension install storage.'); - } - - /** - * {@inheritdoc} - * - * @throws \Drupal\Core\Config\StorageException - */ - public function delete($name) { - throw new StorageException('Delete operation is not allowed for config extension install storage.'); - } - - /** - * {@inheritdoc} - * - * @throws \Drupal\Core\Config\StorageException - */ - public function rename($name, $new_name) { - throw new StorageException('Rename operation is not allowed for config extension install storage.'); - } - } + diff --git a/core/lib/Drupal/Core/Config/ExtensionInstallStorageComparer.php b/core/lib/Drupal/Core/Config/ExtensionInstallStorageComparer.php deleted file mode 100644 index 0503315019..0000000000 --- a/core/lib/Drupal/Core/Config/ExtensionInstallStorageComparer.php +++ /dev/null @@ -1,38 +0,0 @@ -sourceNames = $source_names; - return $this; - } - - /** - * Gets all the configuration names in the source storage. - * - * @return array - * List of all the configuration names in the source storage. - * - * @see self::setSourceNames() - */ - protected function getSourceNames() { - return $this->sourceNames; - } - -} diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php index f9c79e3807..1062ea5590 100644 --- a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallTest.php @@ -52,10 +52,6 @@ function testModuleInstallation() { $config = \Drupal::config($default_configuration_entity); $this->assertIdentical($config->isNew(), FALSE); - // Verify that configuration import callback was invoked for the dynamic - // configuration entity. - $this->assertTrue($GLOBALS['hook_config_import']); - // Verify that config_test API hooks were invoked for the dynamic default // configuration entity. $this->assertFalse(isset($GLOBALS['hook_config_test']['load'])); -- GitLab