Merge branch '5.1' into 5.x
* 5.1: [Messenger] Fix DBAL deprecations in PostgreSQLConnection [DoctrineBridge] Fix DBAL deprecations in middlewares.
This commit is contained in:
commit
f226d981af
@ -12,6 +12,7 @@
|
|||||||
namespace Symfony\Bridge\Doctrine\Messenger;
|
namespace Symfony\Bridge\Doctrine\Messenger;
|
||||||
|
|
||||||
use Doctrine\DBAL\DBALException;
|
use Doctrine\DBAL\DBALException;
|
||||||
|
use Doctrine\DBAL\Exception;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Symfony\Component\Messenger\Envelope;
|
use Symfony\Component\Messenger\Envelope;
|
||||||
use Symfony\Component\Messenger\Middleware\StackInterface;
|
use Symfony\Component\Messenger\Middleware\StackInterface;
|
||||||
@ -38,8 +39,8 @@ class DoctrinePingConnectionMiddleware extends AbstractDoctrineMiddleware
|
|||||||
$connection = $entityManager->getConnection();
|
$connection = $entityManager->getConnection();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$connection->query($connection->getDatabasePlatform()->getDummySelectSQL());
|
$connection->executeQuery($connection->getDatabasePlatform()->getDummySelectSQL());
|
||||||
} catch (DBALException $e) {
|
} catch (DBALException | Exception $e) {
|
||||||
$connection->close();
|
$connection->close();
|
||||||
$connection->connect();
|
$connection->connect();
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ namespace Symfony\Bridge\Doctrine\Tests\Messenger;
|
|||||||
|
|
||||||
use Doctrine\DBAL\Connection;
|
use Doctrine\DBAL\Connection;
|
||||||
use Doctrine\DBAL\DBALException;
|
use Doctrine\DBAL\DBALException;
|
||||||
|
use Doctrine\DBAL\Exception;
|
||||||
use Doctrine\ORM\EntityManagerInterface;
|
use Doctrine\ORM\EntityManagerInterface;
|
||||||
use Doctrine\Persistence\ManagerRegistry;
|
use Doctrine\Persistence\ManagerRegistry;
|
||||||
use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware;
|
use Symfony\Bridge\Doctrine\Messenger\DoctrinePingConnectionMiddleware;
|
||||||
@ -49,7 +50,7 @@ class DoctrinePingConnectionMiddlewareTest extends MiddlewareTestCase
|
|||||||
{
|
{
|
||||||
$this->connection->expects($this->once())
|
$this->connection->expects($this->once())
|
||||||
->method('getDatabasePlatform')
|
->method('getDatabasePlatform')
|
||||||
->will($this->throwException(new DBALException()));
|
->will($this->throwException(class_exists(Exception::class) ? new Exception() : new DBALException()));
|
||||||
|
|
||||||
$this->connection->expects($this->once())
|
$this->connection->expects($this->once())
|
||||||
->method('close')
|
->method('close')
|
||||||
@ -68,7 +69,7 @@ class DoctrinePingConnectionMiddlewareTest extends MiddlewareTestCase
|
|||||||
{
|
{
|
||||||
$this->connection->expects($this->once())
|
$this->connection->expects($this->once())
|
||||||
->method('getDatabasePlatform')
|
->method('getDatabasePlatform')
|
||||||
->will($this->throwException(new DBALException()));
|
->will($this->throwException(class_exists(Exception::class) ? new Exception() : new DBALException()));
|
||||||
|
|
||||||
$this->entityManager->expects($this->once())
|
$this->entityManager->expects($this->once())
|
||||||
->method('isOpen')
|
->method('isOpen')
|
||||||
|
@ -341,7 +341,7 @@ class Connection implements ResetInterface
|
|||||||
return $stmt;
|
return $stmt;
|
||||||
}
|
}
|
||||||
|
|
||||||
private function executeStatement(string $sql, array $parameters = [], array $types = [])
|
protected function executeStatement(string $sql, array $parameters = [], array $types = [])
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
if (method_exists($this->driverConnection, 'executeStatement')) {
|
if (method_exists($this->driverConnection, 'executeStatement')) {
|
||||||
|
@ -64,7 +64,7 @@ final class PostgreSqlConnection extends Connection
|
|||||||
if (!$this->listening) {
|
if (!$this->listening) {
|
||||||
// This is secure because the table name must be a valid identifier:
|
// 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
|
// 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;
|
$this->listening = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ final class PostgreSqlConnection extends Connection
|
|||||||
{
|
{
|
||||||
parent::setup();
|
parent::setup();
|
||||||
|
|
||||||
$this->driverConnection->exec(implode("\n", $this->getTriggerSql()));
|
$this->executeStatement(implode("\n", $this->getTriggerSql()));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,7 +134,7 @@ SQL
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->driverConnection->exec(sprintf('UNLISTEN "%s"', $this->configuration['table_name']));
|
$this->executeStatement(sprintf('UNLISTEN "%s"', $this->configuration['table_name']));
|
||||||
$this->listening = false;
|
$this->listening = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user