From dbf9c243ed46e1fd950ff405beb6dfab336a72ff Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Mon, 18 Nov 2024 14:31:28 +0100 Subject: [PATCH] IBX-8534: Dropped removed ContentService::loadRelations methods usage --- phpstan-baseline.neon | 15 ----------- src/bundle/Controller/LocationController.php | 18 +++++++++++-- src/lib/UI/Dataset/RelationsDataset.php | 27 +++++++++++++------- src/lib/UI/Dataset/VersionsDataset.php | 8 +++++- 4 files changed, 41 insertions(+), 27 deletions(-) diff --git a/phpstan-baseline.neon b/phpstan-baseline.neon index bdf62a5ff2..3c8d6eb251 100644 --- a/phpstan-baseline.neon +++ b/phpstan-baseline.neon @@ -455,11 +455,6 @@ parameters: count: 1 path: src/bundle/Controller/LinkManagerController.php - - - message: "#^Cannot access offset 0 on iterable\\\\.$#" - count: 1 - path: src/bundle/Controller/LocationController.php - - message: "#^Cannot access property \\$contentId on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Location\\|null\\.$#" count: 3 @@ -9330,11 +9325,6 @@ parameters: count: 1 path: src/lib/UI/Dataset/PoliciesDataset.php - - - message: "#^PHPDoc tag @param references unknown parameter\\: \\$versionInfo$#" - count: 1 - path: src/lib/UI/Dataset/RelationsDataset.php - - message: "#^Method Ibexa\\\\AdminUi\\\\UI\\\\Dataset\\\\RolesDataset\\:\\:__construct\\(\\) has parameter \\$userContentTypeIdentifier with no value type specified in iterable type array\\.$#" count: 1 @@ -9390,11 +9380,6 @@ parameters: count: 1 path: src/lib/UI/Dataset/VersionsDataset.php - - - message: "#^Parameter \\#2 \\$array of function array_map expects array, iterable\\ given\\.$#" - count: 1 - path: src/lib/UI/Dataset/VersionsDataset.php - - message: "#^Call to an undefined method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\PermissionResolver\\:\\:sudo\\(\\)\\.$#" count: 1 diff --git a/src/bundle/Controller/LocationController.php b/src/bundle/Controller/LocationController.php index 091e67e6cf..0984bd47e5 100644 --- a/src/bundle/Controller/LocationController.php +++ b/src/bundle/Controller/LocationController.php @@ -375,8 +375,22 @@ public function trashAction(Request $request): Response private function trashRelatedAsset(ContentInfo $contentInfo): void { $content = $this->contentService->loadContentByContentInfo($contentInfo); - $relations = $this->contentService->loadRelations($content->versionInfo); - $imageLocation = $this->locationService->loadLocation($relations[0]->destinationContentInfo->mainLocationId); + $relations = $this->contentService->loadRelationList( + $content->versionInfo, + 0, + 1 + ); + + /** @var \Ibexa\Contracts\Core\Repository\Values\Content\RelationList\Item\RelationListItem $relation */ + $relation = $relations->items[0]; + if (!$relation->hasRelation()) { + return; + } + $mainLocationId = $relation->getRelation()->getDestinationContentInfo()->getMainLocationId(); + if ($mainLocationId === null) { + return; + } + $imageLocation = $this->locationService->loadLocation($mainLocationId); $this->trashService->trash($imageLocation); } diff --git a/src/lib/UI/Dataset/RelationsDataset.php b/src/lib/UI/Dataset/RelationsDataset.php index 2551ddd228..7b973d1028 100644 --- a/src/lib/UI/Dataset/RelationsDataset.php +++ b/src/lib/UI/Dataset/RelationsDataset.php @@ -11,6 +11,8 @@ use Ibexa\AdminUi\UI\Value as UIValue; use Ibexa\AdminUi\UI\Value\ValueFactory; use Ibexa\Contracts\Core\Repository\ContentService; +use Ibexa\Contracts\Core\Repository\Iterator\BatchIterator; +use Ibexa\Contracts\Core\Repository\Iterator\BatchIteratorAdapter\RelationListIteratorAdapter; use Ibexa\Contracts\Core\Repository\Values\Content\Content; use Ibexa\Contracts\Core\Repository\Values\Content\RelationList\Item\RelationListItem; @@ -41,21 +43,28 @@ public function __construct(ContentService $contentService, ValueFactory $valueF } /** - * @param VersionInfo $versionInfo - * - * @return RelationsDataset - * * @throws \Ibexa\Contracts\Core\Repository\Exceptions\UnauthorizedException */ public function load(Content $content): self { $versionInfo = $content->getVersionInfo(); - foreach ($this->contentService->loadRelations($versionInfo) as $relation) { - $this->relations[] = $this->valueFactory->createRelationItem( - new RelationListItem($relation), - $content - ); + $relationListIterator = new BatchIterator( + new RelationListIteratorAdapter( + $this->contentService, + $versionInfo + ) + ); + + foreach ($relationListIterator as $relationItem) { + if ($relationItem->hasRelation()) { + /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Relation $relation */ + $relation = $relationItem->getRelation(); + $this->relations[] = $this->valueFactory->createRelationItem( + new RelationListItem($relation), + $content + ); + } } foreach ($this->contentService->loadReverseRelations($versionInfo->getContentInfo()) as $reverseRelation) { diff --git a/src/lib/UI/Dataset/VersionsDataset.php b/src/lib/UI/Dataset/VersionsDataset.php index 9e9603d62e..ebc3a88d7a 100644 --- a/src/lib/UI/Dataset/VersionsDataset.php +++ b/src/lib/UI/Dataset/VersionsDataset.php @@ -41,9 +41,15 @@ public function __construct(ContentService $contentService, ValueFactory $valueF */ public function load(ContentInfo $contentInfo): self { + $versions = $this->contentService->loadVersions($contentInfo); + + if ($versions instanceof \Traversable) { + $versions = iterator_to_array($versions); + } + $this->data = array_map( [$this->valueFactory, 'createVersionInfo'], - $this->contentService->loadVersions($contentInfo) + $versions ); return $this;