Skip to content

Commit

Permalink
IBX-8534: Dropped removed ContentService::loadRelations methods usage
Browse files Browse the repository at this point in the history
  • Loading branch information
ViniTou committed Nov 18, 2024
1 parent f969c8e commit dbf9c24
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 27 deletions.
15 changes: 0 additions & 15 deletions phpstan-baseline.neon
Original file line number Diff line number Diff line change
Expand Up @@ -455,11 +455,6 @@ parameters:
count: 1
path: src/bundle/Controller/LinkManagerController.php

-
message: "#^Cannot access offset 0 on iterable\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Relation\\>\\.$#"
count: 1
path: src/bundle/Controller/LocationController.php

-
message: "#^Cannot access property \\$contentId on Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\Location\\|null\\.$#"
count: 3
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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\\<Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\Values\\\\Content\\\\VersionInfo\\> given\\.$#"
count: 1
path: src/lib/UI/Dataset/VersionsDataset.php

-
message: "#^Call to an undefined method Ibexa\\\\Contracts\\\\Core\\\\Repository\\\\PermissionResolver\\:\\:sudo\\(\\)\\.$#"
count: 1
Expand Down
18 changes: 16 additions & 2 deletions src/bundle/Controller/LocationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
27 changes: 18 additions & 9 deletions src/lib/UI/Dataset/RelationsDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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) {
Expand Down
8 changes: 7 additions & 1 deletion src/lib/UI/Dataset/VersionsDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit dbf9c24

Please sign in to comment.