From 0dd161277046bab1ec994e8d756c4e99c717421e Mon Sep 17 00:00:00 2001 From: Angie Byron Date: Fri, 8 Jan 2010 06:36:34 +0000 Subject: #629794 by yched: Fix Scaling issues with batch API. (with tests) --- includes/batch.queue.inc | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 includes/batch.queue.inc (limited to 'includes/batch.queue.inc') diff --git a/includes/batch.queue.inc b/includes/batch.queue.inc new file mode 100644 index 000000000..8193280f3 --- /dev/null +++ b/includes/batch.queue.inc @@ -0,0 +1,72 @@ + $this->name))->fetchObject(); + if ($item) { + $item->data = unserialize($item->data); + return $item; + } + return FALSE; + } + + /** + * Retrieve all remaining items in the queue. + * + * This is specific to Batch API and is not part of the DrupalQueueInterface, + */ + public function getAllItems() { + $result = array(); + $items = db_query('SELECT data FROM {queue} q WHERE name = :name ORDER BY item_id ASC', array(':name' => $this->name))->fetchAll(); + foreach ($items as $item) { + $result[] = unserialize($item->data); + } + return $result; + } +} + +/** + * Batch queue implementation used for non-progressive batches. + */ +class BatchMemoryQueue extends MemoryQueue { + + public function claimItem($lease_time = 0) { + if (!empty($this->queue)) { + reset($this->queue); + return current($this->queue); + } + return FALSE; + } + + /** + * Retrieve all remaining items in the queue. + * + * This is specific to Batch API and is not part of the DrupalQueueInterface, + */ + public function getAllItems() { + $result = array(); + foreach ($this->queue as $item) { + $result[] = $item->data; + } + return $result; + } +} -- cgit v1.2.3