Skip to content

Commit

Permalink
[Lock] fix compat with doctrine/dbal v3
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolas-grekas committed Jun 9, 2020
1 parent 55b1ae7 commit cac1205
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions Store/PdoStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\Exception\InvalidTtlException;
Expand Down Expand Up @@ -168,10 +169,10 @@ public function putOffExpiration(Key $key, $ttl)
$stmt->bindValue(':id', $this->getHashedKey($key));
$stmt->bindValue(':token1', $uniqueToken);
$stmt->bindValue(':token2', $uniqueToken);
$stmt->execute();
$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 (!$stmt->rowCount() && !$this->exists($key)) {
if (!($result instanceof Result ? $result : $stmt)->rowCount() && !$this->exists($key)) {
throw new LockConflictedException();
}

Expand Down Expand Up @@ -201,9 +202,9 @@ public function exists(Key $key)

$stmt->bindValue(':id', $this->getHashedKey($key));
$stmt->bindValue(':token', $this->getUniqueToken($key));
$stmt->execute();
$result = $stmt->execute();

return (bool) (method_exists($stmt, 'fetchOne') ? $stmt->fetchOne() : $stmt->fetchColumn());
return (bool) ($result instanceof Result ? $result->fetchOne() : $stmt->fetchColumn());
}

/**
Expand Down

0 comments on commit cac1205

Please sign in to comment.