You are here

protected function StorageComparer::addChangelistUpdate in Zircon Profile 8

Same name and namespace in other branches
  1. 8.0 core/lib/Drupal/Core/Config/StorageComparer.php \Drupal\Core\Config\StorageComparer::addChangelistUpdate()

Creates the update changelist.

The list of updates is sorted so that dependencies are created before configuration entities that depend on them. For example, field storages should be updated before fields.

Parameters

string $collection: The storage collection to operate on.

1 call to StorageComparer::addChangelistUpdate()
StorageComparer::createChangelist in core/lib/Drupal/Core/Config/StorageComparer.php

File

core/lib/Drupal/Core/Config/StorageComparer.php, line 261
Contains \Drupal\Core\Config\StorageComparer.

Class

StorageComparer
Defines a config storage comparer.

Namespace

Drupal\Core\Config

Code

protected function addChangelistUpdate($collection) {
  $recreates = array();
  foreach (array_intersect($this->sourceNames[$collection], $this->targetNames[$collection]) as $name) {
    $source_data = $this
      ->getSourceStorage($collection)
      ->read($name);
    $target_data = $this
      ->getTargetStorage($collection)
      ->read($name);
    if ($source_data !== $target_data) {
      if (isset($source_data['uuid']) && $source_data['uuid'] !== $target_data['uuid']) {

        // The entity has the same file as an existing entity but the UUIDs do
        // not match. This means that the entity has been recreated so config
        // synchronization should do the same.
        $recreates[] = $name;
      }
      else {
        $this
          ->addChangeList($collection, 'update', array(
          $name,
        ));
      }
    }
  }
  if (!empty($recreates)) {

    // Recreates should become deletes and creates. Deletes should be ordered
    // so that dependencies are deleted first.
    $this
      ->addChangeList($collection, 'create', $recreates, $this->sourceNames[$collection]);
    $this
      ->addChangeList($collection, 'delete', $recreates, array_reverse($this->targetNames[$collection]));
  }
}