Skip to content

Commit e74bf8e

Browse files
soyukaalanpoulain
andauthored
SearchFilter: fix regression in 2.6.3 (#4134)
* Revert "Handle binary UUID in SearchFilter (#3774)" This reverts commit ff248ae. Co-authored-by: Alan Poulain <[email protected]>
1 parent f193281 commit e74bf8e

File tree

14 files changed

+37
-209
lines changed

14 files changed

+37
-209
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -384,7 +384,7 @@ jobs:
384384
- name: Clear test app cache
385385
run: tests/Fixtures/app/console cache:clear --ansi
386386
- name: Run Behat tests
387-
run: vendor/bin/behat --out=std --format=progress --profile=default --no-interaction --tags '~@!lowest'
387+
run: vendor/bin/behat --out=std --format=progress --profile=default --no-interaction
388388

389389
postgresql:
390390
name: Behat (PHP ${{ matrix.php }}) (PostgreSQL)

CHANGELOG.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
* Doctrine: Fix purging HTTP cache for unreadable relations (#3441)
66
* GraphQL: Manage `pagination_use_output_walkers` and `pagination_fetch_join_collection` for operations (#3311)
77
* Swagger UI: Remove Google fonts (#4112)
8+
* Doctrine: Revert #3774 support for binary UUID in search filter (#4134)
89

910
## 2.6.3
1011

@@ -13,9 +14,7 @@
1314
* Security: Use a `NullToken` when using the new authenticator manager in the resource access checker (#4067)
1415
* Mercure: Do not use data in options when deleting (#4056)
1516
* Doctrine: Support for foreign identifiers (#4042)
16-
* Doctrine: Support for binary UUID in search filter (#3774)
1717
* Doctrine: Do not add join or lookup for search filter with empty value (#3703)
18-
* Doctrine: Reduce code duplication in search filter (#3541)
1918
* JSON Schema: Allow generating documentation when property and method start from "is" (property `isActive` and method `isActive`) (#4064)
2019
* OpenAPI: Fix missing 422 responses in the documentation (#4086)
2120
* OpenAPI: Fix error when schema is empty (#4051)

behat.yml.dist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ postgres:
5050
- 'Behat\MinkExtension\Context\MinkContext'
5151
- 'behatch:context:rest'
5252
filters:
53-
tags: '~@sqlite&&~@mongodb&&~@elasticsearch&&~@!postgres'
53+
tags: '~@sqlite&&~@mongodb&&~@elasticsearch'
5454

5555
mongodb:
5656
suites:

features/doctrine/search_filter.feature

Lines changed: 8 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -539,52 +539,6 @@ Feature: Search filter on collections
539539
}
540540
"""
541541

542-
@!postgres
543-
@!mongodb
544-
@!lowest
545-
Scenario: Search collection by binary UUID (Ramsey)
546-
Given there is a ramsey identified resource with binary uuid "c19900a9-d2b2-45bf-b040-05c72d321282"
547-
And there is a ramsey identified resource with binary uuid "a96cb2ed-e3dc-4449-9842-830e770cdecc"
548-
When I send a "GET" request to "/ramsey_uuid_binary_dummies?id=c19900a9-d2b2-45bf-b040-05c72d321282"
549-
Then the response status code should be 200
550-
And the response should be in JSON
551-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
552-
And the JSON node "hydra:totalItems" should be equal to "1"
553-
554-
@!postgres
555-
@!mongodb
556-
@!lowest
557-
Scenario: Search collection by binary UUID (Ramsey) (multiple values)
558-
Given there is a ramsey identified resource with binary uuid "f71a6469-1bfc-4945-bad1-d6092f09a8c3"
559-
When I send a "GET" request to "/ramsey_uuid_binary_dummies?id[]=c19900a9-d2b2-45bf-b040-05c72d321282&id[]=f71a6469-1bfc-4945-bad1-d6092f09a8c3"
560-
Then the response status code should be 200
561-
And the response should be in JSON
562-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
563-
And the JSON node "hydra:totalItems" should be equal to "2"
564-
565-
@!postgres
566-
@!mongodb
567-
@!lowest
568-
Scenario: Search collection by related binary UUID (Ramsey)
569-
Given there is a ramsey identified resource with binary uuid "56fa36c3-2b5e-4813-9e3a-b0bbe2ab5553" having a related resource with binary uuid "02227dc6-a371-4b8b-a34c-bbbf921b8ebd"
570-
And there is a ramsey identified resource with binary uuid "4d796212-4b26-4e19-b092-a32d990b1e7e" having a related resource with binary uuid "31f64c33-6061-4fc1-b0e8-f4711b607c7d"
571-
When I send a "GET" request to "/ramsey_uuid_binary_dummies?relateds=02227dc6-a371-4b8b-a34c-bbbf921b8ebd"
572-
Then the response status code should be 200
573-
And the response should be in JSON
574-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
575-
And the JSON node "hydra:totalItems" should be equal to "1"
576-
577-
@!postgres
578-
@!mongodb
579-
@!lowest
580-
Scenario: Search collection by related binary UUID (Ramsey) (multiple values)
581-
Given there is a ramsey identified resource with binary uuid "3248c908-a89d-483a-b75f-25888730d391" having a related resource with binary uuid "d7b2e909-37b0-411e-814c-74e044afbccb"
582-
When I send a "GET" request to "/ramsey_uuid_binary_dummies?relateds[]=02227dc6-a371-4b8b-a34c-bbbf921b8ebd&relateds[]=d7b2e909-37b0-411e-814c-74e044afbccb"
583-
Then the response status code should be 200
584-
And the response should be in JSON
585-
And the header "Content-Type" should be equal to "application/ld+json; charset=utf-8"
586-
And the JSON node "hydra:totalItems" should be equal to "2"
587-
588542
Scenario: Search for entities within an impossible range
589543
When I send a "GET" request to "/dummies?name=MuYm"
590544
Then the response status code should be 200
@@ -1039,3 +993,11 @@ Feature: Search filter on collections
1039993
}
1040994
}
1041995
"""
996+
997+
@createSchema
998+
Scenario: Search by date (#4128)
999+
Given there are 3 dummydate objects with dummyDate
1000+
When I send a "GET" request to "/dummy_dates?dummyDate=2015-04-01"
1001+
Then the response status code should be 200
1002+
And the response should be in JSON
1003+
And the JSON node "hydra:totalItems" should be equal to 1

src/Bridge/Doctrine/Orm/Filter/SearchFilter.php

Lines changed: 8 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,8 @@
2121
use ApiPlatform\Core\Bridge\Doctrine\Orm\Util\QueryNameGeneratorInterface;
2222
use ApiPlatform\Core\Exception\InvalidArgumentException;
2323
use Doctrine\DBAL\Types\Type as DBALType;
24-
use Doctrine\ORM\Query\Parameter;
2524
use Doctrine\ORM\QueryBuilder;
2625
use Doctrine\Persistence\ManagerRegistry;
27-
use Doctrine\Persistence\Mapping\ClassMetadata;
2826
use Psr\Log\LoggerInterface;
2927
use Symfony\Component\HttpFoundation\RequestStack;
3028
use Symfony\Component\PropertyAccess\PropertyAccess;
@@ -115,7 +113,7 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
115113
return;
116114
}
117115

118-
$this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $alias, $field, $values, $caseSensitive, $metadata);
116+
$this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $alias, $field, $values, $caseSensitive);
119117

120118
return;
121119
}
@@ -150,23 +148,16 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
150148
$associationField = $associationFieldIdentifier;
151149
}
152150

153-
$this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $associationAlias, $associationField, $values, $caseSensitive, $metadata);
151+
$this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $associationAlias, $associationField, $values, $caseSensitive);
154152
}
155153

156154
/**
157155
* Adds where clause according to the strategy.
158156
*
159157
* @throws InvalidArgumentException If strategy does not exist
160158
*/
161-
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $values, bool $caseSensitive/*, ClassMetadata $metadata*/)
159+
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $values, bool $caseSensitive)
162160
{
163-
if (\func_num_args() > 7 && ($metadata = func_get_arg(7)) instanceof ClassMetadata) {
164-
$type = $metadata->getTypeOfField($field);
165-
} else {
166-
@trigger_error(sprintf('Method %s() will have a 8th argument `$metadata` in version API Platform 3.0.', __FUNCTION__), \E_USER_DEPRECATED);
167-
$type = null;
168-
}
169-
170161
if (!\is_array($values)) {
171162
$values = [$values];
172163
}
@@ -175,26 +166,18 @@ protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuild
175166
$valueParameter = ':'.$queryNameGenerator->generateParameterName($field);
176167
$aliasedField = sprintf('%s.%s', $alias, $field);
177168

178-
if (self::STRATEGY_EXACT === $strategy) {
169+
if (!$strategy || self::STRATEGY_EXACT === $strategy) {
179170
if (1 === \count($values)) {
180171
$queryBuilder
181172
->andWhere($queryBuilder->expr()->eq($wrapCase($aliasedField), $wrapCase($valueParameter)))
182-
->setParameter($valueParameter, $values[0], $type);
173+
->setParameter($valueParameter, $values[0]);
183174

184175
return;
185176
}
186177

187-
$parameters = $queryBuilder->getParameters();
188-
$inQuery = [];
189-
foreach ($values as $value) {
190-
$inQuery[] = $valueParameter;
191-
$parameters->add(new Parameter($valueParameter, $caseSensitive ? $value : strtolower($value), $type));
192-
$valueParameter = ':'.$queryNameGenerator->generateParameterName($field);
193-
}
194-
195178
$queryBuilder
196-
->andWhere($wrapCase($aliasedField).' IN ('.implode(', ', $inQuery).')')
197-
->setParameters($parameters);
179+
->andWhere($queryBuilder->expr()->in($wrapCase($aliasedField), $valueParameter))
180+
->setParameter($valueParameter, $caseSensitive ? $values : array_map('strtolower', $values));
198181

199182
return;
200183
}
@@ -236,7 +219,7 @@ protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuild
236219
}
237220

238221
$queryBuilder->andWhere($queryBuilder->expr()->orX(...$ors));
239-
array_walk($parameters, [$queryBuilder, 'setParameter'], $type);
222+
array_walk($parameters, [$queryBuilder, 'setParameter']);
240223
}
241224

242225
/**

tests/Behat/DoctrineContext.php

Lines changed: 0 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,6 @@
141141
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Pet;
142142
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Product;
143143
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\Question;
144-
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RamseyUuidBinaryDummy;
145144
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RamseyUuidDummy;
146145
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedDummy;
147146
use ApiPlatform\Core\Tests\Fixtures\TestBundle\Entity\RelatedOwnedDummy;
@@ -1344,35 +1343,6 @@ public function thereIsARamseyIdentifiedResource(string $uuid)
13441343
$this->manager->flush();
13451344
}
13461345

1347-
/**
1348-
* @Given there is a ramsey identified resource with binary uuid :uuid
1349-
*/
1350-
public function thereIsARamseyIdentifiedResourceWithBinaryUuid(string $uuid)
1351-
{
1352-
$dummy = new RamseyUuidBinaryDummy();
1353-
$dummy->setId($uuid);
1354-
1355-
$this->manager->persist($dummy);
1356-
$this->manager->flush();
1357-
}
1358-
1359-
/**
1360-
* @Given there is a ramsey identified resource with binary uuid :uuid having a related resource with binary uuid :uuid_related
1361-
*/
1362-
public function thereIsARamseyIdentifiedResourceWithBinaryUuidHavingARelatedResourceWithBinaryUuid(string $uuid, string $uuidRelated)
1363-
{
1364-
$related = new RamseyUuidBinaryDummy();
1365-
$related->setId($uuidRelated);
1366-
1367-
$dummy = new RamseyUuidBinaryDummy();
1368-
$dummy->setId($uuid);
1369-
$dummy->addRelated($related);
1370-
1371-
$this->manager->persist($related);
1372-
$this->manager->persist($dummy);
1373-
$this->manager->flush();
1374-
}
1375-
13761346
/**
13771347
* @Given there is a dummy object with a fourth level relation
13781348
*/

tests/Bridge/Doctrine/Orm/Filter/SearchFilterTest.php

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -390,18 +390,22 @@ public function provideApplyTestData(): array
390390
$filterFactory,
391391
],
392392
'exact (multiple values)' => [
393-
sprintf('SELECT %s FROM %s %1$s WHERE %1$s.name IN (:name_p1, :name_p2)', $this->alias, Dummy::class),
393+
sprintf('SELECT %s FROM %s %1$s WHERE %1$s.name IN(:name_p1)', $this->alias, Dummy::class),
394394
[
395-
'name_p1' => 'CaSE',
396-
'name_p2' => 'SENSitive',
395+
'name_p1' => [
396+
'CaSE',
397+
'SENSitive',
398+
],
397399
],
398400
$filterFactory,
399401
],
400402
'exact (multiple values; case insensitive)' => [
401-
sprintf('SELECT %s FROM %s %1$s WHERE LOWER(%1$s.name) IN (:name_p1, :name_p2)', $this->alias, Dummy::class),
403+
sprintf('SELECT %s FROM %s %1$s WHERE LOWER(%1$s.name) IN(:name_p1)', $this->alias, Dummy::class),
402404
[
403-
'name_p1' => 'case',
404-
'name_p2' => 'insensitive',
405+
'name_p1' => [
406+
'case',
407+
'insensitive',
408+
],
405409
],
406410
$filterFactory,
407411
],
@@ -543,11 +547,10 @@ public function provideApplyTestData(): array
543547
$filterFactory,
544548
],
545549
'mixed IRI and entity ID values for relations' => [
546-
sprintf('SELECT %s FROM %s %1$s INNER JOIN %1$s.relatedDummies relatedDummies_a1 WHERE %1$s.relatedDummy IN (:relatedDummy_p1, :relatedDummy_p2) AND relatedDummies_a1.id = :id_p4', $this->alias, Dummy::class),
550+
sprintf('SELECT %s FROM %s %1$s INNER JOIN %1$s.relatedDummies relatedDummies_a1 WHERE %1$s.relatedDummy IN(:relatedDummy_p1) AND relatedDummies_a1.id = :id_p2', $this->alias, Dummy::class),
547551
[
548-
'relatedDummy_p1' => 1,
549-
'relatedDummy_p2' => 2,
550-
'id_p4' => 1,
552+
'relatedDummy_p1' => [1, 2],
553+
'id_p2' => 1,
551554
],
552555
$filterFactory,
553556
],

tests/Fixtures/TestBundle/Document/DummyDate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Core\Annotation\ApiFilter;
1717
use ApiPlatform\Core\Annotation\ApiResource;
1818
use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\DateFilter;
19+
use ApiPlatform\Core\Bridge\Doctrine\MongoDbOdm\Filter\SearchFilter;
1920
use Doctrine\ODM\MongoDB\Mapping\Annotations as ODM;
2021

2122
/**
@@ -27,6 +28,7 @@
2728
* @ApiResource(attributes={
2829
* "filters"={"my_dummy_date.mongodb.date"}
2930
* })
31+
* @ApiFilter(SearchFilter::class, properties={"dummyDate"})
3032
* @ApiFilter(DateFilter::class, properties={
3133
* "dateIncludeNullAfter"=DateFilter::INCLUDE_NULL_AFTER,
3234
* "dateIncludeNullBefore"=DateFilter::INCLUDE_NULL_BEFORE,

tests/Fixtures/TestBundle/Entity/DummyDate.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Core\Annotation\ApiFilter;
1717
use ApiPlatform\Core\Annotation\ApiResource;
1818
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\DateFilter;
19+
use ApiPlatform\Core\Bridge\Doctrine\Orm\Filter\SearchFilter;
1920
use Doctrine\ORM\Mapping as ORM;
2021

2122
/**
@@ -26,6 +27,7 @@
2627
* @ApiResource(attributes={
2728
* "filters"={"my_dummy_date.date"}
2829
* })
30+
* @ApiFilter(SearchFilter::class, properties={"dummyDate"})
2931
* @ApiFilter(DateFilter::class, properties={
3032
* "dateIncludeNullAfter"=DateFilter::INCLUDE_NULL_AFTER,
3133
* "dateIncludeNullBefore"=DateFilter::INCLUDE_NULL_BEFORE,

tests/Fixtures/TestBundle/Entity/RamseyUuidBinaryDummy.php

Lines changed: 0 additions & 89 deletions
This file was deleted.

0 commit comments

Comments
 (0)