class ContentSyncManager in Content Synchronization 8.2
Same name and namespace in other branches
- 3.0.x src/ContentSyncManager.php \Drupal\content_sync\ContentSyncManager
Hierarchy
- class \Drupal\content_sync\ContentSyncManager implements ContentSyncManagerInterface
Expanded class hierarchy of ContentSyncManager
1 file declares its use of ContentSyncManager
- ContentEntityNormalizer.php in src/
Normalizer/ ContentEntityNormalizer.php
1 string reference to 'ContentSyncManager'
1 service uses ContentSyncManager
File
- src/
ContentSyncManager.php, line 12
Namespace
Drupal\content_syncView source
class ContentSyncManager implements ContentSyncManagerInterface {
const DELIMITER = '.';
/**
* @var \Symfony\Component\Serializer\Serializer
*/
protected $serializer;
/**
* @var \Drupal\Core\Entity\EntityTypeManagerInterface
*/
protected $entityTypeManager;
/**
* @var \Drupal\content_sync\Exporter\ContentExporterInterface
*/
protected $contentExporter;
/**
* @var \Drupal\content_sync\Importer\ContentImporterInterface
*/
protected $contentImporter;
/**
* ContentSyncManager constructor.
*/
public function __construct(Serializer $serializer, EntityTypeManagerInterface $entity_type_manager, ContentExporterInterface $content_exporter, ContentImporterInterface $content_importer) {
$this->serializer = $serializer;
$this->entityTypeManager = $entity_type_manager;
$this->contentExporter = $content_exporter;
$this->contentImporter = $content_importer;
}
/**
* @return \Drupal\content_sync\Exporter\ContentExporterInterface
*/
public function getContentExporter() {
return $this->contentExporter;
}
/**
* @return \Drupal\content_sync\Importer\ContentImporterInterface
*/
public function getContentImporter() {
return $this->contentImporter;
}
/**
* @param $file_names
* @param $directory
*
* @return array
*/
public function generateImportQueue($file_names, $directory) {
$queue = [];
foreach ($file_names as $file) {
$ids = explode('.', $file);
list($entity_type_id, $bundle, $uuid) = $ids;
$file_path = $directory . "/" . $entity_type_id . "/" . $bundle . "/" . $file . ".yml";
if (!file_exists($file_path) || !$this
->isValidFilename($file)) {
continue;
}
$content = file_get_contents($file_path);
$format = $this->contentImporter
->getFormat();
$decoded_entity = $this->serializer
->decode($content, $format);
$decoded_entities[$file] = $decoded_entity;
}
if (!empty($decoded_entities)) {
$resolver = new ImportQueueResolver();
$queue = $resolver
->resolve($decoded_entities);
}
return $queue;
}
/**
* @param $file_names
* @param $directory
*
* @return array
*/
public function generateExportQueue($decoded_entities, $visited) {
$queue = [];
if (!empty($decoded_entities)) {
$resolver = new ExportQueueResolver();
$queue = $resolver
->resolve($decoded_entities, $visited);
}
return $queue;
}
/**
* @return \Symfony\Component\Serializer\Serializer
*/
public function getSerializer() {
return $this->serializer;
}
/**
* @return \Drupal\Core\Entity\EntityTypeManagerInterface
*/
public function getEntityTypeManager() {
return $this->entityTypeManager;
}
/**
* Checks filename structure
*
* @param $filename
*
* @return bool
*/
protected function isValidFilename($filename) {
$parts = explode(static::DELIMITER, $filename);
return count($parts) === 3;
}
}