You are here

protected function ContentStorageComparer::getAndSortContentDataByCollectionAndNames 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::getAndSortContentDataByCollectionAndNames()

Gets and sorts configuration data from the source and target storages.

1 call to ContentStorageComparer::getAndSortContentDataByCollectionAndNames()
ContentStorageComparer::createChangelistbyCollectionAndNames in src/Content/ContentStorageComparer.php

File

src/Content/ContentStorageComparer.php, line 50

Class

ContentStorageComparer
Extends config storage comparer.

Namespace

Drupal\content_sync\Content

Code

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