Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 966dc58

Browse filesBrowse files
committed
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 ------- a038851 fix compatibility with Doctrine DBAL 3
2 parents 50f37f0 + a038851 commit 966dc58
Copy full SHA for 966dc58

File tree

6 files changed

+32
-13
lines changed
Filter options

6 files changed

+32
-13
lines changed

‎src/Symfony/Component/Cache/Traits/PdoTrait.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Cache/Traits/PdoTrait.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
use Doctrine\DBAL\Driver\Result as DriverResult;
1818
use Doctrine\DBAL\Driver\ServerInfoAwareConnection;
1919
use Doctrine\DBAL\DriverManager;
20+
use Doctrine\DBAL\Exception;
2021
use Doctrine\DBAL\Exception\TableNotFoundException;
2122
use Doctrine\DBAL\Schema\Schema;
2223
use Symfony\Component\Cache\Exception\InvalidArgumentException;
@@ -85,6 +86,7 @@ private function init($connOrDsn, string $namespace, int $defaultLifetime, array
8586
*
8687
* @throws \PDOException When the table already exists
8788
* @throws DBALException When the table already exists
89+
* @throws Exception When the table already exists
8890
* @throws \DomainException When an unsupported PDO driver is used
8991
*/
9092
public function createTable()
@@ -392,7 +394,7 @@ protected function doSave(array $values, int $lifetime)
392394
if (null === $driver && !($result instanceof DriverResult ? $result : $stmt)->rowCount()) {
393395
try {
394396
$insertStmt->execute();
395-
} catch (DBALException $e) {
397+
} catch (DBALException | Exception $e) {
396398
} catch (\PDOException $e) {
397399
// A concurrent write won, let it be
398400
}

‎src/Symfony/Component/Lock/Store/PdoStore.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Lock/Store/PdoStore.php
+3-1Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use Doctrine\DBAL\DBALException;
1616
use Doctrine\DBAL\Driver\Result;
1717
use Doctrine\DBAL\DriverManager;
18+
use Doctrine\DBAL\Exception;
1819
use Doctrine\DBAL\Schema\Schema;
1920
use Symfony\Component\Lock\Exception\InvalidArgumentException;
2021
use Symfony\Component\Lock\Exception\InvalidTtlException;
@@ -127,7 +128,7 @@ public function save(Key $key)
127128

128129
try {
129130
$stmt->execute();
130-
} catch (DBALException $e) {
131+
} catch (DBALException | Exception $e) {
131132
// the lock is already acquired. It could be us. Let's try to put off.
132133
$this->putOffExpiration($key, $this->initialTtl);
133134
} catch (\PDOException $e) {
@@ -250,6 +251,7 @@ private function getConnection()
250251
*
251252
* @throws \PDOException When the table already exists
252253
* @throws DBALException When the table already exists
254+
* @throws Exception When the table already exists
253255
* @throws \DomainException When an unsupported PDO driver is used
254256
*/
255257
public function createTable(): void

‎src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Tests/Transport/Doctrine/ConnectionTest.php
+13-2Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
use Doctrine\DBAL\Abstraction\Result;
1515
use Doctrine\DBAL\DBALException;
16+
use Doctrine\DBAL\Exception;
1617
use Doctrine\DBAL\Platforms\AbstractPlatform;
1718
use Doctrine\DBAL\Query\QueryBuilder;
1819
use Doctrine\DBAL\Schema\AbstractSchemaManager;
@@ -87,7 +88,12 @@ public function testItThrowsATransportExceptionIfItCannotAcknowledgeMessage()
8788
{
8889
$this->expectException('Symfony\Component\Messenger\Exception\TransportException');
8990
$driverConnection = $this->getDBALConnectionMock();
90-
$driverConnection->method('delete')->willThrowException(new DBALException());
91+
92+
if (class_exists(Exception::class)) {
93+
$driverConnection->method('delete')->willThrowException(new Exception());
94+
} else {
95+
$driverConnection->method('delete')->willThrowException(new DBALException());
96+
}
9197

9298
$connection = new Connection([], $driverConnection);
9399
$connection->ack('dummy_id');
@@ -97,7 +103,12 @@ public function testItThrowsATransportExceptionIfItCannotRejectMessage()
97103
{
98104
$this->expectException('Symfony\Component\Messenger\Exception\TransportException');
99105
$driverConnection = $this->getDBALConnectionMock();
100-
$driverConnection->method('delete')->willThrowException(new DBALException());
106+
107+
if (class_exists(Exception::class)) {
108+
$driverConnection->method('delete')->willThrowException(new Exception());
109+
} else {
110+
$driverConnection->method('delete')->willThrowException(new DBALException());
111+
}
101112

102113
$connection = new Connection([], $driverConnection);
103114
$connection->reject('dummy_id');

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/Doctrine/Connection.php
+4-2Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Doctrine\DBAL\Connection as DBALConnection;
1515
use Doctrine\DBAL\DBALException;
1616
use Doctrine\DBAL\Driver\Result;
17+
use Doctrine\DBAL\Exception;
1718
use Doctrine\DBAL\Exception\TableNotFoundException;
1819
use Doctrine\DBAL\Query\QueryBuilder;
1920
use Doctrine\DBAL\Schema\Comparator;
@@ -110,6 +111,7 @@ public static function buildConfiguration(string $dsn, array $options = []): arr
110111
* @return string The inserted id
111112
*
112113
* @throws \Doctrine\DBAL\DBALException
114+
* @throws \Doctrine\DBAL\Exception
113115
*/
114116
public function send(string $body, array $headers, int $delay = 0): string
115117
{
@@ -205,7 +207,7 @@ public function ack(string $id): bool
205207
{
206208
try {
207209
return $this->driverConnection->delete($this->configuration['table_name'], ['id' => $id]) > 0;
208-
} catch (DBALException $exception) {
210+
} catch (DBALException | Exception $exception) {
209211
throw new TransportException($exception->getMessage(), 0, $exception);
210212
}
211213
}
@@ -214,7 +216,7 @@ public function reject(string $id): bool
214216
{
215217
try {
216218
return $this->driverConnection->delete($this->configuration['table_name'], ['id' => $id]) > 0;
217-
} catch (DBALException $exception) {
219+
} catch (DBALException | Exception $exception) {
218220
throw new TransportException($exception->getMessage(), 0, $exception);
219221
}
220222
}

‎src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineReceiver.php
+7-6Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Messenger\Transport\Doctrine;
1313

1414
use Doctrine\DBAL\DBALException;
15+
use Doctrine\DBAL\Exception;
1516
use Doctrine\DBAL\Exception\RetryableException;
1617
use Symfony\Component\Messenger\Envelope;
1718
use Symfony\Component\Messenger\Exception\LogicException;
@@ -58,7 +59,7 @@ public function get(): iterable
5859
}
5960

6061
return [];
61-
} catch (DBALException $exception) {
62+
} catch (DBALException | Exception $exception) {
6263
throw new TransportException($exception->getMessage(), 0, $exception);
6364
}
6465

@@ -76,7 +77,7 @@ public function ack(Envelope $envelope): void
7677
{
7778
try {
7879
$this->connection->ack($this->findDoctrineReceivedStamp($envelope)->getId());
79-
} catch (DBALException $exception) {
80+
} catch (DBALException | Exception $exception) {
8081
throw new TransportException($exception->getMessage(), 0, $exception);
8182
}
8283
}
@@ -88,7 +89,7 @@ public function reject(Envelope $envelope): void
8889
{
8990
try {
9091
$this->connection->reject($this->findDoctrineReceivedStamp($envelope)->getId());
91-
} catch (DBALException $exception) {
92+
} catch (DBALException | Exception $exception) {
9293
throw new TransportException($exception->getMessage(), 0, $exception);
9394
}
9495
}
@@ -100,7 +101,7 @@ public function getMessageCount(): int
100101
{
101102
try {
102103
return $this->connection->getMessageCount();
103-
} catch (DBALException $exception) {
104+
} catch (DBALException | Exception $exception) {
104105
throw new TransportException($exception->getMessage(), 0, $exception);
105106
}
106107
}
@@ -112,7 +113,7 @@ public function all(int $limit = null): iterable
112113
{
113114
try {
114115
$doctrineEnvelopes = $this->connection->findAll($limit);
115-
} catch (DBALException $exception) {
116+
} catch (DBALException | Exception $exception) {
116117
throw new TransportException($exception->getMessage(), 0, $exception);
117118
}
118119

@@ -128,7 +129,7 @@ public function find($id): ?Envelope
128129
{
129130
try {
130131
$doctrineEnvelope = $this->connection->find($id);
131-
} catch (DBALException $exception) {
132+
} catch (DBALException | Exception $exception) {
132133
throw new TransportException($exception->getMessage(), 0, $exception);
133134
}
134135

‎src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineSender.php

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Transport/Doctrine/DoctrineSender.php
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\Component\Messenger\Transport\Doctrine;
1313

1414
use Doctrine\DBAL\DBALException;
15+
use Doctrine\DBAL\Exception;
1516
use Symfony\Component\Messenger\Envelope;
1617
use Symfony\Component\Messenger\Exception\TransportException;
1718
use Symfony\Component\Messenger\Stamp\DelayStamp;
@@ -47,7 +48,7 @@ public function send(Envelope $envelope): Envelope
4748

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

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.