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\StoreCode
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);
}