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 2f059e0

Browse filesBrowse files
committed
fix compatibility with Doctrine DBAL 4
1 parent 5611ed4 commit 2f059e0
Copy full SHA for 2f059e0

File tree

Expand file treeCollapse file tree

2 files changed

+33
-4
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+33
-4
lines changed

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Doctrine/Tests/Transport/ConnectionTest.php
+17-2Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,9 @@ public function testGetWithNoPendingMessageWillReturnNull()
8282
$queryBuilder
8383
->method('getParameterTypes')
8484
->willReturn([]);
85+
$queryBuilder
86+
->method('getSQL')
87+
->willReturn('SELECT FOR UPDATE');
8588
$driverConnection->expects($this->once())
8689
->method('createQueryBuilder')
8790
->willReturn($queryBuilder);
@@ -120,7 +123,11 @@ private function getDBALConnectionMock()
120123
{
121124
$driverConnection = $this->createMock(DBALConnection::class);
122125
$platform = $this->createMock(AbstractPlatform::class);
123-
$platform->method('getWriteLockSQL')->willReturn('FOR UPDATE');
126+
127+
if (!method_exists(QueryBuilder::class, 'forUpdate')) {
128+
$platform->method('getWriteLockSQL')->willReturn('FOR UPDATE');
129+
}
130+
124131
$configuration = $this->createMock(\Doctrine\DBAL\Configuration::class);
125132
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
126133
$driverConnection->method('getConfiguration')->willReturn($configuration);
@@ -381,7 +388,9 @@ public function testGeneratedSql(AbstractPlatform $platform, string $expectedSql
381388
$driverConnection
382389
->expects($this->once())
383390
->method('executeQuery')
384-
->with($expectedSql)
391+
->with($this->callback(function ($sql) use ($expectedSql) {
392+
return trim($expectedSql) === trim($sql);
393+
}))
385394
->willReturn($result)
386395
;
387396
$driverConnection->expects($this->once())->method('commit');
@@ -415,6 +424,12 @@ class_exists(SQLServerPlatform::class) && !class_exists(SQLServer2012Platform::c
415424
new OraclePlatform(),
416425
'SELECT w.id AS "id", w.body AS "body", w.headers AS "headers", w.queue_name AS "queue_name", w.created_at AS "created_at", w.available_at AS "available_at", w.delivered_at AS "delivered_at" FROM messenger_messages w WHERE w.id IN (SELECT m.id FROM messenger_messages m WHERE (m.queue_name = ?) AND (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) ORDER BY available_at ASC FETCH NEXT 1 ROWS ONLY) FOR UPDATE',
417426
];
427+
} elseif (method_exists(QueryBuilder::class, 'forUpdate')) {
428+
// DBAL >= 3.8
429+
yield 'Oracle' => [
430+
new OraclePlatform(),
431+
'SELECT w.id AS "id", w.body AS "body", w.headers AS "headers", w.queue_name AS "queue_name", w.created_at AS "created_at", w.available_at AS "available_at", w.delivered_at AS "delivered_at" FROM messenger_messages w WHERE w.id IN (SELECT a.id FROM (SELECT m.id FROM messenger_messages m WHERE (m.queue_name = ?) AND (m.delivered_at is null OR m.delivered_at < ?) AND (m.available_at <= ?) ORDER BY available_at ASC) a WHERE ROWNUM <= 1 FOR UPDATE)',
432+
];
418433
} else {
419434
// DBAL < 4
420435
yield 'Oracle' => [

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

Copy file name to clipboardExpand all lines: src/Symfony/Component/Messenger/Bridge/Doctrine/Transport/Connection.php
+16-2Lines changed: 16 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\Driver\Exception as DriverException;
1616
use Doctrine\DBAL\Driver\Result as DriverResult;
17+
use Doctrine\DBAL\Exception;
1718
use Doctrine\DBAL\Exception as DBALException;
1819
use Doctrine\DBAL\Exception\TableNotFoundException;
1920
use Doctrine\DBAL\LockMode;
@@ -177,7 +178,16 @@ public function get(): ?array
177178

178179
// Append pessimistic write lock to FROM clause if db platform supports it
179180
$sql = $query->getSQL();
180-
if (preg_match('/FROM (.+) WHERE/', (string) $sql, $matches)) {
181+
182+
if (method_exists(QueryBuilder::class, 'forUpdate')) {
183+
$query->forUpdate();
184+
try {
185+
$sql = $query->getSQL();
186+
} catch (Exception $e) {
187+
}
188+
}
189+
190+
if (!method_exists(QueryBuilder::class, 'forUpdate') && preg_match('/FROM (.+) WHERE/', (string) $sql, $matches)) {
181191
$fromClause = $matches[1];
182192
$sql = str_replace(
183193
sprintf('FROM %s WHERE', $fromClause),
@@ -194,8 +204,12 @@ public function get(): ?array
194204
}
195205

196206
// use SELECT ... FOR UPDATE to lock table
207+
if (!method_exists(QueryBuilder::class, 'forUpdate')) {
208+
$sql .= ' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL();
209+
}
210+
197211
$stmt = $this->executeQuery(
198-
$sql.' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL(),
212+
$sql,
199213
$query->getParameters(),
200214
$query->getParameterTypes()
201215
);

0 commit comments

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