Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Symfony/Component/Cache/Traits/PdoTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
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;
Expand Down Expand Up @@ -85,6 +86,7 @@ private function init($connOrDsn, string $namespace, int $defaultLifetime, array
*
* @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()
Expand Down Expand Up @@ -392,7 +394,7 @@ protected function doSave(array $values, int $lifetime)
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
}
Expand Down
4 changes: 3 additions & 1 deletion src/Symfony/Component/Lock/Store/PdoStore.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
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;
Expand Down Expand Up @@ -127,7 +128,7 @@ public function save(Key $key)

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) {
Expand Down Expand Up @@ -250,6 +251,7 @@ private function getConnection()
*
* @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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

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;
Expand Down Expand Up @@ -87,7 +88,12 @@ public function testItThrowsATransportExceptionIfItCannotAcknowledgeMessage()
{
$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');
Expand All @@ -97,7 +103,12 @@ public function testItThrowsATransportExceptionIfItCannotRejectMessage()
{
$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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
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;
Expand Down Expand Up @@ -110,6 +111,7 @@ public static function buildConfiguration(string $dsn, array $options = []): arr
* @return string The inserted id
*
* @throws \Doctrine\DBAL\DBALException
* @throws \Doctrine\DBAL\Exception
*/
public function send(string $body, array $headers, int $delay = 0): string
{
Expand Down Expand Up @@ -205,7 +207,7 @@ public function ack(string $id): bool
{
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);
}
}
Expand All @@ -214,7 +216,7 @@ public function reject(string $id): bool
{
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);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -58,7 +59,7 @@ public function get(): iterable
}

return [];
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}

Expand All @@ -76,7 +77,7 @@ public function ack(Envelope $envelope): void
{
try {
$this->connection->ack($this->findDoctrineReceivedStamp($envelope)->getId());
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}
}
Expand All @@ -88,7 +89,7 @@ public function reject(Envelope $envelope): void
{
try {
$this->connection->reject($this->findDoctrineReceivedStamp($envelope)->getId());
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}
}
Expand All @@ -100,7 +101,7 @@ public function getMessageCount(): int
{
try {
return $this->connection->getMessageCount();
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}
}
Expand All @@ -112,7 +113,7 @@ public function all(int $limit = null): iterable
{
try {
$doctrineEnvelopes = $this->connection->findAll($limit);
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}

Expand All @@ -128,7 +129,7 @@ public function find($id): ?Envelope
{
try {
$doctrineEnvelope = $this->connection->find($id);
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -47,7 +48,7 @@ public function send(Envelope $envelope): Envelope

try {
$id = $this->connection->send($encodedMessage['body'], $encodedMessage['headers'] ?? [], $delay);
} catch (DBALException $exception) {
} catch (DBALException | Exception $exception) {
throw new TransportException($exception->getMessage(), 0, $exception);
}

Expand Down