You are here

public function ContentSynchronizerManager::createExportFile in Content Synchronizer 3.x

Create a tar.gz file.

Parameters

array $entitiesToExport: The entities list.

string|bool $label: The id of the export.

string $destination: The destination.

Return value

array The data of the export.

2 calls to ContentSynchronizerManager::createExportFile()
ContentSynchronizerManager::exportEntity in src/Service/ContentSynchronizerManager.php
Export a single entity.
ContentSynchronizerManager::launchExport in src/Service/ContentSynchronizerManager.php
Launch the specified export.

File

src/Service/ContentSynchronizerManager.php, line 217

Class

ContentSynchronizerManager
ContentSynchronizerManager service.

Namespace

Drupal\content_synchronizer\Service

Code

public function createExportFile(array $entitiesToExport = [], $label = FALSE, $destination = '') {
  $writer = new ExportEntityWriter();
  $writer
    ->initFromId($label ?: time());
  $processor = new ExportProcessor($writer);

  // Loop for log.
  $count = count($entitiesToExport);
  $data = [
    'destination' => '',
    'entities' => [],
  ];
  foreach (array_values($entitiesToExport) as $key => $entity) {
    try {
      $processor
        ->exportEntity($entity);
      $status = $this
        ->t('Exported');
    } catch (\Exception $error) {
      $status = $this
        ->t('Error');
    }
    $data['entities'][] = [
      '@key' => $key + 1,
      '@count' => $count,
      '@label' => ExportEntityWriter::getEntityLabel($entity),
      '@status' => $status,
    ];
  }
  $tempArchive = $this->fileSystem
    ->realpath($processor
    ->closeProcess());

  // Deplace archive.
  $data['destination'] = $this
    ->setDestination($destination, $tempArchive);
  return $data;
}