You are here

protected function ExportQueueResolver::depthFirstSearch in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/DependencyResolver/ExportQueueResolver.php \Drupal\content_sync\DependencyResolver\ExportQueueResolver::depthFirstSearch()

Builds a graph placing the deepest vertexes at the first place.

Parameters

array $visited: Array of vertexes to return.

array $identifiers: Array of entity identifiers to process.

array $normalized_entities: Parsed entities to import.

1 call to ExportQueueResolver::depthFirstSearch()
ExportQueueResolver::resolve in src/DependencyResolver/ExportQueueResolver.php
Creates a queue.

File

src/DependencyResolver/ExportQueueResolver.php, line 25

Class

ExportQueueResolver
Class ImportQueueResolver.

Namespace

Drupal\content_sync\DependencyResolver

Code

protected function depthFirstSearch(array &$visited, array $identifiers, array $normalized_entities) {
  foreach ($identifiers as $identifier) {

    // Get a decoded entity.
    $entity = $entity = $this
      ->getEntity($identifier, $normalized_entities);

    // Process dependencies first.
    if (!empty($entity['_content_sync']['entity_dependencies'])) {
      foreach ($entity['_content_sync']['entity_dependencies'] as $ref_entity_type_id => $references) {
        $this
          ->depthFirstSearch($visited, $references, $normalized_entities);
      }
    }

    // Process translations' dependencies if any.
    if (!empty($entity["_translations"])) {
      foreach ($entity["_translations"] as $translation) {
        if (!empty($translation['_content_sync']['entity_dependencies'])) {
          foreach ($translation['_content_sync']['entity_dependencies'] as $ref_entity_type_id => $references) {
            $this
              ->depthFirstSearch($visited, $references, $normalized_entities);
          }
        }
      }
    }
    if (!isset($visited[$identifier])) {
      list($entity_type_id, $bundle, $uuid) = explode('.', $identifier);
      $visited[$identifier] = [
        'entity_type' => $entity_type_id,
        'entity_uuid' => $uuid,
      ];
    }
  }
}