bug #38284 [Cache][Lock][Messenger] fix compatibility with Doctrine DBAL 3 (xabbuh)

This PR was merged into the 4.4 branch.

Discussion
----------

[Cache][Lock][Messenger] fix compatibility with Doctrine DBAL 3

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       |
| License       | MIT
| Doc PR        |

Commits
-------

a03885168e fix compatibility with Doctrine DBAL 3
This commit is contained in:
Christian Flothmann 2020-09-24 09:08:24 +02:00
commit 966dc5814a
6 changed files with 32 additions and 13 deletions

View File

@ -17,6 +17,7 @@ use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Result as DriverResult;
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\Cache\Exception\InvalidArgumentException;
@ -85,6 +86,7 @@ trait PdoTrait
*
* @throws \PDOException When the table already exists
* @throws DBALException When the table already exists
* @throws Exception When the table already exists
* @throws \DomainException When an unsupported PDO driver is used
*/
public function createTable()
@ -392,7 +394,7 @@ trait PdoTrait
if (null === $driver && !($result instanceof DriverResult ? $result : $stmt)->rowCount()) {
try {
$insertStmt->execute();
} catch (DBALException $e) {
} catch (DBALException | Exception $e) {
} catch (\PDOException $e) {
// A concurrent write won, let it be
}

View File

@ -15,6 +15,7 @@ use Doctrine\DBAL\Connection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\DriverManager;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Schema\Schema;
use Symfony\Component\Lock\Exception\InvalidArgumentException;
use Symfony\Component\Lock\Exception\InvalidTtlException;
@ -127,7 +128,7 @@ class PdoStore implements StoreInterface
try {
$stmt->execute();
} catch (DBALException $e) {
} catch (DBALException | Exception $e) {
// the lock is already acquired. It could be us. Let's try to put off.
$this->putOffExpiration($key, $this->initialTtl);
} catch (\PDOException $e) {
@ -250,6 +251,7 @@ class PdoStore implements StoreInterface
*
* @throws \PDOException When the table already exists
* @throws DBALException When the table already exists
* @throws Exception When the table already exists
* @throws \DomainException When an unsupported PDO driver is used
*/
public function createTable(): void

View File

@ -13,6 +13,7 @@ namespace Symfony\Component\Messenger\Tests\Transport\Doctrine;
use Doctrine\DBAL\Abstraction\Result;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Platforms\AbstractPlatform;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\AbstractSchemaManager;
@ -87,7 +88,12 @@ class ConnectionTest extends TestCase
{
$this->expectException('Symfony\Component\Messenger\Exception\TransportException');
$driverConnection = $this->getDBALConnectionMock();
$driverConnection->method('delete')->willThrowException(new DBALException());
if (class_exists(Exception::class)) {
$driverConnection->method('delete')->willThrowException(new Exception());
} else {
$driverConnection->method('delete')->willThrowException(new DBALException());
}
$connection = new Connection([], $driverConnection);
$connection->ack('dummy_id');
@ -97,7 +103,12 @@ class ConnectionTest extends TestCase
{
$this->expectException('Symfony\Component\Messenger\Exception\TransportException');
$driverConnection = $this->getDBALConnectionMock();
$driverConnection->method('delete')->willThrowException(new DBALException());
if (class_exists(Exception::class)) {
$driverConnection->method('delete')->willThrowException(new Exception());
} else {
$driverConnection->method('delete')->willThrowException(new DBALException());
}
$connection = new Connection([], $driverConnection);
$connection->reject('dummy_id');

View File

@ -14,6 +14,7 @@ namespace Symfony\Component\Messenger\Transport\Doctrine;
use Doctrine\DBAL\Connection as DBALConnection;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Driver\Result;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\TableNotFoundException;
use Doctrine\DBAL\Query\QueryBuilder;
use Doctrine\DBAL\Schema\Comparator;
@ -110,6 +111,7 @@ class Connection
* @return string The inserted id
*
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Exception
*/
public function send(string $body, array $headers, int $delay = 0): string
{
@ -205,7 +207,7 @@ class Connection
{
try {
return $this->driverConnection->delete($this->configuration['table_name'], ['id' => $id]) > 0;
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}
}
@ -214,7 +216,7 @@ class Connection
{
try {
return $this->driverConnection->delete($this->configuration['table_name'], ['id' => $id]) > 0;
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}
}

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Messenger\Transport\Doctrine;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception;
use Doctrine\DBAL\Exception\RetryableException;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\LogicException;
@ -58,7 +59,7 @@ class DoctrineReceiver implements ReceiverInterface, MessageCountAwareInterface,
}
return [];
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}
@ -76,7 +77,7 @@ class DoctrineReceiver implements ReceiverInterface, MessageCountAwareInterface,
{
try {
$this->connection->ack($this->findDoctrineReceivedStamp($envelope)->getId());
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}
}
@ -88,7 +89,7 @@ class DoctrineReceiver implements ReceiverInterface, MessageCountAwareInterface,
{
try {
$this->connection->reject($this->findDoctrineReceivedStamp($envelope)->getId());
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}
}
@ -100,7 +101,7 @@ class DoctrineReceiver implements ReceiverInterface, MessageCountAwareInterface,
{
try {
return $this->connection->getMessageCount();
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}
}
@ -112,7 +113,7 @@ class DoctrineReceiver implements ReceiverInterface, MessageCountAwareInterface,
{
try {
$doctrineEnvelopes = $this->connection->findAll($limit);
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}
@ -128,7 +129,7 @@ class DoctrineReceiver implements ReceiverInterface, MessageCountAwareInterface,
{
try {
$doctrineEnvelope = $this->connection->find($id);
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}

View File

@ -12,6 +12,7 @@
namespace Symfony\Component\Messenger\Transport\Doctrine;
use Doctrine\DBAL\DBALException;
use Doctrine\DBAL\Exception;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\TransportException;
use Symfony\Component\Messenger\Stamp\DelayStamp;
@ -47,7 +48,7 @@ class DoctrineSender implements SenderInterface
try {
$id = $this->connection->send($encodedMessage['body'], $encodedMessage['headers'] ?? [], $delay);
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}