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

Breadcrumb

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

function PdoStore::save

Overrides PersistingStoreInterface::save

File

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

Class

PdoStore
PdoStore is a PersistingStoreInterface implementation using a PDO connection.

Namespace

Symfony\Component\Lock\Store

Code

public function save(Key $key) : void {
    $key->reduceLifetime($this->initialTtl);
    $sql = "INSERT INTO {$this->table} ({$this->idCol}, {$this->tokenCol}, {$this->expirationCol}) VALUES (:id, :token, {$this->getCurrentTimestampStatement()} + {$this->initialTtl})";
    $conn = $this->getConnection();
    try {
        $stmt = $conn->prepare($sql);
    } catch (\PDOException $e) {
        if ($this->isTableMissing($e) && (!$conn->inTransaction() || \in_array($this->getDriver(), [
            'pgsql',
            'sqlite',
            'sqlsrv',
        ], true))) {
            $this->createTable();
        }
        $stmt = $conn->prepare($sql);
    }
    $stmt->bindValue(':id', $this->getHashedKey($key));
    $stmt->bindValue(':token', $this->getUniqueToken($key));
    try {
        $stmt->execute();
    } catch (\PDOException $e) {
        if ($this->isTableMissing($e) && (!$conn->inTransaction() || \in_array($this->getDriver(), [
            'pgsql',
            'sqlite',
            'sqlsrv',
        ], true))) {
            $this->createTable();
            try {
                $stmt->execute();
            } catch (\PDOException) {
                $this->putOffExpiration($key, $this->initialTtl);
            }
        }
        else {
            // the lock is already acquired. It could be us. Let's try to put off.
            $this->putOffExpiration($key, $this->initialTtl);
        }
    }
    $this->randomlyPrune();
    $this->checkNotExpired($key);
}

API Navigation

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