Skip to content

Commit f9414a8

Browse files
bug #29260 [Lock] Fixed PdoStore::putOffExpiration(), PdoStore::getHashedKey() (PavelPrischepa)
This PR was merged into the 4.2-dev branch. Discussion ---------- [Lock] Fixed PdoStore::putOffExpiration(), PdoStore::getHashedKey() | Q | A | ------------- | --- | Branch? | master | Bug fix? | yes | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | It seems no | Fixed tickets | | License | MIT | Doc PR | 1. Fixed PDO Statement exception in PdoStore::putOffExpiration(): ``` An exception occurred while executing 'UPDATE lock_keys SET key_expiration = UNIX_TIMESTAMP() + 10, key_token = :token WHERE key_id = :id AND (key_token = :token OR key_expiration <= UNIX_TIMESTAMP())' with params ["dcfc5ff369bc1896563 325c2e90478154eb670f6b6ebad3617e946ecb1f81517", "FRJOnftxRwPIgIRVb4EpOIVFwNjTmx0fwkBSTVJdViI="]: SQLSTATE[HY093]: Invalid parameter number ``` 2. Added explicit casting `Key` to `string` in getHashedKey() to avoid error with `strict_types` enabled. Commits ------- a639301 [Lock] Fixed PDOStatement exception "Invalid parameter number" in putOffExpiration()
2 parents 4c1e8bd + a639301 commit f9414a8

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

src/Symfony/Component/Lock/Store/PdoStore.php

+5-3
Original file line numberDiff line numberDiff line change
@@ -164,11 +164,13 @@ public function putOffExpiration(Key $key, $ttl)
164164

165165
$key->reduceLifetime($ttl);
166166

167-
$sql = "UPDATE $this->table SET $this->expirationCol = {$this->getCurrentTimestampStatement()} + $ttl, $this->tokenCol = :token WHERE $this->idCol = :id AND ($this->tokenCol = :token OR $this->expirationCol <= {$this->getCurrentTimestampStatement()})";
167+
$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()})";
168168
$stmt = $this->getConnection()->prepare($sql);
169169

170+
$uniqueToken = $this->getUniqueToken($key);
170171
$stmt->bindValue(':id', $this->getHashedKey($key));
171-
$stmt->bindValue(':token', $this->getUniqueToken($key));
172+
$stmt->bindValue(':token1', $uniqueToken);
173+
$stmt->bindValue(':token2', $uniqueToken);
172174
$stmt->execute();
173175

174176
// 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
@@ -214,7 +216,7 @@ public function exists(Key $key)
214216
*/
215217
private function getHashedKey(Key $key): string
216218
{
217-
return hash('sha256', $key);
219+
return hash('sha256', (string) $key);
218220
}
219221

220222
private function getUniqueToken(Key $key): string

0 commit comments

Comments
 (0)