You are here

class ContentStorageComparer in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/Content/ContentStorageComparer.php \Drupal\content_sync\Content\ContentStorageComparer

Extends config storage comparer.

Hierarchy

Expanded class hierarchy of ContentStorageComparer

1 file declares its use of ContentStorageComparer
ContentSyncCommands.php in src/Commands/ContentSyncCommands.php

File

src/Content/ContentStorageComparer.php, line 12

Namespace

Drupal\content_sync\Content
View source
class ContentStorageComparer extends StorageComparer {

  /**
   * {@inheritdoc}
   */
  public function createChangelistbyCollection($collection) {
    $this->changelist[$collection] = $this
      ->getEmptyChangelist();
    $this
      ->getAndSortConfigData($collection);
    $this
      ->addChangelistCreate($collection);
    $this
      ->addChangelistUpdate($collection);
    $this
      ->addChangelistDelete($collection);

    // Only collections that support configuration entities can have renames.
    if ($collection == StorageInterface::DEFAULT_COLLECTION) {
      $this
        ->addChangelistRename($collection);
    }
    return $this;
  }

  /**
   * {@inheritdoc}
   */
  public function createChangelistbyCollectionAndNames($collection, $names) {
    $this->changelist[$collection] = $this
      ->getEmptyChangelist();
    if ($this
      ->getAndSortContentDataByCollectionAndNames($collection, $names)) {
      $this
        ->addChangelistCreate($collection);
      $this
        ->addChangelistUpdate($collection);
      $this
        ->addChangelistDelete($collection);

      // Only collections that support configuration entities can have renames.
      if ($collection == StorageInterface::DEFAULT_COLLECTION) {
        $this
          ->addChangelistRename($collection);
      }
    }
    return $this;
  }

  /**
   * Gets and sorts configuration data from the source and target storages.
   */
  protected function getAndSortContentDataByCollectionAndNames($collection, $names) {
    $names = explode(',', $names);
    $target_names = [];
    $source_names = [];
    foreach ($names as $key => $name) {
      $name = $collection . '.' . $name;
      $source_storage = $this
        ->getSourceStorage($collection);
      $target_storage = $this
        ->getTargetStorage($collection);
      if ($source_storage
        ->exists($name) || $target_storage
        ->exists($name)) {
        $target_names = array_merge($target_names, $target_storage
          ->listAll($name));
        $source_names = array_merge($source_names, $source_storage
          ->listAll($name));
      }
    }
    $target_names = array_filter($target_names);
    $source_names = array_filter($source_names);
    if (!empty($target_names) || !empty($source_names)) {

      // Prime the static caches by reading all the configuration in the source
      // and target storages.
      $target_data = $target_storage
        ->readMultiple($target_names);
      $source_data = $source_storage
        ->readMultiple($source_names);
      $this->targetNames[$collection] = $target_names;
      $this->sourceNames[$collection] = $source_names;
      return true;
    }
    return false;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ContentStorageComparer::createChangelistbyCollection public function
ContentStorageComparer::createChangelistbyCollectionAndNames public function
ContentStorageComparer::getAndSortContentDataByCollectionAndNames protected function Gets and sorts configuration data from the source and target storages.
DependencySerializationTrait::$_entityStorages protected property An array of entity type IDs keyed by the property name of their storages.
DependencySerializationTrait::$_serviceIds protected property An array of service IDs keyed by property name used for serialization.
DependencySerializationTrait::__sleep public function 1
DependencySerializationTrait::__wakeup public function 2
StorageComparer::$changelist protected property List of changes to between the source storage and the target storage.
StorageComparer::$sourceCacheStorage protected property A memory cache backend to statically cache source configuration data.
StorageComparer::$sourceNames protected property Sorted list of all the configuration object names in the source storage.
StorageComparer::$sourceStorage protected property The source storage used to discover configuration changes.
StorageComparer::$sourceStorages protected property The source storages keyed by collection.
StorageComparer::$targetCacheStorage protected property A memory cache backend to statically cache target configuration data.
StorageComparer::$targetNames protected property Sorted list of all the configuration object names in the target storage.
StorageComparer::$targetStorage protected property The target storage used to write configuration changes.
StorageComparer::$targetStorages protected property The target storages keyed by collection.
StorageComparer::addChangeList protected function Adds changes to the changelist.
StorageComparer::addChangelistCreate protected function Creates the create changelist.
StorageComparer::addChangelistDelete protected function Creates the delete changelist.
StorageComparer::addChangelistRename protected function Creates the rename changelist.
StorageComparer::addChangelistUpdate protected function Creates the update changelist.
StorageComparer::createChangelist public function
StorageComparer::createRenameName protected function Creates a rename name from the old and new names for the object.
StorageComparer::extractRenameNames public function Extracts old and new configuration names from a configuration change name. Overrides StorageComparerInterface::extractRenameNames
StorageComparer::getAllCollectionNames public function Gets the existing collections from both the target and source storage. Overrides StorageComparerInterface::getAllCollectionNames
StorageComparer::getAndSortConfigData protected function Gets and sorts configuration data from the source and target storages.
StorageComparer::getChangelist public function Gets the list of differences to import. Overrides StorageComparerInterface::getChangelist
StorageComparer::getEmptyChangelist public function Gets an empty changelist. Overrides StorageComparerInterface::getEmptyChangelist
StorageComparer::getSourceStorage public function Gets the configuration source storage. Overrides StorageComparerInterface::getSourceStorage
StorageComparer::getTargetStorage public function Gets the configuration target storage. Overrides StorageComparerInterface::getTargetStorage
StorageComparer::hasChanges public function Checks if there are any operations with changes to process. Overrides StorageComparerInterface::hasChanges
StorageComparer::moveRenameToUpdate public function Moves a rename operation to an update. Overrides StorageComparerInterface::moveRenameToUpdate
StorageComparer::removeFromChangelist protected function Removes the entry from the given operation changelist for the given name.
StorageComparer::reset public function Recalculates the differences. Overrides StorageComparerInterface::reset
StorageComparer::validateSiteUuid public function Validates that the system.site::uuid in the source and target match. Overrides StorageComparerInterface::validateSiteUuid
StorageComparer::__construct public function Constructs the Configuration storage comparer.