You are here

public function SystemSetQueue::createItem in Queue Unique 7

Same name and namespace in other branches
  1. 7.2 src/Queue/SystemSetQueue.php \Drupal\queue_unique\Queue\SystemSetQueue::createItem()

File

src/Queue/SystemSetQueue.php, line 31
Contains \Drupal\queue_unique\Queue\SystemSetQueue

Class

SystemSetQueue

Namespace

Drupal\queue_unique\Queue

Code

public function createItem($data) {

  // During a Drupal 6.x to 7.x update, drupal_get_schema() does not contain
  // the queue table yet, so we cannot rely on drupal_write_record().
  $sql = "INSERT INTO {" . static::TABLE_NAME . "} (name, created, data, md5) VALUES (:name, :created, :data, MD5(:md5))";
  try {
    return (bool) db_query($sql, array(
      ':name' => $this->name,
      ':data' => serialize($data),
      // We cannot rely on REQUEST_TIME because many items might be created
      // by a single request which takes longer than 1 second.
      ':created' => time(),
      ':md5' => $this->name . serialize($data),
    ));
  } catch (\PDOException $e) {
    throw new SystemSetQueueException(sprintf('Attempted to insert a duplicated item. (%s).', $e
      ->getMessage()));
  }
}