public function UniqueDatabaseQueue::doCreateItem in Queue Unique 8.2
Adds a queue item and store it directly to the queue.
Parameters
$data: Arbitrary data to be associated with the new task in the queue.
Return value
A unique ID if the item was successfully created and was (best effort) added to the queue, otherwise FALSE. We don't guarantee the item was committed to disk etc, but as far as we know, the item is now in the queue.
Overrides DatabaseQueue::doCreateItem
File
- src/
UniqueDatabaseQueue.php, line 33
Class
- UniqueDatabaseQueue
- Database queue implementation which only adds unique items.
Namespace
Drupal\queue_uniqueCode
public function doCreateItem($data) {
try {
$serialized_data = serialize($data);
$query = $this->connection
->insert(static::TABLE_NAME)
->fields([
'name' => $this->name,
'data' => $serialized_data,
'created' => time(),
// Generate a near-unique value for this data on this queue.
'hash' => static::hash($this->name, $serialized_data),
]);
return $query
->execute();
} catch (IntegrityConstraintViolationException $e) {
// Assume this is because we have violated the uniqueness constraint.
// Return FALSE to indicate that no item has been placed on the queue as
// specified by QueueInterface.
return FALSE;
}
}