Skip to content

5.0: Use RelationListIterator #2548

New issue

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

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

Already on GitHub? # to your account

Draft
wants to merge 14 commits into
base: 5.0
Choose a base branch
from
Draft
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Command;

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\LocationService;
use Ibexa\Contracts\Core\Repository\ObjectStateService;
use Ibexa\Contracts\Core\Repository\PermissionResolver;
Expand Down Expand Up @@ -104,9 +106,13 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Relations
$versionInfo = $this->contentService->loadVersionInfo($contentInfo);
$relationCount = $this->contentService->countRelations($versionInfo);
$relationList = $this->contentService->loadRelationList($versionInfo, 0, $relationCount);
foreach ($relationList as $relationListItem) {
$relationListIterator = new BatchIterator(
new RelationListIteratorAdapter(
$this->contentService,
$versionInfo
)
);
foreach ($relationListIterator as $relationListItem) {
$name = $relationListItem->hasRelation() ? $relationListItem->getRelation()->destinationContentInfo->name : '(Unauthorized)';
$output->writeln("Relation to content '$name'");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
namespace App\Controller;

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\LocationService;
use Ibexa\Core\MVC\Symfony\View\View;

Expand All @@ -25,11 +27,16 @@ public function showContentAction(View $view, $locationId): View
$location = $this->locationService->loadLocation($locationId);
$contentInfo = $location->getContentInfo();
$versionInfo = $this->contentService->loadVersionInfo($contentInfo);
$relationList = $this->contentService->loadRelationList($versionInfo);
$relationListIterator = new BatchIterator(
new RelationListIteratorAdapter(
$this->contentService,
$versionInfo
)
);

$items = [];

foreach ($relationList as $relationListItem) {
foreach ($relationListIterator as $relationListItem) {
if ($relationListItem->hasRelation() && in_array($relationListItem->getRelation()->getDestinationContentInfo()->getContentType()->identifier, $acceptedContentTypes)) {
$items[] = $this->contentService->loadContentByContentInfo($relationListItem->getRelation()->getDestinationContentInfo());
}
Expand Down
Loading
Loading