Mercurial > hg > isophonics-drupal-site
comparison core/lib/Drupal/Core/Queue/Batch.php @ 0:4c8ae668cc8c
Initial import (non-working)
author | Chris Cannam |
---|---|
date | Wed, 29 Nov 2017 16:09:58 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:4c8ae668cc8c |
---|---|
1 <?php | |
2 | |
3 namespace Drupal\Core\Queue; | |
4 | |
5 /** | |
6 * Defines a batch queue handler used by the Batch API. | |
7 * | |
8 * This implementation: | |
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. | |
12 * | |
13 * Stale items from failed batches are cleaned from the {queue} table on cron | |
14 * using the 'created' date. | |
15 * | |
16 * @ingroup queue | |
17 */ | |
18 class Batch extends DatabaseQueue { | |
19 | |
20 /** | |
21 * Overrides \Drupal\Core\Queue\DatabaseQueue::claimItem(). | |
22 * | |
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. | |
26 */ | |
27 public function claimItem($lease_time = 0) { | |
28 try { | |
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(); | |
30 if ($item) { | |
31 $item->data = unserialize($item->data); | |
32 return $item; | |
33 } | |
34 } | |
35 catch (\Exception $e) { | |
36 $this->catchException($e); | |
37 } | |
38 return FALSE; | |
39 } | |
40 | |
41 /** | |
42 * Retrieves all remaining items in the queue. | |
43 * | |
44 * This is specific to Batch API and is not part of the | |
45 * \Drupal\Core\Queue\QueueInterface. | |
46 * | |
47 * @return array | |
48 * An array of queue items. | |
49 */ | |
50 public function getAllItems() { | |
51 $result = []; | |
52 try { | |
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); | |
56 } | |
57 } | |
58 catch (\Exception $e) { | |
59 $this->catchException($e); | |
60 } | |
61 return $result; | |
62 } | |
63 | |
64 } |