function config_sync_get_changes

Returns a list of differences between configuration storages.

Parameters

Drupal\Core\Config\StorageInterface $source_storage: The storage to synchronize configuration from.

Drupal\Core\Config\StorageInterface $target_storage: The storage to synchronize configuration to.

Return value

array|bool An assocative array containing the differences between source and target storage, or FALSE if there are no differences.

5 calls to config_sync_get_changes()
ConfigImportTest::testDeleted in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php
Tests deletion of configuration during import.
ConfigImportTest::testNew in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php
Tests creation of configuration during import.
ConfigImportTest::testUpdated in drupal/core/modules/config/lib/Drupal/config/Tests/ConfigImportTest.php
Tests updating of configuration during import.
config_admin_sync_form in drupal/core/modules/config/config.admin.inc
Helper function to construct the storage changes in a configuration synchronization form.
config_import in drupal/core/includes/config.inc
Imports configuration into the active configuration.

File

drupal/core/includes/config.inc, line 120
This is the API for configuration storage.

Code

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;
}