diff --git a/src/lib/Specification/Content/ContentHaveAssetRelation.php b/src/lib/Specification/Content/ContentHaveAssetRelation.php index 746777d747..f602a9ae4d 100644 --- a/src/lib/Specification/Content/ContentHaveAssetRelation.php +++ b/src/lib/Specification/Content/ContentHaveAssetRelation.php @@ -11,8 +11,8 @@ use Ibexa\AdminUi\Exception\InvalidArgumentException; use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\Core\Repository\Values\Content\Content; +use Ibexa\Contracts\Core\Repository\Values\Content\RelationType; use Ibexa\Contracts\Core\Specification\AbstractSpecification; -use Ibexa\Core\Repository\Values\Content\Relation; class ContentHaveAssetRelation extends AbstractSpecification { @@ -41,14 +41,6 @@ public function isSatisfiedBy($item): bool throw new InvalidArgumentException($item, sprintf('Must be an instance of %s', Content::class)); } - $relations = $this->contentService->loadRelations($item->versionInfo); - - foreach ($relations as $relation) { - if (Relation::ASSET === $relation->type) { - return true; - } - } - - return false; + return $this->contentService->countRelations($item->versionInfo, RelationType::ASSET) > 0; } } diff --git a/src/lib/Specification/Content/ContentHaveUniqueRelation.php b/src/lib/Specification/Content/ContentHaveUniqueRelation.php index 0cab15f362..22b48a32aa 100644 --- a/src/lib/Specification/Content/ContentHaveUniqueRelation.php +++ b/src/lib/Specification/Content/ContentHaveUniqueRelation.php @@ -10,9 +10,11 @@ use Ibexa\AdminUi\Exception\InvalidArgumentException; 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\RelationType; use Ibexa\Contracts\Core\Specification\AbstractSpecification; -use Ibexa\Core\Repository\Values\Content\Relation; class ContentHaveUniqueRelation extends AbstractSpecification { @@ -41,12 +43,21 @@ public function isSatisfiedBy($item): bool throw new InvalidArgumentException($item, sprintf('Must be an instance of %s', Content::class)); } - $relations = $this->contentService->loadRelations($item->versionInfo); + $relationListIterator = new BatchIterator( + new RelationListIteratorAdapter( + $this->contentService, + $item->getVersionInfo(), + RelationType::ASSET + ) + ); - foreach ($relations as $relation) { - if (Relation::ASSET === $relation->type) { + /** @var \Ibexa\Contracts\Core\Repository\Values\Content\RelationList\Item\RelationListItem $relationItem */ + foreach ($relationListIterator as $relationItem) { + if ($relationItem->hasRelation()) { + /** @var \Ibexa\Contracts\Core\Repository\Values\Content\Relation $relation */ + $relation = $relationItem->getRelation(); $relationsFromAssetSide = $this->contentService->countReverseRelations( - $relation->destinationContentInfo + $relation->getDestinationContentInfo() ); if ($relationsFromAssetSide > 1) {