Skip to content

Commit 2e2debb

Browse files
authored
feat(mongodb): Replace usage of deprecated method AggregationBuilder::execute() (api-platform#6933)
1 parent 4bdf042 commit 2e2debb

File tree

8 files changed

+40
-13
lines changed

8 files changed

+40
-13
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@
124124
"doctrine/common": "^3.2.2",
125125
"doctrine/dbal": "^4.0",
126126
"doctrine/doctrine-bundle": "^2.11",
127-
"doctrine/mongodb-odm": "^2.9.2",
127+
"doctrine/mongodb-odm": "^2.10",
128128
"doctrine/mongodb-odm-bundle": "^4.0 || ^5.0",
129129
"doctrine/orm": "^2.17 || ^3.0",
130130
"elasticsearch/elasticsearch": "^8.4",

src/Doctrine/Odm/Extension/PaginationExtension.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public function getResult(Builder $aggregationBuilder, string $resourceClass, ?O
111111
$attribute = $operation?->getExtraProperties()['doctrine_mongodb'] ?? [];
112112
$executeOptions = $attribute['execute_options'] ?? [];
113113

114-
return new Paginator($aggregationBuilder->execute($executeOptions), $manager->getUnitOfWork(), $resourceClass);
114+
return new Paginator($aggregationBuilder->getAggregation($executeOptions)->getIterator(), $manager->getUnitOfWork(), $resourceClass);
115115
}
116116

117117
private function addCountToContext(Builder $aggregationBuilder, array $context): array

src/Doctrine/Odm/State/CollectionProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,6 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
7777
$attribute = $operation->getExtraProperties()['doctrine_mongodb'] ?? [];
7878
$executeOptions = $attribute['execute_options'] ?? [];
7979

80-
return $aggregationBuilder->hydrate($documentClass)->execute($executeOptions);
80+
return $aggregationBuilder->hydrate($documentClass)->getAggregation($executeOptions)->getIterator();
8181
}
8282
}

src/Doctrine/Odm/State/ItemProvider.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,6 @@ public function provide(Operation $operation, array $uriVariables = [], array $c
8484

8585
$executeOptions = $operation->getExtraProperties()['doctrine_mongodb']['execute_options'] ?? [];
8686

87-
return $aggregationBuilder->hydrate($documentClass)->execute($executeOptions)->current() ?: null;
87+
return $aggregationBuilder->hydrate($documentClass)->getAggregation($executeOptions)->getIterator()->current() ?: null;
8888
}
8989
}

src/Doctrine/Odm/State/LinksHandlerTrait.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,7 @@ private function buildAggregation(string $toClass, array $links, array $identifi
128128
return $aggregation;
129129
}
130130

131-
$results = $aggregation->execute($executeOptions)->toArray();
131+
$results = $aggregation->getAggregation($executeOptions)->getIterator()->toArray();
132132
$in = [];
133133
foreach ($results as $result) {
134134
foreach ($result[$lookupPropertyAlias] ?? [] as $lookupResult) {

src/Doctrine/Odm/Tests/Extension/PaginationExtensionTest.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
use Doctrine\ODM\MongoDB\Aggregation\Stage\Facet;
2828
use Doctrine\ODM\MongoDB\Aggregation\Stage\Skip;
2929
use Doctrine\ODM\MongoDB\DocumentManager;
30+
use Doctrine\ODM\MongoDB\Iterator\IterableResult;
3031
use Doctrine\ODM\MongoDB\Iterator\Iterator;
3132
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
3233
use Doctrine\Persistence\ManagerRegistry;
@@ -333,8 +334,11 @@ public function testGetResult(): void
333334
],
334335
]);
335336

