public static function ProcessQueueForm::processUpdates in Field Encryption 3.0.x
Processes field updates.
Parameters
string $queue_id: The ID of the queue to process.
array $context: The batch API context.
File
- src/
Form/ ProcessQueueForm.php, line 107
Class
- ProcessQueueForm
- Form builder for the field_encrypt process queue form.
Namespace
Drupal\field_encrypt\FormCode
public static function processUpdates($queue_id, array &$context) {
$batch_size = \Drupal::config('field_encrypt.settings')
->get('batch_size');
/** @var \Drupal\Core\Queue\QueueInterface $queue */
$queue = \Drupal::service('queue')
->get($queue_id);
$num_items = $queue
->numberOfItems();
/** @var \Drupal\field_encrypt\Plugin\QueueWorker\FieldEncryptQueueWorkerInterface $queue_worker */
$queue_worker = \Drupal::service('plugin.manager.queue_worker')
->createInstance($queue_id);
if (empty($context['sandbox'])) {
$context['sandbox']['progress'] = 0;
$context['sandbox']['max'] = $num_items;
}
// Process entities in groups.
for ($i = 1; $i <= $batch_size && $i <= $num_items; $i++) {
if ($item = $queue
->claimItem()) {
try {
$queue_worker
->processItem($item->data);
$queue
->deleteItem($item);
$context['results']['items'][] = $item->data['entity_id'];
$context['message'] = $queue_worker
->batchMessage($item->data);
$context['sandbox']['progress']++;
} catch (SuspendQueueException $e) {
$queue
->releaseItem($item);
} catch (\Exception $e) {
watchdog_exception('field_encrypt', $e);
if (!isset($context['results']['errors'])) {
$context['results']['errors'] = [];
}
$context['results']['errors'][] = $e
->getMessage();
}
}
else {
$context['finished'] = 1;
$context['results']['errors'][] = t('Cannot claim an item - unable to process the batch');
return;
}
}
// Inform the batch engine that we are not finished,
// and provide an estimation of the completion level we reached.
if ($context['sandbox']['progress'] != $context['sandbox']['max']) {
$context['finished'] = $context['sandbox']['progress'] / $context['sandbox']['max'];
}
}