From 8afbc081ddc04576b6c2643287cb9f6ac4458d32 Mon Sep 17 00:00:00 2001 From: catch Date: Sun, 24 Feb 2013 21:04:38 +0000 Subject: [PATCH] Issue #1889620 by vijaycs85, sun, heyrocker: Fixed config_install_default_config() overwrites existing configuration. --- core/includes/config.inc | 12 +- .../config/Tests/ConfigInstallWebTest.php | 108 ++++++++++++++++++ .../config_integration_test.settings.yml | 1 + ...g_test.dynamic.config_integration_test.yml | 2 + .../config_integration_test.info | 6 + .../config_integration_test.module | 6 + .../config/tests/config_test/config_test.info | 4 +- 7 files changed, 131 insertions(+), 8 deletions(-) create mode 100644 core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php create mode 100644 core/modules/config/tests/config_integration_test/config/config_integration_test.settings.yml create mode 100644 core/modules/config/tests/config_integration_test/config/config_test.dynamic.config_integration_test.yml create mode 100644 core/modules/config/tests/config_integration_test/config_integration_test.info create mode 100644 core/modules/config/tests/config_integration_test/config_integration_test.module diff --git a/core/includes/config.inc b/core/includes/config.inc index 50b6fab2d5f..0b83f60636b 100644 --- a/core/includes/config.inc +++ b/core/includes/config.inc @@ -35,15 +35,15 @@ function config_install_default_config($type, $name) { $source_storage = new FileStorage($config_dir); $target_storage = drupal_container()->get('config.storage'); - $config_changes = array( - 'delete' => array(), - 'create' => array(), - 'change' => array(), - ); - $config_changes['create'] = $source_storage->listAll(); + // Ignore manifest files. + $config_changes = config_sync_get_changes($source_storage, $target_storage, FALSE); if (empty($config_changes['create'])) { return; } + + // Do not overwrite or delete pre-existing configuration. + $config_changes['change'] = array(); + $config_changes['delete'] = array(); $remaining_changes = config_import_invoke_owner($config_changes, $source_storage, $target_storage); config_sync_changes($remaining_changes, $source_storage, $target_storage); } diff --git a/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php new file mode 100644 index 00000000000..06950f9f2a0 --- /dev/null +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigInstallWebTest.php @@ -0,0 +1,108 @@ + 'Installation functionality', + 'description' => 'Tests installation of configuration objects in installation functionality.', + 'group' => 'Configuration', + ); + } + + function setUp() { + parent::setUp(); + + // Ensure the global variable being asserted by this test does not exist; + // a previous test executed in this request/process might have set it. + unset($GLOBALS['hook_config_test']); + } + + /** + * Tests module re-installation. + */ + function testIntegrationModuleReinstallation() { + $default_config = 'config_integration_test.settings'; + $default_configuration_entity = 'config_test.dynamic.config_integration_test'; + + // Install the config_test module we're integrating with. + module_enable(array('config_test')); + + // Verify the configuration does not exist prior to installation. + $config_static = config($default_config); + $this->assertIdentical($config_static->isNew(), TRUE); + $config_entity = config($default_configuration_entity); + $this->assertIdentical($config_entity->isNew(), TRUE); + + // Install the integration module. + module_enable(array('config_integration_test')); + + // Verify that default module config exists. + $config_static = config($default_config); + $this->assertIdentical($config_static->isNew(), FALSE); + $this->assertIdentical($config_static->get('foo'), 'default setting'); + $config_entity = config($default_configuration_entity); + $this->assertIdentical($config_entity->isNew(), FALSE); + $this->assertIdentical($config_entity->get('label'), 'Default integration config label'); + + // Customize both configuration objects. + $config_static->set('foo', 'customized setting')->save(); + $config_entity->set('label', 'Customized integration config label')->save(); + + // @todo FIXME: Setting config keys WITHOUT SAVING retains the changed config + // object in memory. Every new call to config() MUST revert in-memory changes + // that haven't been saved! + // In other words: This test passes even without this reset, but it shouldn't. + $this->container->get('config.factory')->reset(); + + // Disable and enable the integration module. + module_disable(array('config_integration_test')); + module_enable(array('config_integration_test')); + + // Verify that customized config exists. + $config_static = config($default_config); + $this->assertIdentical($config_static->isNew(), FALSE); + $this->assertIdentical($config_static->get('foo'), 'customized setting'); + $config_entity = config($default_configuration_entity); + $this->assertIdentical($config_entity->isNew(), FALSE); + $this->assertIdentical($config_entity->get('label'), 'Customized integration config label'); + + // Disable and uninstall the integration module. + module_disable(array('config_integration_test')); + module_uninstall(array('config_integration_test')); + + // Verify the integration module's config was uninstalled. + $config_static = config($default_config); + $this->assertIdentical($config_static->isNew(), TRUE); + + // Verify the integration config still exists. + $config_entity = config($default_configuration_entity); + $this->assertIdentical($config_entity->isNew(), FALSE); + $this->assertIdentical($config_entity->get('label'), 'Customized integration config label'); + + // Reinstall the integration module. + module_enable(array('config_integration_test')); + + // Verify the integration module's config was re-installed. + $config_static = config($default_config); + $this->assertIdentical($config_static->isNew(), FALSE); + $this->assertIdentical($config_static->get('foo'), 'default setting'); + + // Verify the customized integration config still exists. + $config_entity = config($default_configuration_entity); + $this->assertIdentical($config_entity->isNew(), FALSE); + $this->assertIdentical($config_entity->get('label'), 'Customized integration config label'); + } + +} diff --git a/core/modules/config/tests/config_integration_test/config/config_integration_test.settings.yml b/core/modules/config/tests/config_integration_test/config/config_integration_test.settings.yml new file mode 100644 index 00000000000..1b33ac0e61d --- /dev/null +++ b/core/modules/config/tests/config_integration_test/config/config_integration_test.settings.yml @@ -0,0 +1 @@ +foo: 'default setting' diff --git a/core/modules/config/tests/config_integration_test/config/config_test.dynamic.config_integration_test.yml b/core/modules/config/tests/config_integration_test/config/config_test.dynamic.config_integration_test.yml new file mode 100644 index 00000000000..f87b9423bc8 --- /dev/null +++ b/core/modules/config/tests/config_integration_test/config/config_test.dynamic.config_integration_test.yml @@ -0,0 +1,2 @@ +id: config_integration_test +label: 'Default integration config label' diff --git a/core/modules/config/tests/config_integration_test/config_integration_test.info b/core/modules/config/tests/config_integration_test/config_integration_test.info new file mode 100644 index 00000000000..8a9db4b0cc4 --- /dev/null +++ b/core/modules/config/tests/config_integration_test/config_integration_test.info @@ -0,0 +1,6 @@ +name = ConfigTest integration +package = Testing +version = VERSION +core = 8.x +hidden = TRUE +dependencies[] = config_test diff --git a/core/modules/config/tests/config_integration_test/config_integration_test.module b/core/modules/config/tests/config_integration_test/config_integration_test.module new file mode 100644 index 00000000000..9c926963783 --- /dev/null +++ b/core/modules/config/tests/config_integration_test/config_integration_test.module @@ -0,0 +1,6 @@ +