Skip to main content
Drupal API
User account menu
  • Log in

Breadcrumb

  1. Drupal Core 11.1.x
  2. PdoStore.php

function PdoStore::putOffExpiration

Overrides PersistingStoreInterface::putOffExpiration

1 call to PdoStore::putOffExpiration()
PdoStore::save in vendor/symfony/lock/Store/PdoStore.php
Stores the resource if it's not locked by someone else.

File

vendor/symfony/lock/Store/PdoStore.php, line 125

Class

PdoStore
PdoStore is a PersistingStoreInterface implementation using a PDO connection.

Namespace

Symfony\Component\Lock\Store

Code

public function putOffExpiration(Key $key, float $ttl) : void {
    if ($ttl < 1) {
        throw new InvalidTtlException(\sprintf('"%s()" expects a TTL greater or equals to 1 second. Got "%s".', __METHOD__, $ttl));
    }
    $key->reduceLifetime($ttl);
    $sql = "UPDATE {$this->table} SET {$this->expirationCol} = {$this->getCurrentTimestampStatement()} + {$ttl}, {$this->tokenCol} = :token1 WHERE {$this->idCol} = :id AND ({$this->tokenCol} = :token2 OR {$this->expirationCol} <= {$this->getCurrentTimestampStatement()})";
    $stmt = $this->getConnection()
        ->prepare($sql);
    $uniqueToken = $this->getUniqueToken($key);
    $stmt->bindValue(':id', $this->getHashedKey($key));
    $stmt->bindValue(':token1', $uniqueToken);
    $stmt->bindValue(':token2', $uniqueToken);
    $result = $stmt->execute();
    // If this method is called twice in the same second, the row wouldn't be updated. We have to call exists to know if we are the owner
    if (!(\is_object($result) ? $result : $stmt)->rowCount() && !$this->exists($key)) {
        throw new LockConflictedException();
    }
    $this->checkNotExpired($key);
}

API Navigation

  • Drupal Core 11.1.x
  • Topics
  • Classes
  • Functions
  • Constants
  • Globals
  • Files
  • Namespaces
  • Deprecated
  • Services
RSS feed
Powered by Drupal