Skip navigation
Help

batch.queue.inc

  1. drupal
    1. 7 drupal/includes/batch.queue.inc

Queue handlers used by the Batch API.

Those implementations:

  • ensure FIFO ordering,
  • let an item be repeatedly claimed until it is actually deleted (no notion of lease time or 'expire' date), to allow multipass operations.

Classes

NameDescription
BatchMemoryQueueBatch queue implementation used for non-progressive batches.
BatchQueueBatch queue implementation.

File

drupal/includes/batch.queue.inc
View source
  1. <?php
  2. /**
  3. * @file
  4. * Queue handlers used by the Batch API.
  5. *
  6. * Those implementations:
  7. * - ensure FIFO ordering,
  8. * - let an item be repeatedly claimed until it is actually deleted (no notion
  9. * of lease time or 'expire' date), to allow multipass operations.
  10. */
  11. /**
  12. * Batch queue implementation.
  13. *
  14. * Stale items from failed batches are cleaned from the {queue} table on cron
  15. * using the 'created' date.
  16. */
  17. class BatchQueue extends SystemQueue {
  18. public function claimItem($lease_time = 0) {
  19. $item = db_query_range('SELECT data, item_id FROM {queue} q WHERE name = :name ORDER BY item_id ASC', 0, 1, array(':name' => $this->name))->fetchObject();
  20. if ($item) {
  21. $item->data = unserialize($item->data);
  22. return $item;
  23. }
  24. return FALSE;
  25. }
  26. /**
  27. * Retrieve all remaining items in the queue.
  28. *
  29. * This is specific to Batch API and is not part of the DrupalQueueInterface,
  30. */
  31. public function getAllItems() {
  32. $result = array();
  33. $items = db_query('SELECT data FROM {queue} q WHERE name = :name ORDER BY item_id ASC', array(':name' => $this->name))->fetchAll();
  34. foreach ($items as $item) {
  35. $result[] = unserialize($item->data);
  36. }
  37. return $result;
  38. }
  39. }
  40. /**
  41. * Batch queue implementation used for non-progressive batches.
  42. */
  43. class BatchMemoryQueue extends MemoryQueue {
  44. public function claimItem($lease_time = 0) {
  45. if (!empty($this->queue)) {
  46. reset($this->queue);
  47. return current($this->queue);
  48. }
  49. return FALSE;
  50. }
  51. /**
  52. * Retrieve all remaining items in the queue.
  53. *
  54. * This is specific to Batch API and is not part of the DrupalQueueInterface,
  55. */
  56. public function getAllItems() {
  57. $result = array();
  58. foreach ($this->queue as $item) {
  59. $result[] = $item->data;
  60. }
  61. return $result;
  62. }
  63. }