function QueueExampleForm::retrieveQueue

Same name in other branches
  1. 3.x modules/queue_example/src/Form/QueueExampleForm.php \Drupal\queue_example\Form\QueueExampleForm::retrieveQueue()

Retrieves the queue from the database for display purposes only.

It is not recommended to access the database directly, and this is only here so that the user interface can give a good idea of what's going on in the queue.

Parameters

string $queue_name: The name of the queue from which to fetch items.

Return value

array An array of item arrays.

1 call to QueueExampleForm::retrieveQueue()
QueueExampleForm::buildForm in modules/queue_example/src/Form/QueueExampleForm.php
Form constructor.

File

modules/queue_example/src/Form/QueueExampleForm.php, line 230

Class

QueueExampleForm
Form with examples on how to use queue.

Namespace

Drupal\queue_example\Form

Code

public function retrieveQueue($queue_name) {
    $items = [];
    // This example requires the default queue implementation to work,
    // so we bail if some other queue implementation has been installed.
    if (!$this->doesQueueUseDb()) {
        return $items;
    }
    // Make sure there are queue items available. The queue will not create our
    // database table if there are no items.
    if ($this->queueFactory
        ->get($queue_name)
        ->numberOfItems() >= 1) {
        $result = $this->database
            ->query('SELECT item_id, data, expire, created FROM {' . DatabaseQueue::TABLE_NAME . '} WHERE name = :name ORDER BY item_id', [
            ':name' => $queue_name,
        ], [
            'fetch' => \PDO::FETCH_ASSOC,
        ]);
        foreach ($result as $item) {
            $items[] = $item;
        }
    }
    return $items;
}