You are here

class ExportProcessor in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 src/Processors/ExportProcessor.php \Drupal\content_synchronizer\Processors\ExportProcessor
  2. 3.x src/Processors/ExportProcessor.php \Drupal\content_synchronizer\Processors\ExportProcessor

Export Processor.

Hierarchy

Expanded class hierarchy of ExportProcessor

4 files declare their use of ExportProcessor
ContentSynchronizerCommands.php in src/Commands/ContentSynchronizerCommands.php
content_synchronizer.drush.inc in ./content_synchronizer.drush.inc
Drush commands for content_synchronizer module.
EntityProcessorBase.php in src/Processors/Entity/EntityProcessorBase.php
FileProcessor.php in src/Plugin/content_synchronizer/entity_processor/FileProcessor.php

File

src/Processors/ExportProcessor.php, line 11

Namespace

Drupal\content_synchronizer\Processors
View source
class ExportProcessor {

  /**
   * The current export processor.
   *
   * @var ExportProcessor
   */
  private static $currentExportProcessor;

  /**
   * The writer.
   *
   * @var ExportEntityWriter
   */
  protected $writer;

  /**
   * The entity processor plugiin manager.
   *
   * @var \Drupal\content_synchronizer\Processors\Entity\EntityProcessorPluginManager
   */
  protected $entityProcessorPluginManager;

  /**
   * {@inheritdoc}
   */
  public function __construct(ExportEntityWriter $writer) {
    $this->writer = $writer;
    $this->entityProcessorPluginManager = \Drupal::service(EntityProcessorPluginManager::SERVICE_NAME);
  }

  /**
   * Export the list of entities.
   */
  public function exportEntitiesList(array $entities) {
    self::$currentExportProcessor = $this;
    foreach ($entities as $entity) {

      // Get the plugin of the entity :

      /** @var \Drupal\content_synchronizer\Processors\Entity\EntityProcessorBase $plugin */
      $plugin = $this->entityProcessorPluginManager
        ->getInstanceByEntityType($entity
        ->getEntityTypeId());
      $plugin
        ->export($entity);
      $this->writer
        ->addRootEntity($entity);
    }
  }

  /**
   * Export the entity.
   *
   * @param \Drupal\Core\Entity\Entity $entity
   *   THe entity to export.
   */
  public function exportEntity(Entity $entity) {
    $this
      ->exportEntitiesList([
      $entity,
    ]);
  }

  /**
   * Get the current Export Processor.
   *
   * @return \Drupal\content_synchronizer\Processors\ExportProcessor
   *   The current export processor.
   */
  public static function getCurrentExportProcessor() {
    return self::$currentExportProcessor;
  }

  /**
   * Get the writer.
   *
   * @return \Drupal\content_synchronizer\Processors\ExportEntityWriter
   *   The writer.
   */
  public function getWriter() {
    return $this->writer;
  }

  /**
   * Delete the unzip files after process.
   */
  public function closeProcess() {
    $this->writer
      ->archiveFiles();
    if ($archive = $this->writer
      ->getArchiveUri()) {
      return $archive;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
ExportProcessor::$currentExportProcessor private static property The current export processor.
ExportProcessor::$entityProcessorPluginManager protected property The entity processor plugiin manager.
ExportProcessor::$writer protected property The writer.
ExportProcessor::closeProcess public function Delete the unzip files after process.
ExportProcessor::exportEntitiesList public function Export the list of entities.
ExportProcessor::exportEntity public function Export the entity.
ExportProcessor::getCurrentExportProcessor public static function Get the current Export Processor.
ExportProcessor::getWriter public function Get the writer.
ExportProcessor::__construct public function