From 969da48c98bbfeef88157c190a83ef3cb23fe930 Mon Sep 17 00:00:00 2001 From: "Alexander M. Turek" Date: Sat, 7 Nov 2020 15:21:55 +0100 Subject: [PATCH 1/2] [DoctrineBridge] Fix DBAL deprecations in middlewares. --- .../Doctrine/Messenger/DoctrinePingConnectionMiddleware.php | 5 +++-- .../Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php b/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php index 3ec525d2cf..c6b219aa79 100644 --- a/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php +++ b/src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php @@ -12,6 +12,7 @@ namespace Symfony\Bridge\Doctrine\Messenger; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\ORM\EntityManagerInterface; use Symfony\Component\Messenger\Envelope; use Symfony\Component\Messenger\Middleware\StackInterface; @@ -38,8 +39,8 @@ class DoctrinePingConnectionMiddleware extends AbstractDoctrineMiddleware $connection = $entityManager->getConnection(); try { - $connection->query($connection->getDatabasePlatform()->getDummySelectSQL()); - } catch (DBALException $e) { + $connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL()); + } catch (DBALException | Exception $e) { $connection->close(); $connection->connect(); } diff --git a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php index e491558a2a..f99a48527c 100644 --- a/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php +++ b/src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php @@ -13,6 +13,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Messenger; use Doctrine\DBAL\Connection; use Doctrine\DBAL\DBALException; +use Doctrine\DBAL\Exception; use Doctrine\ORM\EntityManagerInterface; use Doctrine\Persistence\ManagerRegistry; use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware; @@ -49,7 +50,7 @@ class DoctrinePingConnectionMiddlewareTest extends MiddlewareTestCase { $this->connection->expects($this->once()) ->method('getDatabasePlatform') - ->will($this->throwException(new DBALException())); + ->will($this->throwException(class_exists(Exception::class) ? new Exception() : new DBALException())); $this->connection->expects($this->once()) ->method('close') @@ -68,7 +69,7 @@ class DoctrinePingConnectionMiddlewareTest extends MiddlewareTestCase { $this->connection->expects($this->once()) ->method('getDatabasePlatform') - ->will($this->throwException(new DBALException())); + ->will($this->throwException(class_exists(Exception::class) ? new Exception() : new DBALException())); $this->entityManager->expects($this->once()) ->method('isOpen') From bc42cf604e9ff2cf716bc087e144ade92a881dbc Mon Sep 17 00:00:00 2001 From: Robin Chalas Date: Sat, 7 Nov 2020 15:33:20 +0100 Subject: [PATCH 2/2] [Messenger] Fix DBAL deprecations in PostgreSQLConnection --- .../Messenger/Bridge/Doctrine/Transport/Connection.php | 2 +- .../Bridge/Doctrine/Transport/PostgreSqlConnection.php | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php index ba095f288c..51d29c6353 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php @@ -372,7 +372,7 @@ class Connection implements ResetInterface return $stmt; } - private function executeStatement(string $sql, array $parameters = [], array $types = []) + protected function executeStatement(string $sql, array $parameters = [], array $types = []) { try { if (method_exists($this->driverConnection, 'executeStatement')) { diff --git a/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/PostgreSqlConnection.php b/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/PostgreSqlConnection.php index 79a1dd68ba..9dc8b77e38 100644 --- a/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/PostgreSqlConnection.php +++ b/src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/PostgreSqlConnection.php @@ -64,7 +64,7 @@ final class PostgreSqlConnection extends Connection if (!$this->listening) { // This is secure because the table name must be a valid identifier: // https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS - $this->driverConnection->exec(sprintf('LISTEN "%s"', $this->configuration['table_name'])); + $this->executeStatement(sprintf('LISTEN "%s"', $this->configuration['table_name'])); $this->listening = true; } @@ -87,7 +87,7 @@ final class PostgreSqlConnection extends Connection { parent::setup(); - $this->driverConnection->exec(implode("\n", $this->getTriggerSql())); + $this->executeStatement(implode("\n", $this->getTriggerSql())); } /** @@ -134,7 +134,7 @@ SQL return; } - $this->driverConnection->exec(sprintf('UNLISTEN "%s"', $this->configuration['table_name'])); + $this->executeStatement(sprintf('UNLISTEN "%s"', $this->configuration['table_name'])); $this->listening = false; } }