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

[Messenger] fix compatibility with Doctrine DBAL 4 #52476

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
Nov 7, 2023
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
fix compatibility with Doctrine DBAL 4
  • Loading branch information
xabbuh committed Nov 7, 2023
commit fca96ac15e53a9e208215ce7c2ac4971d10ff1cb
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,9 @@ public function testGetWithNoPendingMessageWillReturnNull()
$queryBuilder
->method('getParameterTypes')
->willReturn([]);
$queryBuilder
->method('getSQL')
->willReturn('SELECT FOR UPDATE');
$driverConnection->expects($this->once())
->method('createQueryBuilder')
->willReturn($queryBuilder);
Expand Down Expand Up @@ -120,7 +123,11 @@ private function getDBALConnectionMock()
{
$driverConnection = $this->createMock(DBALConnection::class);
$platform = $this->createMock(AbstractPlatform::class);
$platform->method('getWriteLockSQL')->willReturn('FOR UPDATE');

if (!method_exists(QueryBuilder::class, 'forUpdate')) {
$platform->method('getWriteLockSQL')->willReturn('FOR UPDATE');
}

$configuration = $this->createMock(\Doctrine\DBAL\Configuration::class);
$driverConnection->method('getDatabasePlatform')->willReturn($platform);
$driverConnection->method('getConfiguration')->willReturn($configuration);
Expand Down Expand Up @@ -381,7 +388,9 @@ public function testGeneratedSql(AbstractPlatform $platform, string $expectedSql
$driverConnection
->expects($this->once())
->method('executeQuery')
->with($expectedSql)
->with($this->callback(function ($sql) use ($expectedSql) {
return trim($expectedSql) === trim($sql);
}))
->willReturn($result)
;
$driverConnection->expects($this->once())->method('commit');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,24 @@ public function get(): ?array

// Append pessimistic write lock to FROM clause if db platform supports it
$sql = $query->getSQL();
if (preg_match('/FROM (.+) WHERE/', (string) $sql, $matches)) {

// Wrap the rownum query in a sub-query to allow writelocks without ORA-02014 error
if ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
$query = $this->createQueryBuilder('w')
->where('w.id IN ('.str_replace('SELECT a.* FROM', 'SELECT a.id FROM', $sql).')');

if (method_exists(QueryBuilder::class, 'forUpdate')) {
$query->forUpdate();
}

$sql = $query->getSQL();
} elseif (method_exists(QueryBuilder::class, 'forUpdate')) {
$query->forUpdate();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the case of the oracle platform, this is now applying the lock on the inner query and not the outer one (see the specific code below). Is this expected ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's probably better not to change the outcome here, updated

try {
$sql = $query->getSQL();
} catch (DBALException $e) {
}
} elseif (preg_match('/FROM (.+) WHERE/', (string) $sql, $matches)) {
$fromClause = $matches[1];
$sql = str_replace(
sprintf('FROM %s WHERE', $fromClause),
Expand All @@ -186,16 +203,13 @@ public function get(): ?array
);
}

// Wrap the rownum query in a sub-query to allow writelocks without ORA-02014 error
if ($this->driverConnection->getDatabasePlatform() instanceof OraclePlatform) {
$sql = $this->createQueryBuilder('w')
->where('w.id IN ('.str_replace('SELECT a.* FROM', 'SELECT a.id FROM', $sql).')')
->getSQL();
// use SELECT ... FOR UPDATE to lock table
if (!method_exists(QueryBuilder::class, 'forUpdate')) {
nicolas-grekas marked this conversation as resolved.
Show resolved Hide resolved
$sql .= ' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL();
}

// use SELECT ... FOR UPDATE to lock table
$stmt = $this->executeQuery(
$sql.' '.$this->driverConnection->getDatabasePlatform()->getWriteLockSQL(),
$sql,
$query->getParameters(),
$query->getParameterTypes()
);
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.