From 9c66a85ee8242948da78b62fd689e6c28ad5f72f Mon Sep 17 00:00:00 2001 From: henk Date: Tue, 25 Jun 2024 14:12:49 +0200 Subject: [PATCH] Adapt to doctrine/orm 3 - use QueryBuilder::resetDQLPart insead of add( , null) - adapt composer.json - did composer update --- composer.json | 2 +- src/Filter/DateFilter.php | 8 ++++++-- src/Filter/FilterLogic.php | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index 036140b..8e740f8 100644 --- a/composer.json +++ b/composer.json @@ -15,7 +15,7 @@ "php": ">=7.2.5", "symfony/http-kernel": "^4.4 || ^5.1 || ^6.0 || ^7.0", "api-platform/core": "^2.7 || ^3.0", - "doctrine/orm": "^2.7" + "doctrine/orm": "^2.14 || ^3.0" }, "require-dev": { }, diff --git a/src/Filter/DateFilter.php b/src/Filter/DateFilter.php index 2f6cee6..13c518e 100644 --- a/src/Filter/DateFilter.php +++ b/src/Filter/DateFilter.php @@ -52,12 +52,16 @@ protected function filterProperty(string $property, $values, QueryBuilder $query } $oldWhere = $queryBuilder->getDQLPart('where'); - $queryBuilder->add('where', null); + $queryBuilder->resetDQLPart('where'); $this->inner->apply($queryBuilder, $queryNameGenerator, $resourceClass, $operation, $contextCopy); $expressions = $queryBuilder->getDQLPart('where')->getParts(); - $queryBuilder->add('where', $oldWhere); + if ($oldWhere === null) { + $queryBuilder->resetDQLPart('where'); + } else { + $queryBuilder->add('where', $oldWhere); //restores old where + } $isNotNull = array_shift($expressions); foreach ($expressions as $expr) { diff --git a/src/Filter/FilterLogic.php b/src/Filter/FilterLogic.php index a5ae611..2535841 100644 --- a/src/Filter/FilterLogic.php +++ b/src/Filter/FilterLogic.php @@ -142,7 +142,11 @@ protected function doGenerate($queryBuilder, $queryNameGenerator, $resourceClass $this->applyFilters($queryBuilder, $queryNameGenerator, $resourceClass, $operation, $subcontext); $newWhere = $queryBuilder->getDQLPart('where'); - $queryBuilder->add('where', $oldWhere); //restores old where + if ($oldWhere === null) { + $queryBuilder->resetDQLPart('where'); + } else { + $queryBuilder->add('where', $oldWhere); //restores old where + } // force $operator logic upon $newWhere $expressions = $this->getAppliedExpressions($newWhere, $marker);