Skip to content

Commit

Permalink
bug #37169 [Cache] fix forward compatibility with Doctrine DBAL 3 (xa…
Browse files Browse the repository at this point in the history
…bbuh)

This PR was merged into the 3.4 branch.

Discussion
----------

[Cache] fix forward compatibility with Doctrine DBAL 3

| Q             | A
| ------------- | ---
| Branch?       | 3.4
| Bug fix?      | yes
| New feature?  | no
| Deprecations? | no
| Tickets       | Fix #36987 (comment)
| License       | MIT
| Doc PR        |

Commits
-------

316efef fix forward compatibility with Doctrine DBAL 3
  • Loading branch information
nicolas-grekas committed Jun 9, 2020
2 parents 911c5d5 + 316efef commit e26d5f2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
Expand Up @@ -11,6 +11,8 @@

namespace Symfony\Component\Cache\Tests\Traits;

use Doctrine\DBAL\Result;

trait PdoPruneableTrait
{
protected function isPruned($cache, $name)
Expand All @@ -27,8 +29,8 @@ protected function isPruned($cache, $name)
/** @var \Doctrine\DBAL\Statement|\PDOStatement $select */
$select = $getPdoConn->invoke($cache)->prepare('SELECT 1 FROM cache_items WHERE item_id LIKE :id');
$select->bindValue(':id', sprintf('%%%s', $name));
$select->execute();
$result = $select->execute();

return 1 !== (int) (method_exists($select, 'fetchOne') ? $select->fetchOne() : $select->fetch(\PDO::FETCH_COLUMN));
return 1 !== (int) ($result instanceof Result ? $result->fetchOne() : $select->fetch(\PDO::FETCH_COLUMN));
}
}
14 changes: 8 additions & 6 deletions src/Symfony/Component/Cache/Traits/PdoTrait.php
Expand Up @@ -14,6 +14,7 @@
use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\Result;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\Cache\Exception\InvalidArgumentException;

Expand Down Expand Up @@ -175,15 +176,16 @@ protected function doFetch(array $ids)
foreach ($ids as $id) {
$stmt->bindValue(++$i, $id);
}
$stmt->execute();
$result = $stmt->execute();

if (method_exists($stmt, 'iterateNumeric')) {
$stmt = $stmt->iterateNumeric();
if ($result instanceof Result) {
$result = $result->iterateNumeric();
} else {
$stmt->setFetchMode(\PDO::FETCH_NUM);
$result = $stmt;
}

foreach ($stmt as $row) {
foreach ($result as $row) {
if (null === $row[1]) {
$expired[] = $row[0];
} else {
Expand Down Expand Up @@ -213,9 +215,9 @@ protected function doHave($id)

$stmt->bindValue(':id', $id);
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
$stmt->execute();
$result = $stmt->execute();

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

/**
Expand Down

0 comments on commit e26d5f2

Please sign in to comment.