Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IBX-8534: Dropped removed ContentService::loadRelations methods usage #1395

Merged
merged 2 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
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
5 changes: 4 additions & 1 deletion src/lib/UI/Dataset/VersionsDataset.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -41,9 +42,11 @@ public function __construct(ContentService $contentService, ValueFactory $valueF
*/
public function load(ContentInfo $contentInfo): self
{
$versions = $this->contentService->loadVersions($contentInfo);

$this->data = array_map(
[$this->valueFactory, 'createVersionInfo'],
$this->contentService->loadVersions($contentInfo)
iterator_to_array($versions)
);

return $this;
Expand Down
Loading