Skip to content
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
12 changes: 2 additions & 10 deletions src/lib/Specification/Content/ContentHaveAssetRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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;
}
}
21 changes: 16 additions & 5 deletions src/lib/Specification/Content/ContentHaveUniqueRelation.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -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) {
Expand Down
Loading