class BatchImportProcessor in Content Synchronizer 8
Same name and namespace in other branches
- 8.2 src/Processors/BatchImportProcessor.php \Drupal\content_synchronizer\Processors\BatchImportProcessor
- 3.x src/Processors/BatchImportProcessor.php \Drupal\content_synchronizer\Processors\BatchImportProcessor
Batch Import.
Hierarchy
- class \Drupal\content_synchronizer\Base\BatchProcessorBase
- class \Drupal\content_synchronizer\Processors\BatchImportProcessor
Expanded class hierarchy of BatchImportProcessor
1 file declares its use of BatchImportProcessor
- LaunchImportForm.php in src/
Form/ LaunchImportForm.php
File
- src/
Processors/ BatchImportProcessor.php, line 11
Namespace
Drupal\content_synchronizer\ProcessorsView source
class BatchImportProcessor extends BatchProcessorBase {
/**
* The entities to import.
*
* @var array
*/
protected $entitiesToImport;
/**
* Launch the import of the import entity.
*
* @param \Drupal\content_synchronizer\Entity\ImportEntity $import
* The import entity.
* @param array $entitiesToImport
* The entities to import.
* @param mixed $finishCallBack
* The finishcallback.
* @param string $creationType
* The creation entity type.
* @param string $updateType
* The update entity type.
*/
public function import(ImportEntity $import, array $entitiesToImport, $finishCallBack = NULL, $creationType = ImportProcessor::PUBLICATION_UNPUBLISH, $updateType = ImportProcessor::UPDATE_IF_RECENT) {
$operations = $this
->getBatchOperations($import, $entitiesToImport, $finishCallBack, $creationType, $updateType);
$batch = [
'title' => t('Importing entities...'),
'operations' => $operations,
'finished' => get_called_class() . '::onFinishBatchProcess',
];
batch_set($batch);
}
/**
* Set the entities to import list.
*/
public function setEntitiesToImport(array $entitiesToImport) {
$this->entitiesToImport = $entitiesToImport;
}
/**
* {@inheritdoc}
*/
protected function getBatchOperations(ImportEntity $import, array $entitiesToImport, $finishCallBack = NULL, $creationType = ImportProcessor::PUBLICATION_UNPUBLISH, $updateType = ImportProcessor::UPDATE_IF_RECENT) {
$operations = [];
foreach ($entitiesToImport as $data) {
$data['finishCallback'] = $finishCallBack;
$data['importId'] = $import
->id();
$data['creationType'] = $creationType;
$data['updateType'] = $updateType;
$operations[] = [
get_called_class() . '::processBatchOperation',
[
$data,
],
];
}
return $operations;
}
/**
* Do a batch operation.
*
* @param array $data
* The data to treat.
* @param array $context
* The context.
*/
public static function processBatchOperation(array $data, array $context) {
$importProcessor = new ImportProcessor(ImportEntity::load($data['importId']));
$importProcessor
->setCreationType($data['creationType']);
$importProcessor
->setUpdateType($data['updateType']);
$importProcessor
->importEntityFromRootData($data);
$context['results']['finishCallback'] = $data['finishCallback'];
}
/**
* Callback.
*/
public static function onFinishBatchProcess($success, $results, $operations) {
if (array_key_exists('finishCallback', $results)) {
self::callFinishCallback($results['finishCallback'], $results);
}
}
}
Members
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
BatchImportProcessor:: |
protected | property | The entities to import. | |
BatchImportProcessor:: |
protected | function | ||
BatchImportProcessor:: |
public | function | Launch the import of the import entity. | |
BatchImportProcessor:: |
public static | function |
Callback. Overrides BatchProcessorBase:: |
|
BatchImportProcessor:: |
public static | function |
Do a batch operation. Overrides BatchProcessorBase:: |
|
BatchImportProcessor:: |
public | function | Set the entities to import list. | |
BatchProcessorBase:: |
protected static | function | Call the callback method if defined. |