Skip to content

Commit

Permalink
IBX-251: Replaced eZ\Publish\API\Repository\ContentService::loadRever…
Browse files Browse the repository at this point in the history
…seRelations usages (#1741)

* IBX-251: Replaced eZ\Publish\API\Repository\ContentService::loadReverseRelations usages

* Trigger CI
  • Loading branch information
adamwojs authored Apr 22, 2021
1 parent 1bfa43c commit d90d6be
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/bundle/Controller/ContentViewController.php
Original file line number Diff line number Diff line change
Expand Up @@ -557,13 +557,14 @@ private function supplyIsLocationBookmarked(ContentView $view): void
private function supplyContentReverseRelations(ContentView $view): void
{
$contentInfo = $view->getLocation()->getContentInfo();
$relations = $this->permissionResolver->sudo(
function (Repository $repository) use ($contentInfo) {
return $repository->getContentService()->loadReverseRelations($contentInfo);

$hasReverseRelations = $this->permissionResolver->sudo(
static function (Repository $repository) use ($contentInfo): bool {
return $repository->getContentService()->countReverseRelations($contentInfo) > 0;
},
$this->repository
);

$view->addParameters(['content_has_reverse_relations' => \count($relations) > 0]);
$view->addParameters(['content_has_reverse_relations' => $hasReverseRelations]);
}
}
6 changes: 4 additions & 2 deletions src/lib/Specification/Content/ContentHaveUniqueRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ public function isSatisfiedBy($item): bool

foreach ($relations as $relation) {
if (Relation::ASSET === $relation->type) {
$relationsFromAssetSide = $this->contentService->loadReverseRelations($relation->destinationContentInfo);
$relationsFromAssetSide = $this->contentService->countReverseRelations(
$relation->destinationContentInfo
);

if (count($relationsFromAssetSide) > 1) {
if ($relationsFromAssetSide > 1) {
return false;
}
}
Expand Down

0 comments on commit d90d6be

Please sign in to comment.