Skip to content

Commit ef89083

Browse files
committed
Revert "Handle binary UUID in SearchFilter (#3774)"
This reverts commit ff248ae.
1 parent 8b02b2b commit ef89083

File tree

12 files changed

+43
-209
lines changed

12 files changed

+43
-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 & 1 deletion
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+
* OpenApi: Fix missing 422 responses in the documentation (#4086)
89

910
## 2.6.3
1011

@@ -13,7 +14,6 @@
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)
1818
* Doctrine: Reduce code duplication in search filter (#3541)
1919
* JSON Schema: Allow generating documentation when property and method start from "is" (property `isActive` and method `isActive`) (#4064)

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: 0 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

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

Lines changed: 26 additions & 26 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,16 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
115113
return;
116114
}
117115

118-
$this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $alias, $field, $values, $caseSensitive, $metadata);
116+
$caseSensitive = true;
117+
$strategy = $this->properties[$property] ?? self::STRATEGY_EXACT;
118+
119+
// prefixing the strategy with i makes it case insensitive
120+
if (0 === strpos($strategy, 'i')) {
121+
$strategy = substr($strategy, 1);
122+
$caseSensitive = false;
123+
}
124+
125+
$this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $alias, $field, $values, $caseSensitive);
119126

120127
return;
121128
}
@@ -150,23 +157,24 @@ protected function filterProperty(string $property, $value, QueryBuilder $queryB
150157
$associationField = $associationFieldIdentifier;
151158
}
152159

153-
$this->addWhereByStrategy($strategy, $queryBuilder, $queryNameGenerator, $associationAlias, $associationField, $values, $caseSensitive, $metadata);
160+
if (1 === \count($values)) {
161+
$queryBuilder
162+
->andWhere($queryBuilder->expr()->eq($associationAlias.'.'.$associationField, ':'.$valueParameter))
163+
->setParameter($valueParameter, $values[0]);
164+
} else {
165+
$queryBuilder
166+
->andWhere($queryBuilder->expr()->in($associationAlias.'.'.$associationField, ':'.$valueParameter))
167+
->setParameter($valueParameter, $values);
168+
}
154169
}
155170

156171
/**
157172
* Adds where clause according to the strategy.
158173
*
159174
* @throws InvalidArgumentException If strategy does not exist
160175
*/
161-
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $values, bool $caseSensitive/*, ClassMetadata $metadata*/)
176+
protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuilder, QueryNameGeneratorInterface $queryNameGenerator, string $alias, string $field, $values, bool $caseSensitive)
162177
{
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-
170178
if (!\is_array($values)) {
171179
$values = [$values];
172180
}
@@ -175,26 +183,18 @@ protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuild
175183
$valueParameter = ':'.$queryNameGenerator->generateParameterName($field);
176184
$aliasedField = sprintf('%s.%s', $alias, $field);
177185

178-
if (self::STRATEGY_EXACT === $strategy) {
179-
if (1 === \count($values)) {
186+
if (null == $strategy || self::STRATEGY_EXACT == $strategy) {
187+
if (1 == \count($values)) {
180188
$queryBuilder
181189
->andWhere($queryBuilder->expr()->eq($wrapCase($aliasedField), $wrapCase($valueParameter)))
182-
->setParameter($valueParameter, $values[0], $type);
190+
->setParameter($valueParameter, $values[0]);
183191

184192
return;
185193
}
186194

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-
195195
$queryBuilder
196-
->andWhere($wrapCase($aliasedField).' IN ('.implode(', ', $inQuery).')')
197-
->setParameters($parameters);
196+
->andWhere($queryBuilder->expr()->in($wrapCase($aliasedField), $valueParameter))
197+
->setParameter($valueParameter, $caseSensitive ? $values : array_map('strtolower', $values));
198198

199199
return;
200200
}
@@ -236,7 +236,7 @@ protected function addWhereByStrategy(string $strategy, QueryBuilder $queryBuild
236236
}
237237

238238
$queryBuilder->andWhere($queryBuilder->expr()->orX(...$ors));
239-
array_walk($parameters, [$queryBuilder, 'setParameter'], $type);
239+
array_walk($parameters, [$queryBuilder, 'setParameter']);
240240
}
241241

242242
/**

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 = :relatedDummies_p2', $this->alias, Dummy::class),
547551
[
548-
'relatedDummy_p1' => 1,
549-
'relatedDummy_p2' => 2,
550-
'id_p4' => 1,
552+
'relatedDummy_p1' => [1, 2],
553+
'relatedDummies_p2' => 1,
551554
],
552555
$filterFactory,
553556
],

tests/Fixtures/TestBundle/Entity/RamseyUuidBinaryDummy.php

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

tests/Fixtures/app/config/config_common.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,7 @@ doctrine:
88
path: '%kernel.cache_dir%/db.sqlite'
99
charset: 'UTF8'
1010
types:
11-
uuid: Ramsey\Uuid\Doctrine\UuidType
12-
uuid_binary: Ramsey\Uuid\Doctrine\UuidBinaryType
11+
uuid: Ramsey\Uuid\Doctrine\UuidType
1312

1413
orm:
1514
auto_generate_proxy_classes: '%kernel.debug%'

tests/Fixtures/app/config/config_mysql.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ doctrine:
1313
server_version: '%env(MYSQL_VERSION)%'
1414
types:
1515
uuid: Ramsey\Uuid\Doctrine\UuidType
16-
uuid_binary: Ramsey\Uuid\Doctrine\UuidBinaryType

tests/Fixtures/app/config/config_postgres.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,3 @@ doctrine:
1313
server_version: '%env(POSTGRES_VERSION)%'
1414
types:
1515
uuid: Ramsey\Uuid\Doctrine\UuidType
16-
uuid_binary: Ramsey\Uuid\Doctrine\UuidBinaryType

tests/Fixtures/app/config/config_sqlite.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,3 @@ doctrine:
1010
url: '%env(resolve:DATABASE_URL)%'
1111
types:
1212
uuid: Ramsey\Uuid\Doctrine\UuidType
13-
uuid_binary: Ramsey\Uuid\Doctrine\UuidBinaryType

0 commit comments

Comments
 (0)