public function ContentHubExportQueue::batchProcess in Acquia Content Hub 8.2
Common batch processing callback for all operations.
Parameters
mixed $context: The context array.
File
- modules/
acquia_contenthub_publisher/ src/ ContentHubExportQueue.php, line 95
Class
- ContentHubExportQueue
- Implements an Export Queue for Content Hub.
Namespace
Drupal\acquia_contenthub_publisherCode
public function batchProcess(&$context) {
$queueWorker = $this->queueManager
->createInstance('acquia_contenthub_publish_export');
// Get a queued item.
if ($item = $this->queue
->claimItem()) {
try {
// Generating a list of entities.
$msg_label = $this
->t('(@entity_type, @entity_id)', [
'@entity_type' => $item->data->type,
'@entity_id' => $item->data->uuid,
]);
// Process item.
$entities_processed = $queueWorker
->processItem($item->data);
if ($entities_processed == FALSE) {
// Indicate that the item could not be processed.
if ($entities_processed === FALSE) {
$message = $this
->t('There was an error processing entities: @entities and their dependencies. The item has been sent back to the queue to be processed again later. Check your logs for more info.', [
'@entities' => $msg_label,
]);
}
else {
$message = $this
->t('No processing was done for entities: @entities and their dependencies. The item has been sent back to the queue to be processed again later. Check your logs for more info.', [
'@entities' => $msg_label,
]);
}
$context['message'] = $message
->jsonSerialize();
$context['results'][] = $message
->jsonSerialize();
}
else {
// If everything was correct, delete processed item from the queue.
$this->queue
->deleteItem($item);
// Creating a text message to present to the user.
$message = $this
->t('Processed entities: @entities and their dependencies (@count @label sent).', [
'@entities' => $msg_label,
'@count' => $entities_processed,
'@label' => $entities_processed == 1 ? $this
->t('entity') : $this
->t('entities'),
]);
$context['message'] = $message
->jsonSerialize();
$context['results'][] = $message
->jsonSerialize();
}
} catch (SuspendQueueException $e) {
// If there was an Exception thrown because of an error
// Releases the item that the worker could not process.
// Another worker can come and process it.
$this->queue
->releaseItem($item);
}
}
}