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

Skip to content

Commit ce9130e

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

File tree

4 files changed

+25
-2
lines changed

4 files changed

+25
-2
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ private function init($connOrDsn, string $namespace, int $defaultLifetime, array
8585
*
8686
* @throws \PDOException When the table already exists
8787
* @throws DBALException When the table already exists
88+
* @throws Exception When the table already exists
8889
* @throws \DomainException When an unsupported PDO driver is used
8990
*/
9091
public function createTable()

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

Lines changed: 5 additions & 0 deletions
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,6 +128,9 @@ public function save(Key $key)
127128

128129
try {
129130
$stmt->execute();
131+
} catch (Exception $e) {
132+
// the lock is already acquired. It could be us. Let's try to put off.
133+
$this->putOffExpiration($key, $this->initialTtl);
130134
} catch (DBALException $e) {
131135
// the lock is already acquired. It could be us. Let's try to put off.
132136
$this->putOffExpiration($key, $this->initialTtl);
@@ -250,6 +254,7 @@ private function getConnection()
250254
*
251255
* @throws \PDOException When the table already exists
252256
* @throws DBALException When the table already exists
257+
* @throws Exception When the table already exists
253258
* @throws \DomainException When an unsupported PDO driver is used
254259
*/
255260
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: 6 additions & 0 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,6 +207,8 @@ public function ack(string $id): bool
205207
{
206208
try {
207209
return $this->driverConnection->delete($this->configuration['table_name'], ['id' => $id]) > 0;
210+
} catch (Exception $exception) {
211+
throw new TransportException($exception->getMessage(), 0, $exception);
208212
} catch (DBALException $exception) {
209213
throw new TransportException($exception->getMessage(), 0, $exception);
210214
}
@@ -214,6 +218,8 @@ public function reject(string $id): bool
214218
{
215219
try {
216220
return $this->driverConnection->delete($this->configuration['table_name'], ['id' => $id]) > 0;
221+
} catch (Exception $exception) {
222+
throw new TransportException($exception->getMessage(), 0, $exception);
217223
} catch (DBALException $exception) {
218224
throw new TransportException($exception->getMessage(), 0, $exception);
219225
}

0 commit comments

Comments
 (0)
0