8000 fix compatibility with Doctrine DBAL 3 · symfony/symfony@92993bd · GitHub
[go: up one dir, main page]

Skip to content

Commit 92993bd

Browse files
committed
fix compatibility with Doctrine DBAL 3
1 parent 50f37f0 commit 92993bd

File tree

4 files changed

+23
-5
lines changed

4 files changed

+23
-5
lines changed

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

Lines changed: 3 additions & 0 deletions
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()
@@ -393,6 +395,7 @@ protected function doSave(array $values, int $lifetime)
393395
try {
394396
$insertStmt->execute();
395397
} catch (DBALException $e) {
398+
} catch (Exception $e) {
396399
} catch (\PDOException $e) {
397400
// A concurrent write won, let it be
398401
}

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

Lines 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

Lines 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

Lines 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
B41A 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
}

0 commit comments

Comments
 (0)
0