ExportQueueResolver.php in Content Synchronization 8.2
File
src/DependencyResolver/ExportQueueResolver.php
View source
<?php
namespace Drupal\content_sync\DependencyResolver;
use Drupal\Core\Serialization\Yaml;
use Drupal\content_sync\Content\ContentDatabaseStorage;
class ExportQueueResolver implements ContentSyncResolverInterface {
protected function depthFirstSearch(array &$visited, array $identifiers, array $normalized_entities) {
foreach ($identifiers as $identifier) {
$entity = $entity = $this
->getEntity($identifier, $normalized_entities);
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);
}
}
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,
];
}
}
}
protected function getEntity($identifier, $normalized_entities) {
if (!empty($normalized_entities[$identifier])) {
$entity = $normalized_entities[$identifier];
}
else {
$activeStorage = new ContentDatabaseStorage(\Drupal::database(), 'cs_db_snapshot');
$entity = $activeStorage
->cs_read($identifier);
}
return $entity;
}
public function resolve(array $normalized_entities, $visited = []) {
foreach ($normalized_entities as $identifier => $entity) {
$this
->depthFirstSearch($visited, [
$identifier,
], $normalized_entities);
}
return array_reverse($visited);
}
}