public function UniqueQueueItem::addItem in TMGMT Extension Suite 8.3
Same name and namespace in other branches
- 8 src/Utils/UniqueQueueItem.php \Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem::addItem()
- 8.2 src/Utils/UniqueQueueItem.php \Drupal\tmgmt_extension_suit\Utils\UniqueQueueItem::addItem()
Adds item into a queue only if it's unique.
Parameters
string $queue_name: Queue name.
array $data: Data to be added.
bool $force: Force adding item into the queue.
File
- src/
Utils/ UniqueQueueItem.php, line 65
Class
- UniqueQueueItem
- Class UniqueQueueItem.
Namespace
Drupal\tmgmt_extension_suit\UtilsCode
public function addItem($queue_name, array $data, $force = FALSE) {
$serialized_data = serialize($data);
if (!$force) {
$count = $this->databaseConnection
->select('queue', 'q')
->condition('q.name', $queue_name)
->condition('q.data', $serialized_data)
->countQuery()
->execute()
->fetchField();
if ($count != 0) {
return;
}
}
$result = $this->queueFactory
->get($queue_name)
->createItem($data);
if ($result) {
$this->logger
->info('New unique item has been added into the "@queue" queue. Serialized queue item: @item, forced: @forced.', [
'@queue' => $queue_name,
'@item' => $serialized_data,
'@forced' => (int) $force,
]);
}
}