public function ContentSynchronizerCommands::synchronizerLaunchExport in Content Synchronizer 8
Same name and namespace in other branches
- 8.2 src/Commands/ContentSynchronizerCommands.php \Drupal\content_synchronizer\Commands\ContentSynchronizerCommands::synchronizerLaunchExport()
Launch the export of the passed ID.
@command content:synchronizer-launch-export @aliases cslex,content-synchronizer-launch-export
Parameters
$exportId: The export id.
$destination: File to create
1 call to ContentSynchronizerCommands::synchronizerLaunchExport()
- ContentSynchronizerCommands::synchronizerAllExport in src/
Commands/ ContentSynchronizerCommands.php - Export all nodes/taxo : bind together create Export, attach all node in & cslex
File
- src/
Commands/ ContentSynchronizerCommands.php, line 103
Class
- ContentSynchronizerCommands
- A Drush commandfile.
Namespace
Drupal\content_synchronizer\CommandsCode
public function synchronizerLaunchExport($exportId, $destination = '') {
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) {
$this->logger
->error($error
->getMessage());
$status = t('Error');
}
$this->logger
->notice(t('[@key/@count] - "@label" - @status', [
'@key' => $key + 1,
'@count' => $count,
'@label' => ExportEntityWriter::getEntityLabel($entity),
'@status' => $status,
])
->__toString());
}
// Deplace archive.
$tempArchive = $path = \Drupal::service('file_system')
->realpath($processor
->closeProcess());
if ($destination == '') {
$destination = './' . basename($tempArchive);
}
rename($tempArchive, $destination);
$this->logger
->notice(t('Archive file : @destination', [
'@destination' => $destination,
])
->__toString());
}
}