Returns a list of differences between configuration storages.
Drupal\Core\Config\StorageInterface $source_storage: The storage to synchronize configuration from.
Drupal\Core\Config\StorageInterface $target_storage: The storage to synchronize configuration to.
array|bool An assocative 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) {
// 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 ($target_manifest_data = $target_storage
->read($name)) {
$target_config_data = array_merge($target_config_data, $target_manifest_data);
}
}
$config_changes = array(
'create' => array(),
'change' => array(),
'delete' => array(),
);
foreach (array_diff_assoc($target_config_data, $source_config_data) as $name => $value) {
$config_changes['delete'][] = $value['name'];
}
foreach (array_diff_assoc($source_config_data, $target_config_data) as $name => $value) {
$config_changes['create'][] = $value['name'];
}
foreach (array_intersect($source_storage
->listAll(), $target_storage
->listAll()) as $name) {
// Ignore manifest files
if (substr($name, 0, 9) != 'manifest.') {
$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;
}