class UniqueQueueItem in TMGMT Extension Suite 8
Same name and namespace in other branches
- 8.3 src/Utils/UniqueQueueItem.php \Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem
- 8.2 src/Utils/UniqueQueueItem.php \Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem
Hierarchy
- class \Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem
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'
1 service uses UniqueQueueItem
File
- src/
Utils/ UniqueQueueItem.php, line 14 - Contains QueueUniqueItem service class.
Namespace
Drupal\tmgmt_extension_suit\UtilsView 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
Name | Modifiers | Type | Description | Overrides |
---|---|---|---|---|
UniqueQueueItem:: |
private | property | ||
UniqueQueueItem:: |
private | property | ||
UniqueQueueItem:: |
private | property | ||
UniqueQueueItem:: |
public | function | Adds item into a queue only if it's unique. | |
UniqueQueueItem:: |
public | function |