Skip to content

Commit f226d98

Browse files
committed
Merge branch '5.1' into 5.x
* 5.1: [Messenger] Fix DBAL deprecations in PostgreSQLConnection [DoctrineBridge] Fix DBAL deprecations in middlewares.
2 parents 5c5b8d6 + 245d041 commit f226d98

File tree

4 files changed

+10
-8
lines changed

4 files changed

+10
-8
lines changed

src/Symfony/Bridge/Doctrine/Messenger/DoctrinePingConnectionMiddleware.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Bridge\Doctrine\Messenger;
1313

1414
use Doctrine\DBAL\DBALException;
15+
use Doctrine\DBAL\Exception;
1516
use Doctrine\ORM\EntityManagerInterface;
1617
use Symfony\Component\Messenger\Envelope;
1718
use Symfony\Component\Messenger\Middleware\StackInterface;
@@ -38,8 +39,8 @@ private function pingConnection(EntityManagerInterface $entityManager)
3839
$connection = $entityManager->getConnection();
3940

4041
try {
41-
$connection->query($connection->getDatabasePlatform()->getDummySelectSQL());
42-
} catch (DBALException $e) {
42+
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
43+
} catch (DBALException | Exception $e) {
4344
$connection->close();
4445
$connection->connect();
4546
}

src/Symfony/Bridge/Doctrine/Tests/Messenger/DoctrinePingConnectionMiddlewareTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\DBAL\Connection;
1515
use Doctrine\DBAL\DBALException;
16+
use Doctrine\DBAL\Exception;
1617
use Doctrine\ORM\EntityManagerInterface;
1718
use Doctrine\Persistence\ManagerRegistry;
1819
use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware;
@@ -49,7 +50,7 @@ public function testMiddlewarePingOk()
4950
{
5051
$this->connection->expects($this->once())
5152
->method('getDatabasePlatform')
52-
->will($this->throwException(new DBALException()));
53+
->will($this->throwException(class_exists(Exception::class) ? new Exception() : new DBALException()));
5354

5455
$this->connection->expects($this->once())
5556
->method('close')
@@ -68,7 +69,7 @@ public function testMiddlewarePingResetEntityManager()
6869
{
6970
$this->connection->expects($this->once())
7071
->method('getDatabasePlatform')
71-
->will($this->throwException(new DBALException()));
72+
->will($this->throwException(class_exists(Exception::class) ? new Exception() : new DBALException()));
7273

7374
$this->entityManager->expects($this->once())
7475
->method('isOpen')

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -341,7 +341,7 @@ private function executeQuery(string $sql, array $parameters = [], array $types
341341
return $stmt;
342342
}
343343

344-
private function executeStatement(string $sql, array $parameters = [], array $types = [])
344+
protected function executeStatement(string $sql, array $parameters = [], array $types = [])
345345
{
346346
try {
347347
if (method_exists($this->driverConnection, 'executeStatement')) {

src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/PostgreSqlConnection.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ public function get(): ?array
6464
if (!$this->listening) {
6565
// This is secure because the table name must be a valid identifier:
6666
// https://www.postgresql.org/docs/current/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS
67-
$this->driverConnection->exec(sprintf('LISTEN "%s"', $this->configuration['table_name']));
67+
$this->executeStatement(sprintf('LISTEN "%s"', $this->configuration['table_name']));
6868
$this->listening = true;
6969
}
7070

@@ -87,7 +87,7 @@ public function setup(): void
8787
{
8888
parent::setup();
8989

90-
$this->driverConnection->exec(implode("\n", $this->getTriggerSql()));
90+
$this->executeStatement(implode("\n", $this->getTriggerSql()));
9191
}
9292

9393
/**
@@ -134,7 +134,7 @@ private function unlisten()
134134
return;
135135
}
136136

137-
$this->driverConnection->exec(sprintf('UNLISTEN "%s"', $this->configuration['table_name']));
137+
$this->executeStatement(sprintf('UNLISTEN "%s"', $this->configuration['table_name']));
138138
$this->listening = false;
139139
}
140140
}

0 commit comments

Comments
 (0)