You are here

class UniqueQueueItem in TMGMT Extension Suite 8

Same name and namespace in other branches
  1. 8.3 src/Utils/UniqueQueueItem.php \Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem
  2. 8.2 src/Utils/UniqueQueueItem.php \Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem

Hierarchy

Expanded class hierarchy of UniqueQueueItem

1 file declares its use of UniqueQueueItem
JobCheckStatus.php in src/Plugin/QueueWorker/JobCheckStatus.php
1 string reference to 'UniqueQueueItem'
tmgmt_extension_suit.services.yml in ./tmgmt_extension_suit.services.yml
tmgmt_extension_suit.services.yml
1 service uses UniqueQueueItem
tmgmt_extension_suit.utils.queue_unique_item in ./tmgmt_extension_suit.services.yml
Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem

File

src/Utils/UniqueQueueItem.php, line 14
Contains QueueUniqueItem service class.

Namespace

Drupal\tmgmt_extension_suit\Utils
View source
class UniqueQueueItem {

  /**
   * @var \Drupal\Core\Queue\QueueFactory
   */
  private $queueFactory;

  /**
   * @var \Psr\Log\LoggerInterface
   */
  private $logger;

  /**
   * @var \Drupal\Core\Database\Connection
   */
  private $databaseConnection;
  public function __construct(QueueFactory $queueFactory, LoggerInterface $logger, Connection $databaseConnection) {
    $this->queueFactory = $queueFactory;
    $this->logger = $logger;
    $this->databaseConnection = $databaseConnection;
  }

  /**
   * Adds item into a queue only if it's unique.
   *
   * @param string $queueName
   *   Queue name.
   * @param array $data
   *   Data to be added.
   */
  public function addItem($queueName, $data) {
    $serializedData = serialize($data);
    $count = $this->databaseConnection
      ->select('queue', 'q')
      ->condition('q.name', $queueName)
      ->condition('q.data', $serializedData)
      ->countQuery()
      ->execute()
      ->fetchField();
    if ($count != 0) {
      return;
    }
    $result = $this->queueFactory
      ->get($queueName)
      ->createItem($data);
    if ($result) {
      $this->logger
        ->info('New unique item has been added into the "@queue" queue. Serialized queue item: @item.', [
        '@queue' => $queueName,
        '@item' => $serializedData,
      ]);
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
UniqueQueueItem::$databaseConnection private property
UniqueQueueItem::$logger private property
UniqueQueueItem::$queueFactory private property
UniqueQueueItem::addItem public function Adds item into a queue only if it's unique.
UniqueQueueItem::__construct public function