From dbf9c243ed46e1fd950ff405beb6dfab336a72ff Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Mon, 18 Nov 2024 14:31:28 +0100 Subject: [PATCH 1/2] 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; From d6657ea0b5595e64a63180f4c4248c39b44d04f6 Mon Sep 17 00:00:00 2001 From: Dawid Parafinski Date: Mon, 18 Nov 2024 14:38:39 +0100 Subject: [PATCH 2/2] switched to iterator_to_array polyfill --- composer.json | 1 + src/lib/UI/Dataset/VersionsDataset.php | 7 ++----- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/composer.json b/composer.json index 790da838df..5ea3f908ec 100644 --- a/composer.json +++ b/composer.json @@ -28,6 +28,7 @@ "ibexa/core": "~5.0.x-dev", "ibexa/design-engine": "~5.0.x-dev", "ibexa/fieldtype-richtext": "~5.0.x-dev", + "ibexa/polyfill-php82": "^1.0", "ibexa/rest": "~5.0.x-dev", "ibexa/search": "~5.0.x-dev", "ibexa/user": "~5.0.x-dev", diff --git a/src/lib/UI/Dataset/VersionsDataset.php b/src/lib/UI/Dataset/VersionsDataset.php index ebc3a88d7a..d6f8ff5445 100644 --- a/src/lib/UI/Dataset/VersionsDataset.php +++ b/src/lib/UI/Dataset/VersionsDataset.php @@ -12,6 +12,7 @@ use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\Values\Content\ContentInfo; use Ibexa\Contracts\Core\Repository\Values\Content\VersionInfo; +use function Ibexa\PolyfillPhp82\iterator_to_array; class VersionsDataset { @@ -43,13 +44,9 @@ 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'], - $versions + iterator_to_array($versions) ); return $this;