You are here

function drush_content_synchronizer_launch_export in Content Synchronizer 8

Same name and namespace in other branches
  1. 8.2 content_synchronizer.drush.inc \drush_content_synchronizer_launch_export()

Launche the specified export.

File

./content_synchronizer.drush.inc, line 109
Drush commands for content_synchronizer module.

Code

function drush_content_synchronizer_launch_export($exportId) {
  if ($export = ExportEntity::load($exportId)) {
    $entitiesToExport = $export
      ->getEntitiesList();
    $writer = new ExportEntityWriter();
    $writer
      ->initFromId($export
      ->label());
    $processor = new ExportProcessor($writer);

    // Loop for log.
    $count = count($entitiesToExport);
    foreach (array_values($entitiesToExport) as $key => $entity) {
      try {
        $processor
          ->exportEntity($entity);
        $status = t('Exported');
      } catch (\Exception $error) {
        drush_log($error
          ->getMessage(), 'error');
        $status = t('Error');
      }
      drush_log(t('[@key/@count] - "@label" - @status', [
        '@key' => $key + 1,
        '@count' => $count,
        '@label' => ExportEntityWriter::getEntityLabel($entity),
        '@status' => $status,
      ]), 'status');
    }

    // Deplace archive.
    $tempArchive = $path = \Drupal::service('file_system')
      ->realpath($processor
      ->closeProcess());
    $destination = './' . basename($tempArchive);
    rename($tempArchive, $destination);
    drush_log(t('Archive file : @destination', [
      '@destination' => $destination,
    ]));
  }
}