Patched to Drupal 8.4.8 level. See https://www.drupal.org/sa-core-2018-004 and patch...
[yaffs-website] / web / core / lib / Drupal / Core / Queue / BatchMemory.php
1 <?php
2
3 namespace Drupal\Core\Queue;
4
5 /**
6  * Defines a batch queue handler used by the Batch API for non-progressive
7  * batches.
8  *
9  * This implementation:
10  * - Ensures FIFO ordering.
11  * - Allows an item to be repeatedly claimed until it is actually deleted (no
12  *   notion of lease time or 'expire' date), to allow multipass operations.
13  *
14  * @ingroup queue
15  */
16 class BatchMemory extends Memory {
17
18   /**
19    * Overrides \Drupal\Core\Queue\Memory::claimItem().
20    *
21    * Unlike \Drupal\Core\Queue\Memory::claimItem(), this method provides a
22    * default lease time of 0 (no expiration) instead of 30. This allows the item
23    * to be claimed repeatedly until it is deleted.
24    */
25   public function claimItem($lease_time = 0) {
26     if (!empty($this->queue)) {
27       reset($this->queue);
28       return current($this->queue);
29     }
30     return FALSE;
31   }
32
33   /**
34    * Retrieves all remaining items in the queue.
35    *
36    * This is specific to Batch API and is not part of the
37    * \Drupal\Core\Queue\QueueInterface.
38    *
39    * @return array
40    *   An array of queue items.
41    */
42   public function getAllItems() {
43     $result = [];
44     foreach ($this->queue as $item) {
45       $result[] = $item->data;
46     }
47     return $result;
48   }
49
50 }