Skip to content

[Cache] fix forward compatibility with Doctrine DBAL 3 #37169

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
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
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\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