3 namespace Drupal\Core\Queue;
6 * Defines a batch queue handler used by the Batch API.
9 * - Ensures FIFO ordering.
10 * - Allows an item to be repeatedly claimed until it is actually deleted (no
11 * notion of lease time or 'expire' date), to allow multipass operations.
13 * Stale items from failed batches are cleaned from the {queue} table on cron
14 * using the 'created' date.
18 class Batch extends DatabaseQueue {
21 * Overrides \Drupal\Core\Queue\DatabaseQueue::claimItem().
23 * Unlike \Drupal\Core\Queue\DatabaseQueue::claimItem(), this method provides
24 * a default lease time of 0 (no expiration) instead of 30. This allows the
25 * item to be claimed repeatedly until it is deleted.
27 public function claimItem($lease_time = 0) {
29 $item = $this->connection->queryRange('SELECT data, item_id FROM {queue} q WHERE name = :name ORDER BY item_id ASC', 0, 1, [':name' => $this->name])->fetchObject();
31 $item->data = unserialize($item->data);
35 catch (\Exception $e) {
36 $this->catchException($e);
42 * Retrieves all remaining items in the queue.
44 * This is specific to Batch API and is not part of the
45 * \Drupal\Core\Queue\QueueInterface.
48 * An array of queue items.
50 public function getAllItems() {
53 $items = $this->connection->query('SELECT data FROM {queue} q WHERE name = :name ORDER BY item_id ASC', [':name' => $this->name])->fetchAll();
54 foreach ($items as $item) {
55 $result[] = unserialize($item->data);
58 catch (\Exception $e) {
59 $this->catchException($e);