diff -u b/core/includes/config.inc b/core/includes/config.inc --- b/core/includes/config.inc +++ b/core/includes/config.inc @@ -100,50 +100,61 @@ } /** - * Returns config sync actions using the contents of the source storage. + * 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. + * @param bool $use_manifest + * (optional) Whether to determine changes based on manifest files. Defaults + * to TRUE. * * @return array|bool - * An associative array containing config sync actions to import the config - * from source storage to the target storage, or FALSE if there are none. + * An associative array containing the differences between source and target + * storage, or FALSE if there are no differences. */ -function config_sync_get_changes(StorageInterface $source_storage, StorageInterface $target_storage) { +function config_sync_get_changes(StorageInterface $source_storage, StorageInterface $target_storage, $use_manifest = TRUE) { + $config_changes = array( + 'create' => array(), + 'change' => array(), + 'delete' => array(), + ); + $all_source_names = $source_storage->listAll(); + $all_target_names = $target_storage->listAll(); + // 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. - $source_config_data = array(); - $target_config_data = array(); - foreach ($source_storage->listAll('manifest') as $name) { - if ($source_manifest_data = $source_storage->read($name)) { - $source_config_data = array_merge($source_config_data, $source_manifest_data); + if ($use_manifest) { + $source_config_data = array(); + $target_config_data = array(); + foreach ($source_storage->listAll('manifest') as $name) { + if ($source_manifest_data = $source_storage->read($name)) { + $source_config_data = array_merge($source_config_data, $source_manifest_data); + } + + if ($target_manifest_data = $target_storage->read($name)) { + $target_config_data = array_merge($target_config_data, $target_manifest_data); + } } - if ($target_manifest_data = $target_storage->read($name)) { - $target_config_data = array_merge($target_config_data, $target_manifest_data); + foreach (array_diff_key($target_config_data, $source_config_data) as $name => $value) { + $config_changes['delete'][] = $value['name']; } - } - $config_changes = array( - 'create' => array(), - 'change' => array(), - 'delete' => array(), - ); - - foreach (array_diff_key($target_config_data, $source_config_data) as $name => $value) { - $config_changes['delete'][] = $value['name']; + foreach (array_diff_key($source_config_data, $target_config_data) as $name => $value) { + $config_changes['create'][] = $value['name']; + } } - - foreach (array_diff_key($source_config_data, $target_config_data) as $name => $value) { - $config_changes['create'][] = $value['name']; + else { + $config_changes['delete'] = array_diff($all_target_names, $all_source_names); + $config_changes['create'] = array_diff($all_source_names, $all_target_names); } - foreach (array_intersect($source_storage->listAll(), $target_storage->listAll()) as $name) { + foreach (array_intersect($all_source_names, $all_target_names) as $name) { // Ignore manifest files if (substr($name, 0, 9) != 'manifest.') { $source_config_data = $source_storage->read($name); @@ -163,51 +174,6 @@ } /** - * 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 @@ -47,19 +47,19 @@ // Verify that we have an initial snapshot that matches the active // configuration. This has to be true as no config should be installed. - $this->assertFalse(config_sync_get_changes($snapshot, $active)); + $this->assertFalse(config_sync_get_changes($snapshot, $active, FALSE)); // Install the default config. config_install_default_config('module', 'config_test'); // Although we have imported config this has not affected the snapshot. - $this->assertTrue(config_compare_storage_contents($snapshot, $active)); + $this->assertTrue(config_sync_get_changes($snapshot, $active, FALSE)); // Update the config snapshot. config_import_create_snapshot($active, $snapshot); // The snapshot and active config should now contain the same config // objects. - $this->assertFalse(config_compare_storage_contents($snapshot, $active)); + $this->assertFalse(config_sync_get_changes($snapshot, $active, FALSE)); // Change a configuration value in staging. $staging_data = config($config_name)->get(); @@ -68,9 +68,9 @@ // Verify that active and snapshot match, and that staging doesn't match // either of them. - $this->assertFalse(config_compare_storage_contents($snapshot, $active)); - $this->assertTrue(config_compare_storage_contents($snapshot, $staging)); - $this->assertTrue(config_compare_storage_contents($staging, $active)); + $this->assertFalse(config_sync_get_changes($snapshot, $active, FALSE)); + $this->assertTrue(config_sync_get_changes($snapshot, $staging, FALSE)); + $this->assertTrue(config_sync_get_changes($staging, $active, FALSE)); // Import changed data from staging to active. config_import(); @@ -80,7 +80,7 @@ // Verify that a new snapshot was created which and that it matches // the active config. - $this->assertFalse(config_compare_storage_contents($snapshot, $active)); + $this->assertFalse(config_sync_get_changes($snapshot, $active, FALSE)); } }