annotate core/lib/Drupal/Core/Queue/Batch.php @ 19:fa3358dc1485 tip

Add ndrum files
author Chris Cannam
date Wed, 28 Aug 2019 13:14:47 +0100
parents 4c8ae668cc8c
children
rev   line source
Chris@0 1 <?php
Chris@0 2
Chris@0 3 namespace Drupal\Core\Queue;
Chris@0 4
Chris@0 5 /**
Chris@0 6 * Defines a batch queue handler used by the Batch API.
Chris@0 7 *
Chris@0 8 * This implementation:
Chris@0 9 * - Ensures FIFO ordering.
Chris@0 10 * - Allows an item to be repeatedly claimed until it is actually deleted (no
Chris@0 11 * notion of lease time or 'expire' date), to allow multipass operations.
Chris@0 12 *
Chris@0 13 * Stale items from failed batches are cleaned from the {queue} table on cron
Chris@0 14 * using the 'created' date.
Chris@0 15 *
Chris@0 16 * @ingroup queue
Chris@0 17 */
Chris@0 18 class Batch extends DatabaseQueue {
Chris@0 19
Chris@0 20 /**
Chris@0 21 * Overrides \Drupal\Core\Queue\DatabaseQueue::claimItem().
Chris@0 22 *
Chris@0 23 * Unlike \Drupal\Core\Queue\DatabaseQueue::claimItem(), this method provides
Chris@0 24 * a default lease time of 0 (no expiration) instead of 30. This allows the
Chris@0 25 * item to be claimed repeatedly until it is deleted.
Chris@0 26 */
Chris@0 27 public function claimItem($lease_time = 0) {
Chris@0 28 try {
Chris@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();
Chris@0 30 if ($item) {
Chris@0 31 $item->data = unserialize($item->data);
Chris@0 32 return $item;
Chris@0 33 }
Chris@0 34 }
Chris@0 35 catch (\Exception $e) {
Chris@0 36 $this->catchException($e);
Chris@0 37 }
Chris@0 38 return FALSE;
Chris@0 39 }
Chris@0 40
Chris@0 41 /**
Chris@0 42 * Retrieves all remaining items in the queue.
Chris@0 43 *
Chris@0 44 * This is specific to Batch API and is not part of the
Chris@0 45 * \Drupal\Core\Queue\QueueInterface.
Chris@0 46 *
Chris@0 47 * @return array
Chris@0 48 * An array of queue items.
Chris@0 49 */
Chris@0 50 public function getAllItems() {
Chris@0 51 $result = [];
Chris@0 52 try {
Chris@0 53 $items = $this->connection->query('SELECT data FROM {queue} q WHERE name = :name ORDER BY item_id ASC', [':name' => $this->name])->fetchAll();
Chris@0 54 foreach ($items as $item) {
Chris@0 55 $result[] = unserialize($item->data);
Chris@0 56 }
Chris@0 57 }
Chris@0 58 catch (\Exception $e) {
Chris@0 59 $this->catchException($e);
Chris@0 60 }
Chris@0 61 return $result;
Chris@0 62 }
Chris@0 63
Chris@0 64 }