diff -u b/core/includes/config.inc b/core/includes/config.inc --- b/core/includes/config.inc +++ b/core/includes/config.inc @@ -100,7 +100,7 @@ } /** - * Returns a list of differences between configuration storages. + * Returns config sync actions using the contents of the source storage. * * @param Drupal\Core\Config\StorageInterface $source_storage * The storage to synchronize configuration from. @@ -108,8 +108,8 @@ * The storage to synchronize configuration to. * * @return array|bool - * An assocative array containing the differences between source and target - * storage, or FALSE if there are no differences. + * An associative array containing config sync actions to import the config + * from source storage to the target storage, or FALSE if there are none. */ function config_sync_get_changes(StorageInterface $source_storage, StorageInterface $target_storage) { // Config entities maintain 'manifest' files that list the objects they @@ -163,6 +163,51 @@ } /** + * Returns a list of differences between configuration storages. + * + * @param Drupal\Core\Config\StorageInterface $source_storage + * The storage to synchronize configuration from. + * @param Drupal\Core\Config\StorageInterface $target_storage + * The storage to synchronize configuration to. + * + * @return array|bool + * An assocative array containing the differences between source and target + * storage, or FALSE if there are no differences. + */ +function config_compare_storage_contents(StorageInterface $source_storage, StorageInterface $target_storage) { + // Config entities maintain 'manifest' files that list the objects they + // are currently handling. Each file is a simple indexed array of config + // object names. In order to generate a list of objects that have been + // created or deleted we need to open these files in both the source and + // target storage, generate an array of the objects, and compare them. + $active_config = $source_storage->listAll(); + $target_config = $target_storage->listAll(); + + + $config_changes = array( + 'create' => array_diff($target_config, $active_config), + 'change' => array(), + 'delete' => array_diff($active_config, $target_config), + ); + + + foreach (array_intersect($active_config, $target_config) as $name) { + $source_config_data = $source_storage->read($name); + $target_config_data = $target_storage->read($name); + if ($source_config_data !== $target_config_data) { + $config_changes['change'][] = $name; + } + } + + // Do not trigger subsequent synchronization operations if there are no + // changes in any category. + if (empty($config_changes['create']) && empty($config_changes['change']) && empty($config_changes['delete'])) { + return FALSE; + } + return $config_changes; +} + +/** * Writes an array of config file changes from a source storage to a target storage. * * @param array $config_changes diff -u b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php --- b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php +++ b/core/modules/config/lib/Drupal/config/Tests/ConfigSnapshotTest.php @@ -51,17 +51,15 @@ // Install the default config. config_install_default_config('module', 'config_test'); - // Although we have imported config this has not affected the snapshot and - // no differences are show because: manifests are only compared if they - // exist in the snapshot and simple config is only listed if it is changed. - $this->assertFalse(config_sync_get_changes($snapshot, $active)); + // Although we have imported config this has not affected the snapshot. + $this->assertTrue(config_compare_storage_contents($snapshot, $active)); // Update the config snapshot. config_import_create_snapshot($active, $snapshot); // The snapshot and active config should now contain the same config // objects. - $this->assertIdentical($active->listAll(), $snapshot->listAll()); + $this->assertFalse(config_compare_storage_contents($snapshot, $active)); // Change a configuration value in staging. $staging_data = config($config_name)->get(); @@ -70,9 +68,9 @@ // Verify that active and snapshot match, and that staging doesn't match // either of them. - $this->assertFalse(config_sync_get_changes($snapshot, $active)); - $this->assertTrue(config_sync_get_changes($snapshot, $staging)); - $this->assertTrue(config_sync_get_changes($staging, $active)); + $this->assertFalse(config_compare_storage_contents($snapshot, $active)); + $this->assertTrue(config_compare_storage_contents($snapshot, $staging)); + $this->assertTrue(config_compare_storage_contents($staging, $active)); // Import changed data from staging to active. config_import(); @@ -82,7 +80,7 @@ // Verify that a new snapshot was created which and that it matches // the active config. - $this->assertFalse(config_sync_get_changes($snapshot, $active)); + $this->assertFalse(config_compare_storage_contents($snapshot, $active)); } }