public function ContentHubImportQueue::process in Acquia Content Hub 8
Handle the route to create a batch process.
1 string reference to 'ContentHubImportQueue::process'
File
- src/
Controller/ ContentHubImportQueue.php, line 55
Class
- ContentHubImportQueue
- Implements an Import Queue for entities.
Namespace
Drupal\acquia_contenthub\ControllerCode
public function process() {
$config = $this
->config('acquia_contenthub.entity_config');
$queue = $this->queueFactory
->get('acquia_contenthub_import_queue');
if ($queue
->numberOfItems() < 1) {
$this
->messenger()
->addStatus('No items to process.');
$this
->redirect('acquia_contenthub.import_queue');
}
$batch = [
'title' => $this
->t('Process all remaining entities'),
'operations' => [],
'finished' => [
self::class,
'batchFinished',
],
];
// Define a default value for batch_size in case it is not defined.
$batch_size = $config
->get('import_queue_batch_size');
$batch_size = !empty($batch_size) && is_numeric($batch_size) ? $batch_size : 1;
// Batch operations.
for ($i = 0; ceil($i < $queue
->numberOfItems() / $batch_size); $i++) {
$batch['operations'][] = [
[
self::class,
'batchProcess',
],
[
$config,
],
];
}
batch_set($batch);
return batch_process('/admin/config/services/acquia-contenthub/import-queue');
}