Skip to content

Commit

Permalink
Bump ORM requirements, fix translation walker handling of paginated q…
Browse files Browse the repository at this point in the history
…ueries
  • Loading branch information
mbabker committed Feb 9, 2025
1 parent 910c4ba commit aec4f6c
Show file tree
Hide file tree
Showing 11 changed files with 50 additions and 175 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ a release.
---

## [Unreleased]
### Changed
- Updated minimum versions for `doctrine/orm` to ^2.20 || ^3.3

### Fixed
- Regression with `doctrine/orm` ^2.20 || ^3.3 that caused the translation walker to produce queries with duplicated LIMIT clauses (issue #2917)

## [3.18.0] - 2025-02-01
### Added
Expand Down
4 changes: 2 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
"doctrine/dbal": "^3.7 || ^4.0",
"doctrine/doctrine-bundle": "^2.3",
"doctrine/mongodb-odm": "^2.3",
"doctrine/orm": "^2.14.0 || ^3.0",
"doctrine/orm": "^2.20 || ^3.3",
"friendsofphp/php-cs-fixer": "^3.14.0",
"nesbot/carbon": "^2.71 || ^3.0",
"phpstan/phpstan": "^2.1.1",
Expand All @@ -76,7 +76,7 @@
"doctrine/common": "<2.13 || >=4.0",
"doctrine/dbal": "<3.7 || >=5.0",
"doctrine/mongodb-odm": "<2.3 || >=3.0",
"doctrine/orm": "<2.14.0 || 2.16.0 || 2.16.1 || >=4.0"
"doctrine/orm": "<2.20 || >=3.0,<3.3 || >=4.0"
},
"suggest": {
"doctrine/mongodb-odm": "to use the extensions with the MongoDB ODM",
Expand Down
6 changes: 0 additions & 6 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -540,12 +540,6 @@ parameters:
count: 1
path: src/Timestampable/Mapping/Driver/Yaml.php

-
message: '#^Call to an undefined static method Doctrine\\ORM\\Query\\SqlWalker\:\:getFinalizer\(\)\.$#'
identifier: staticMethod.notFound
count: 2
path: src/Tool/ORM/Walker/CompatSqlOutputWalker.php

-
message: '#^Access to an undefined property ProxyManager\\Proxy\\GhostObjectInterface&TObject of object\:\:\$identifier\.$#'
identifier: property.notFound
Expand Down
4 changes: 2 additions & 2 deletions src/SoftDeleteable/Query/TreeWalker/SoftDeleteableWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
use Doctrine\ORM\Query\Exec\PreparedExecutorFinalizer;
use Doctrine\ORM\Query\Exec\SingleTableDeleteUpdateExecutor;
use Doctrine\ORM\Query\Exec\SqlFinalizer;
use Doctrine\ORM\Query\SqlOutputWalker;
use Gedmo\Exception\RuntimeException;
use Gedmo\Exception\UnexpectedValueException;
use Gedmo\SoftDeleteable\Query\TreeWalker\Exec\MultiTableDeleteExecutor;
use Gedmo\SoftDeleteable\SoftDeleteableListener;
use Gedmo\Tool\ORM\Walker\CompatSqlOutputWalker;
use Gedmo\Tool\ORM\Walker\SqlWalkerCompat;

/**
Expand All @@ -38,7 +38,7 @@
*
* @final since gedmo/doctrine-extensions 3.11
*/
class SoftDeleteableWalker extends CompatSqlOutputWalker
class SoftDeleteableWalker extends SqlOutputWalker
{
use SqlWalkerCompat;

Expand Down
59 changes: 0 additions & 59 deletions src/Tool/ORM/Walker/CompatSqlOutputWalker.php

This file was deleted.

42 changes: 0 additions & 42 deletions src/Tool/ORM/Walker/CompatSqlOutputWalkerForOrm2.php

This file was deleted.

39 changes: 0 additions & 39 deletions src/Tool/ORM/Walker/CompatSqlOutputWalkerForOrm3.php

This file was deleted.

25 changes: 13 additions & 12 deletions src/Tool/ORM/Walker/SqlWalkerCompatForOrm2.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@

namespace Gedmo\Tool\ORM\Walker;

use Doctrine\ORM\Query\AST;
use Doctrine\ORM\Query\AST\DeleteClause;
use Doctrine\ORM\Query\AST\DeleteStatement;
use Doctrine\ORM\Query\AST\FromClause;
use Doctrine\ORM\Query\AST\GroupByClause;
use Doctrine\ORM\Query\AST\HavingClause;
Expand All @@ -19,8 +19,10 @@
use Doctrine\ORM\Query\AST\SelectStatement;
use Doctrine\ORM\Query\AST\SimpleSelectClause;
use Doctrine\ORM\Query\AST\SubselectFromClause;
use Doctrine\ORM\Query\AST\UpdateStatement;
use Doctrine\ORM\Query\AST\WhereClause;
use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
use Doctrine\ORM\Query\Exec\SqlFinalizer;
use Doctrine\ORM\Query\SqlWalker;

/**
Expand All @@ -35,7 +37,7 @@ trait SqlWalkerCompatForOrm2
/**
* Gets an executor that can be used to execute the result of this walker.
*
* @param SelectStatement|AST\UpdateStatement|AST\DeleteStatement $statement
* @param SelectStatement|UpdateStatement|DeleteStatement $statement
*
* @return AbstractSqlExecutor
*/
Expand All @@ -45,15 +47,11 @@ public function getExecutor($statement)
}

/**
* Walks down a SelectStatement AST node, thereby generating the appropriate SQL.
*
* @param SelectStatement $selectStatement
*
* @return string
* @param DeleteStatement|UpdateStatement|SelectStatement $AST
*/
public function walkSelectStatement($selectStatement)
public function getFinalizer($AST): SqlFinalizer
{
return $this->doWalkSelectStatementWithCompat($selectStatement);
return $this->doGetFinalizerWithCompat($AST);
}

/**
Expand Down Expand Up @@ -169,16 +167,19 @@ public function walkWhereClause($whereClause)
/**
* Gets an executor that can be used to execute the result of this walker.
*
* @param SelectStatement|AST\UpdateStatement|AST\DeleteStatement $statement
* @param SelectStatement|UpdateStatement|DeleteStatement $statement
*/
protected function doGetExecutorWithCompat($statement): AbstractSqlExecutor
{
return parent::getExecutor($statement);
}

protected function doWalkSelectStatementWithCompat(SelectStatement $selectStatement): string
/**
* @param DeleteStatement|UpdateStatement|SelectStatement $AST
*/
protected function doGetFinalizerWithCompat($AST): SqlFinalizer

Check warning on line 180 in src/Tool/ORM/Walker/SqlWalkerCompatForOrm2.php

View check run for this annotation

Codecov / codecov/patch

src/Tool/ORM/Walker/SqlWalkerCompatForOrm2.php#L180

Added line #L180 was not covered by tests
{
return parent::walkSelectStatement($selectStatement);
return parent::getFinalizer($AST);

Check warning on line 182 in src/Tool/ORM/Walker/SqlWalkerCompatForOrm2.php

View check run for this annotation

Codecov / codecov/patch

src/Tool/ORM/Walker/SqlWalkerCompatForOrm2.php#L182

Added line #L182 was not covered by tests
}

protected function doWalkSelectClauseWithCompat(SelectClause $selectClause): string
Expand Down
16 changes: 8 additions & 8 deletions src/Tool/ORM/Walker/SqlWalkerCompatForOrm3.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

namespace Gedmo\Tool\ORM\Walker;

use Doctrine\ORM\Query\AST;
use Doctrine\ORM\Query\AST\DeleteClause;
use Doctrine\ORM\Query\AST\DeleteStatement;
use Doctrine\ORM\Query\AST\FromClause;
Expand All @@ -23,6 +22,7 @@
use Doctrine\ORM\Query\AST\UpdateStatement;
use Doctrine\ORM\Query\AST\WhereClause;
use Doctrine\ORM\Query\Exec\AbstractSqlExecutor;
use Doctrine\ORM\Query\Exec\SqlFinalizer;
use Doctrine\ORM\Query\SqlWalker;

/**
Expand All @@ -42,12 +42,9 @@ public function getExecutor(SelectStatement|UpdateStatement|DeleteStatement $sta
return $this->doGetExecutorWithCompat($statement);
}

/**
* Walks down a SelectStatement AST node, thereby generating the appropriate SQL.
*/
public function walkSelectStatement(SelectStatement $selectStatement): string
public function getFinalizer(DeleteStatement|UpdateStatement|SelectStatement $AST): SqlFinalizer
{
return $this->doWalkSelectStatementWithCompat($selectStatement);
return $this->doGetFinalizerWithCompat($AST);
}

/**
Expand Down Expand Up @@ -134,9 +131,12 @@ protected function doGetExecutorWithCompat($statement): AbstractSqlExecutor
return parent::getExecutor($statement);
}

protected function doWalkSelectStatementWithCompat(SelectStatement $selectStatement): string
/**
* @param DeleteStatement|UpdateStatement|SelectStatement $AST
*/
protected function doGetFinalizerWithCompat($AST): SqlFinalizer

Check warning on line 137 in src/Tool/ORM/Walker/SqlWalkerCompatForOrm3.php

View check run for this annotation

Codecov / codecov/patch

src/Tool/ORM/Walker/SqlWalkerCompatForOrm3.php#L137

Added line #L137 was not covered by tests
{
return parent::walkSelectStatement($selectStatement);
return parent::getFinalizer($AST);

Check warning on line 139 in src/Tool/ORM/Walker/SqlWalkerCompatForOrm3.php

View check run for this annotation

Codecov / codecov/patch

src/Tool/ORM/Walker/SqlWalkerCompatForOrm3.php#L139

Added line #L139 was not covered by tests
}

protected function doWalkSelectClauseWithCompat(SelectClause $selectClause): string
Expand Down
10 changes: 5 additions & 5 deletions src/Translatable/Query/TreeWalker/TranslationWalker.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@
use Doctrine\ORM\Query\Exec\SingleSelectExecutor;
use Doctrine\ORM\Query\Exec\SingleSelectSqlFinalizer;
use Doctrine\ORM\Query\Exec\SqlFinalizer;
use Doctrine\ORM\Query\SqlOutputWalker;
use Gedmo\Exception\RuntimeException;
use Gedmo\Tool\ORM\Walker\CompatSqlOutputWalker;
use Gedmo\Tool\ORM\Walker\SqlWalkerCompat;
use Gedmo\Translatable\Hydrator\ORM\ObjectHydrator;
use Gedmo\Translatable\Hydrator\ORM\SimpleObjectHydrator;
Expand All @@ -56,7 +56,7 @@
*
* @final since gedmo/doctrine-extensions 3.11
*/
class TranslationWalker extends CompatSqlOutputWalker
class TranslationWalker extends SqlOutputWalker
{
use SqlWalkerCompat;

Expand Down Expand Up @@ -155,12 +155,12 @@ protected function doGetFinalizerWithCompat($AST): SqlFinalizer
}
$this->prepareTranslatedComponents();

return new SingleSelectSqlFinalizer($this->walkSelectStatement($AST));
return new SingleSelectSqlFinalizer($this->createSqlForFinalizer($AST));
}

protected function doWalkSelectStatementWithCompat(SelectStatement $selectStatement): string
protected function createSqlForFinalizer(SelectStatement $selectStatement): string
{
$result = parent::walkSelectStatement($selectStatement);
$result = parent::createSqlForFinalizer($selectStatement);
if ([] === $this->translatedComponents) {
return $result;
}
Expand Down
15 changes: 15 additions & 0 deletions tests/Gedmo/Translatable/TranslationQueryWalkerTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,21 @@ public function testJoinedWithStatements(): void
static::assertSame('good', $comments[0]['subject']);
}

/**
* @doesNotPerformAssertions
*/
public function testPaginatedQuery(): void
{
$this->populateMore();

$dql = 'SELECT a FROM '.Article::class.' a';
$q = $this->em->createQuery($dql);
$q->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, TranslationWalker::class);
$q->setFirstResult(0);
$q->setMaxResults(1);
$q->getResult(Query::HYDRATE_SIMPLEOBJECT);
}

public function testShouldSelectWithTranslationFallbackOnSimpleObjectHydration(): void
{
$this->em->getConfiguration()->addCustomHydrationMode(
Expand Down

0 comments on commit aec4f6c

Please sign in to comment.