class BatchExportProcessor in Content Synchronizer 8
Same name and namespace in other branches
- 8.2 src/Processors/BatchExportProcessor.php \Drupal\content_synchronizer\Processors\BatchExportProcessor
- 3.x src/Processors/BatchExportProcessor.php \Drupal\content_synchronizer\Processors\BatchExportProcessor
BatchExport processor.
Hierarchy
- class \Drupal\content_synchronizer\Base\BatchProcessorBase
- class \Drupal\content_synchronizer\Processors\BatchExportProcessor
Expanded class hierarchy of BatchExportProcessor
3 files declare their use of BatchExportProcessor
- ExportConfirmForm.php in src/
Form/ ExportConfirmForm.php - LaunchExportForm.php in src/
Form/ LaunchExportForm.php - QuickExportController.php in src/
Controller/ QuickExportController.php
File
- src/
Processors/ BatchExportProcessor.php, line 10
Namespace
Drupal\content_synchronizer\ProcessorsView source
class BatchExportProcessor extends BatchProcessorBase {
/**
* The writer service.
*
* @var ExportEntityWriter
*/
protected $writer;
/**
* The export processor.
*
* @var ExportProcessor
*/
protected $exportProcessor;
/**
* {@inheritdoc}
*/
public function __construct(ExportEntityWriter $writer) {
$this->writer = $writer;
}
/**
* Export entities.
*
* @param array $entities
* Entities to export.
* @param mixed $finishCallback
* Callback method.
*/
public function exportEntities(array $entities, $finishCallback = NULL) {
$operations = $this
->getBatchOperations($entities, $finishCallback);
$batch = [
'title' => t('Exporting entities...'),
'operations' => $operations,
'finished' => get_called_class() . '::onFinishBatchProcess',
];
batch_set($batch);
}
/**
* {@inheritdoc}
*/
protected function getBatchOperations(array $entities, $finishCallback = NULL) {
$operations = [];
/** @var \Drupal\Core\Entity\Entity $entity */
foreach ($entities as $entity) {
$operations[] = [
get_called_class() . '::processBatchOperation',
[
[
'entity_id' => $entity
->id(),
'entity_type' => $entity
->getEntityTypeId(),
'writer' => $this->writer,
'finishCallback' => $finishCallback,
],
],
];
}
return $operations;
}
/**
* Do a batch operation.
*
* @param array $entityData
* Entity data.
* @param array $context
* Context.
*/
public static function processBatchOperation(array $entityData, array $context) {
/** @var ExportEntityWriter $writer */
$writer = $entityData['writer'];
// Get the entity :
/** @var \Drupal\Core\Entity\Entity $entity */
if ($entity = \Drupal::entityTypeManager()
->getStorage($entityData['entity_type'])
->load($entityData['entity_id'])) {
/** @var ExportProcessor $processor */
$processor = new ExportProcessor($writer);
$processor
->exportEntity($entity);
}
$context['results']['writer'] = $writer;
$context['results']['finishCallback'] = $entityData['finishCallback'];
}
/**
* {@inheritdoc}
*/
public static function onFinishBatchProcess($success, $results, $operations) {
/** @var ExportEntityWriter $writer */
$writer = $results['writer'];
$processor = new ExportProcessor($writer);
if ($archiveUri = $processor
->closeProcess()) {
// Redirection :
if (array_key_exists('finishCallback', $results)) {
self::callFinishCallback($results['finishCallback'], $archiveUri);
}
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BatchExportProcessor:: |
protected | property | The export processor. | |
BatchExportProcessor:: |
protected | property | The writer service. | |
BatchExportProcessor:: |
public | function | Export entities. | |
BatchExportProcessor:: |
protected | function | ||
BatchExportProcessor:: |
public static | function |
Callback method. Overrides BatchProcessorBase:: |
|
BatchExportProcessor:: |
public static | function |
Do a batch operation. Overrides BatchProcessorBase:: |
|
BatchExportProcessor:: |
public | function | ||
BatchProcessorBase:: |
protected static | function | Call the callback method if defined. |