Same name and namespace in other branches
  1. 8.9.x core/lib/Drupal/Core/TempStore/PrivateTempStore.php \Drupal\Core\TempStore\PrivateTempStore::delete()
  2. 9 core/lib/Drupal/Core/TempStore/PrivateTempStore.php \Drupal\Core\TempStore\PrivateTempStore::delete()

Deletes data from the store for a given key and releases the lock on it.

Parameters

string $key: The key of the data to delete.

Return value

bool TRUE if the object was deleted or does not exist, FALSE if it exists but is not owned by $this->owner.

Throws

\Drupal\Core\TempStore\TempStoreException Thrown when a lock for the backend storage could not be acquired.

File

core/lib/Drupal/Core/TempStore/PrivateTempStore.php, line 181

Class

PrivateTempStore
Stores and retrieves temporary data for a given owner.

Namespace

Drupal\Core\TempStore

Code

public function delete($key) {
  $key = $this
    ->createKey($key);
  if (!($object = $this->storage
    ->get($key))) {
    return TRUE;
  }
  elseif ($object->owner != $this
    ->getOwner()) {
    return FALSE;
  }
  if (!$this->lockBackend
    ->acquire($key)) {
    $this->lockBackend
      ->wait($key);
    if (!$this->lockBackend
      ->acquire($key)) {
      throw new TempStoreException("Couldn't acquire lock to delete item '{$key}' from '{$this->storage->getCollectionName()}' temporary storage.");
    }
  }
  $this->storage
    ->delete($key);
  $this->lockBackend
    ->release($key);
  return TRUE;
}