337+
$aggregationProphecy = $this->prophesize(IterableResult::class);
338+
$aggregationProphecy->getIterator()->willReturn($iteratorProphecy->reveal());
339+
336340
$aggregationBuilderProphecy = $this->prophesize(Builder::class);
337-
$aggregationBuilderProphecy->execute([])->willReturn($iteratorProphecy->reveal());
341+
$aggregationBuilderProphecy->getAggregation([])->willReturn($aggregationProphecy->reveal());
338342
$aggregationBuilderProphecy->getPipeline()->willReturn([
339343
[
340344
'$facet' => [
@@ -390,8 +394,11 @@ public function testGetResultWithExecuteOptions(): void
390394
],
391395
]);
392396

397+
$aggregationProphecy = $this->prophesize(IterableResult::class);
398+
$aggregationProphecy->getIterator()->willReturn($iteratorProphecy->reveal());
399+
393400
$aggregationBuilderProphecy = $this->prophesize(Builder::class);
394-
$aggregationBuilderProphecy->execute(['allowDiskUse' => true])->willReturn($iteratorProphecy->reveal());
401+
$aggregationBuilderProphecy->getAggregation(['allowDiskUse' => true])->willReturn($aggregationProphecy->reveal());
395402
$aggregationBuilderProphecy->getPipeline()->willReturn([
396403
[
397404
'$facet' => [

src/Doctrine/Odm/Tests/State/CollectionProviderTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
use ApiPlatform\Metadata\Resource\Factory\ResourceMetadataCollectionFactoryInterface;
2323
use Doctrine\ODM\MongoDB\Aggregation\Builder;
2424
use Doctrine\ODM\MongoDB\DocumentManager;
25+
use Doctrine\ODM\MongoDB\Iterator\IterableResult;
2526
use Doctrine\ODM\MongoDB\Iterator\Iterator;
2627
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
2728
use Doctrine\Persistence\ManagerRegistry;
@@ -50,9 +51,12 @@ public function testGetCollection(): void
5051
{
5152
$iterator = $this->prophesize(Iterator::class)->reveal();
5253

54+
$aggregationProphecy = $this->prophesize(IterableResult::class);
55+
$aggregationProphecy->getIterator()->willReturn($iterator);
56+
5357
$aggregationBuilderProphecy = $this->prophesize(Builder::class);
5458
$aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled();
55-
$aggregationBuilderProphecy->execute([])->willReturn($iterator)->shouldBeCalled();
59+
$aggregationBuilderProphecy->getAggregation([])->willReturn($aggregationProphecy)->shouldBeCalled();
5660
$aggregationBuilder = $aggregationBuilderProphecy->reveal();
5761

5862
$repositoryProphecy = $this->prophesize(DocumentRepository::class);
@@ -76,9 +80,12 @@ public function testGetCollectionWithExecuteOptions(): void
7680
{
7781
$iterator = $this->prophesize(Iterator::class)->reveal();
7882

83+
$aggregationProphecy = $this->prophesize(IterableResult::class);
84+
$aggregationProphecy->getIterator()->willReturn($iterator);
85+
7986
$aggregationBuilderProphecy = $this->prophesize(Builder::class);
8087
$aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled();
81-
$aggregationBuilderProphecy->execute(['allowDiskUse' => true])->willReturn($iterator)->shouldBeCalled();
88+
$aggregationBuilderProphecy->getAggregation(['allowDiskUse' => true])->willReturn($aggregationProphecy)->shouldBeCalled();
8289
$aggregationBuilder = $aggregationBuilderProphecy->reveal();
8390

8491
$repositoryProphecy = $this->prophesize(DocumentRepository::class);
@@ -143,9 +150,12 @@ public function testOperationNotFound(): void
143150
{
144151
$iterator = $this->prophesize(Iterator::class)->reveal();
145152

153+
$aggregationProphecy = $this->prophesize(IterableResult::class);
154+
$aggregationProphecy->getIterator()->willReturn($iterator);
155+
146156
$aggregationBuilderProphecy = $this->prophesize(Builder::class);
147157
$aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled();
148-
$aggregationBuilderProphecy->execute([])->willReturn($iterator)->shouldBeCalled();
158+
$aggregationBuilderProphecy->getAggregation([])->willReturn($aggregationProphecy)->shouldBeCalled();
149159
$aggregationBuilder = $aggregationBuilderProphecy->reveal();
150160

151161
$repositoryProphecy = $this->prophesize(DocumentRepository::class);

src/Doctrine/Odm/Tests/State/ItemProviderTest.php

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
use Doctrine\ODM\MongoDB\Aggregation\Builder;
2525
use Doctrine\ODM\MongoDB\Aggregation\Stage\MatchStage as AggregationMatch;
2626
use Doctrine\ODM\MongoDB\DocumentManager;
27+
use Doctrine\ODM\MongoDB\Iterator\IterableResult;
2728
use Doctrine\ODM\MongoDB\Iterator\Iterator;
2829
use Doctrine\ODM\MongoDB\Mapping\ClassMetadata;
2930
use Doctrine\ODM\MongoDB\Repository\DocumentRepository;
@@ -49,10 +50,13 @@ public function testGetItemSingleIdentifier(): void
4950
$result = new \stdClass();
5051
$iterator->current()->willReturn($result)->shouldBeCalled();
5152

53+
$aggregationProphecy = $this->prophesize(IterableResult::class);
54+
$aggregationProphecy->getIterator()->willReturn($iterator);
55+
5256
$aggregationBuilderProphecy = $this->prophesize(Builder::class);
5357
$aggregationBuilderProphecy->match()->willReturn($matchProphecy->reveal())->shouldBeCalled();
5458
$aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled();
55-
$aggregationBuilderProphecy->execute([])->willReturn($iterator->reveal())->shouldBeCalled();
59+
$aggregationBuilderProphecy->getAggregation([])->willReturn($aggregationProphecy->reveal())->shouldBeCalled();
5660
$aggregationBuilder = $aggregationBuilderProphecy->reveal();
5761

5862
$managerRegistry = $this->getManagerRegistry(ProviderDocument::class, $aggregationBuilder);
@@ -82,10 +86,13 @@ public function testGetItemWithExecuteOptions(): void
8286
$result = new \stdClass();
8387
$iterator->current()->willReturn($result)->shouldBeCalled();
8488

89+
$aggregationProphecy = $this->prophesize(IterableResult::class);
90+
$aggregationProphecy->getIterator()->willReturn($iterator);
91+
8592
$aggregationBuilderProphecy = $this->prophesize(Builder::class);
8693
$aggregationBuilderProphecy->match()->willReturn($matchProphecy->reveal())->shouldBeCalled();
8794
$aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled();
88-
$aggregationBuilderProphecy->execute(['allowDiskUse' => true])->willReturn($iterator->reveal())->shouldBeCalled();
95+
$aggregationBuilderProphecy->getAggregation(['allowDiskUse' => true])->willReturn($aggregationProphecy->reveal())->shouldBeCalled();
8996
$aggregationBuilder = $aggregationBuilderProphecy->reveal();
9097

9198
$managerRegistry = $this->getManagerRegistry(ProviderDocument::class, $aggregationBuilder);
@@ -116,10 +123,13 @@ public function testGetItemDoubleIdentifier(): void
116123
$result = new \stdClass();
117124
$iterator->current()->willReturn($result)->shouldBeCalled();
118125

126+
$aggregationProphecy = $this->prophesize(IterableResult::class);
127+
$aggregationProphecy->getIterator()->willReturn($iterator);
128+
119129
$aggregationBuilderProphecy = $this->prophesize(Builder::class);
120130
$aggregationBuilderProphecy->match()->willReturn($matchProphecy->reveal())->shouldBeCalled();
121131
$aggregationBuilderProphecy->hydrate(ProviderDocument::class)->willReturn($aggregationBuilderProphecy)->shouldBeCalled();
122-
$aggregationBuilderProphecy->execute([])->willReturn($iterator->reveal())->shouldBeCalled();
132+
$aggregationBuilderProphecy->getAggregation([])->willReturn($aggregationProphecy->reveal())->shouldBeCalled();
123133
$aggregationBuilder = $aggregationBuilderProphecy->reveal();
124134

125135
$managerRegistry = $this->getManagerRegistry(ProviderDocument::class, $aggregationBuilder);

0 commit comments

Comments
 (0)