function DatabaseQueue::numberOfItems

Same name and namespace in other branches
  1. 9 core/lib/Drupal/Core/Queue/DatabaseQueue.php \Drupal\Core\Queue\DatabaseQueue::numberOfItems()
  2. 8.9.x core/lib/Drupal/Core/Queue/DatabaseQueue.php \Drupal\Core\Queue\DatabaseQueue::numberOfItems()
  3. 10 core/lib/Drupal/Core/Queue/DatabaseQueue.php \Drupal\Core\Queue\DatabaseQueue::numberOfItems()

Overrides QueueInterface::numberOfItems

File

core/lib/Drupal/Core/Queue/DatabaseQueue.php, line 102

Class

DatabaseQueue
Default queue implementation.

Namespace

Drupal\Core\Queue

Code

public function numberOfItems() {
    try {
        return (int) $this->connection
            ->query('SELECT COUNT([item_id]) FROM {' . static::TABLE_NAME . '} WHERE [name] = :name', [
            ':name' => $this->name,
        ])
            ->fetchField();
    } catch (\Exception $e) {
        $this->catchException($e);
        // If there is no table there cannot be any items.
        return 0;
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.