You are here

protected function ImportQueueResolver::depthFirstSearch in Content Synchronization 8.2

Same name and namespace in other branches
  1. 3.0.x src/DependencyResolver/ImportQueueResolver.php \Drupal\content_sync\DependencyResolver\ImportQueueResolver::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 ImportQueueResolver::depthFirstSearch()
ImportQueueResolver::resolve in src/DependencyResolver/ImportQueueResolver.php
Creates a queue.

File

src/DependencyResolver/ImportQueueResolver.php, line 24

Class

ImportQueueResolver
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. FALSE means no need to import.
    try {
      $entity = $this
        ->getEntity($identifier, $normalized_entities);
    } catch (\Exception $e) {
      $entity = FALSE;
      $visited['Missing'][$identifier][] = $e
        ->getMessage();
    }

    // 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]) && $entity) {
      list($entity_type_id, $bundle, $uuid) = explode('.', $identifier);
      $visited[$identifier] = [
        'entity_type_id' => $entity_type_id,
        'decoded_entity' => $entity,
      ];
    }
  }
}