From f50d43511080a5a7323d8da59f4d6dfacafc21e2 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Thu, 20 Jan 2022 15:31:50 -0800 Subject: [PATCH] CRM_Queue_Queue_* - Add fetchItem($id) Note: The return types are a bit wonky here. Unfortunately, as I recall, the original specification for all the methods here allowed backend-specific return types -- anti-standardized return-types. --- CRM/Queue/Queue.php | 11 +++++++++++ CRM/Queue/Queue/Memory.php | 13 +++++++++++++ CRM/Queue/Queue/SqlTrait.php | 20 ++++++++++++++++++++ 3 files changed, 44 insertions(+) diff --git a/CRM/Queue/Queue.php b/CRM/Queue/Queue.php index 280e929dd9..bce38babe2 100644 --- a/CRM/Queue/Queue.php +++ b/CRM/Queue/Queue.php @@ -164,6 +164,17 @@ abstract class CRM_Queue_Queue { */ abstract public function deleteItem($item); + /** + * Get the full data for an item. + * + * This is a passive peek - it does not claim/steal/release anything. + * + * @param int|string $id + * The unique ID of the task within the queue. + * @return CRM_Queue_DAO_QueueItem|object|null $dao + */ + abstract public function fetchItem($id); + /** * Return an item that could not be processed. * diff --git a/CRM/Queue/Queue/Memory.php b/CRM/Queue/Queue/Memory.php index e745fc834b..db0c490bfe 100644 --- a/CRM/Queue/Queue/Memory.php +++ b/CRM/Queue/Queue/Memory.php @@ -168,6 +168,19 @@ class CRM_Queue_Queue_Memory extends CRM_Queue_Queue { unset($this->releaseTimes[$item->id]); } + /** + * Get the full data for an item. + * + * This is a passive peek - it does not claim/steal/release anything. + * + * @param int|string $id + * The unique ID of the task within the queue. + * @return CRM_Queue_DAO_QueueItem|object|null $dao + */ + public function fetchItem($id) { + return $this->items[$id] ?? NULL; + } + /** * Return an item that could not be processed. * diff --git a/CRM/Queue/Queue/SqlTrait.php b/CRM/Queue/Queue/SqlTrait.php index 4c93e2d320..19d3648e76 100644 --- a/CRM/Queue/Queue/SqlTrait.php +++ b/CRM/Queue/Queue/SqlTrait.php @@ -94,6 +94,26 @@ trait CRM_Queue_Queue_SqlTrait { $dao->free(); } + /** + * Get the full data for an item. + * + * This is a passive peek - it does not claim/steal/release anything. + * + * @param int|string $id + * The unique ID of the task within the queue. + * @return CRM_Queue_DAO_QueueItem|object|null $dao + */ + public function fetchItem($id) { + $dao = new CRM_Queue_DAO_QueueItem(); + $dao->id = $id; + $dao->queue_name = $this->getName(); + if (!$dao->find(TRUE)) { + return NULL; + } + $dao->data = unserialize($dao->data); + return $dao; + } + /** * Return an item that could not be processed. * -- 2.25.1