bug #37169 [Cache] fix forward compatibility with Doctrine DBAL 3 (xabbuh)
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 https://github.com/symfony/symfony/pull/36987#issuecomment-641208638
| License | MIT
| Doc PR |
Commits
-------
316efef8b8
fix forward compatibility with Doctrine DBAL 3
This commit is contained in:
commit
e26d5f217b
@ -11,6 +11,8 @@
|
|||||||
|
|
||||||
namespace Symfony\Component\Cache\Tests\Traits;
|
namespace Symfony\Component\Cache\Tests\Traits;
|
||||||
|
|
||||||
|
use Doctrine\DBAL\Result;
|
||||||
|
|
||||||
trait PdoPruneableTrait
|
trait PdoPruneableTrait
|
||||||
{
|
{
|
||||||
protected function isPruned($cache, $name)
|
protected function isPruned($cache, $name)
|
||||||
@ -27,8 +29,8 @@ trait PdoPruneableTrait
|
|||||||
/** @var \Doctrine\DBAL\Statement|\PDOStatement $select */
|
/** @var \Doctrine\DBAL\Statement|\PDOStatement $select */
|
||||||
$select = $getPdoConn->invoke($cache)->prepare('SELECT 1 FROM cache_items WHERE item_id LIKE :id');
|
$select = $getPdoConn->invoke($cache)->prepare('SELECT 1 FROM cache_items WHERE item_id LIKE :id');
|
||||||
$select->bindValue(':id', sprintf('%%%s', $name));
|
$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,6 +14,7 @@ namespace Symfony\Component\Cache\Traits;
|
|||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
use Doctrine\DBAL\DBALException;
|
use Doctrine\DBAL\DBALException;
|
||||||
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
|
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
|
||||||
|
use Doctrine\DBAL\Result;
|
||||||
use Doctrine\DBAL\Schema\Schema;
|
use Doctrine\DBAL\Schema\Schema;
|
||||||
use Symfony\Component\Cache\Exception\InvalidArgumentException;
|
use Symfony\Component\Cache\Exception\InvalidArgumentException;
|
||||||
|
|
||||||
@ -175,15 +176,16 @@ trait PdoTrait
|
|||||||
foreach ($ids as $id) {
|
foreach ($ids as $id) {
|
||||||
$stmt->bindValue(++$i, $id);
|
$stmt->bindValue(++$i, $id);
|
||||||
}
|
}
|
||||||
$stmt->execute();
|
$result = $stmt->execute();
|
||||||
|
|
||||||
if (method_exists($stmt, 'iterateNumeric')) {
|
if ($result instanceof Result) {
|
||||||
$stmt = $stmt->iterateNumeric();
|
$result = $result->iterateNumeric();
|
||||||
} else {
|
} else {
|
||||||
$stmt->setFetchMode(\PDO::FETCH_NUM);
|
$stmt->setFetchMode(\PDO::FETCH_NUM);
|
||||||
|
$result = $stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
foreach ($stmt as $row) {
|
foreach ($result as $row) {
|
||||||
if (null === $row[1]) {
|
if (null === $row[1]) {
|
||||||
$expired[] = $row[0];
|
$expired[] = $row[0];
|
||||||
} else {
|
} else {
|
||||||
@ -213,9 +215,9 @@ trait PdoTrait
|
|||||||
|
|
||||||
$stmt->bindValue(':id', $id);
|
$stmt->bindValue(':id', $id);
|
||||||
$stmt->bindValue(':time', time(), \PDO::PARAM_INT);
|
$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());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Reference in New Issue
Block a user