You are here

public function ContentHubExportQueueController::processQueueItems in Acquia Content Hub 8

Process all queue items with batch API.

Parameters

string|int $number_of_items: The number of items to process.

File

src/Controller/ContentHubExportQueueController.php, line 180

Class

ContentHubExportQueueController
Implements an Export Queue Controller for Content Hub.

Namespace

Drupal\acquia_contenthub\Controller

Code

public function processQueueItems($number_of_items = 'all') {

  // Create batch which collects all the specified queue items and process
  // them one after another.
  $batch = [
    'title' => $this
      ->t("Process Content Hub Export Queue"),
    'operations' => [],
    'finished' => '\\Drupal\\acquia_contenthub\\Controller\\ContentHubExportQueueController::batchFinished',
  ];

  // Calculate the number of items to process.
  $queue = $this->queueFactory
    ->get('acquia_contenthub_export_queue');
  $number_of_items = !is_numeric($number_of_items) ? $queue
    ->numberOfItems() : $number_of_items;

  // Count number of the items in this queue, create enough batch operations.
  $batch_size = $this->config
    ->get('export_queue_batch_size');
  $batch_size = $batch_size ?: 1;
  for ($i = 0; $i < ceil($number_of_items / $batch_size); $i++) {

    // Create batch operations.
    $batch['operations'][] = [
      '\\Drupal\\acquia_contenthub\\Controller\\ContentHubExportQueueController::batchProcess',
      [
        $number_of_items,
      ],
    ];
  }

  // Adds the batch sets.
  batch_set($batch);
}