diff --git a/Neos.Media/Classes/Domain/Repository/AssetRepository.php b/Neos.Media/Classes/Domain/Repository/AssetRepository.php index 3fe7719d196..7489ef11d60 100644 --- a/Neos.Media/Classes/Domain/Repository/AssetRepository.php +++ b/Neos.Media/Classes/Domain/Repository/AssetRepository.php @@ -87,7 +87,7 @@ public function findBySearchTermOrTags($searchTerm, array $tags = [], AssetColle $constraints[] = $query->contains('tags', $tag); } $query->matching($query->logicalOr($constraints)); - $this->addAssetVariantFilterClause($query); + $this->addAssetVariantToQueryConstraints($query); $this->addAssetCollectionToQueryConstraints($query, $assetCollection); return $query->execute(); } @@ -104,7 +104,7 @@ public function findByTag(Tag $tag, AssetCollection $assetCollection = null): Qu { $query = $this->createQuery(); $query->matching($query->contains('tags', $tag)); - $this->addAssetVariantFilterClause($query); + $this->addAssetVariantToQueryConstraints($query); $this->addAssetCollectionToQueryConstraints($query, $assetCollection); return $query->execute(); } @@ -147,7 +147,7 @@ public function countByTag(Tag $tag, AssetCollection $assetCollection = null): i public function findAll(AssetCollection $assetCollection = null): QueryResultInterface { $query = $this->createQuery(); - $this->addAssetVariantFilterClause($query); + $this->addAssetVariantToQueryConstraints($query); $this->addAssetCollectionToQueryConstraints($query, $assetCollection); return $query->execute(); } @@ -188,7 +188,7 @@ public function findUntagged(AssetCollection $assetCollection = null): QueryResu { $query = $this->createQuery(); $query->matching($query->isEmpty('tags')); - $this->addAssetVariantFilterClause($query); + $this->addAssetVariantToQueryConstraints($query); $this->addAssetCollectionToQueryConstraints($query, $assetCollection); return $query->execute(); } @@ -229,7 +229,7 @@ public function countUntagged(AssetCollection $assetCollection = null): int public function findByAssetCollection(AssetCollection $assetCollection): QueryResultInterface { $query = $this->createQuery(); - $this->addAssetVariantFilterClause($query); + $this->addAssetVariantToQueryConstraints($query); $this->addAssetCollectionToQueryConstraints($query, $assetCollection); return $query->execute(); } @@ -268,9 +268,8 @@ protected function addAssetCollectionToQueryConstraints(QueryInterface $query, A return; } - $query->getQueryBuilder()->andWhere( - $query->contains('assetCollections', $assetCollection) - ); + $constraints = $query->getConstraint(); + $query->matching($query->logicalAnd([$constraints, $query->contains('assetCollections', $assetCollection)])); } /** @@ -279,14 +278,16 @@ protected function addAssetCollectionToQueryConstraints(QueryInterface $query, A * @param Query $query * @return void */ - protected function addAssetVariantFilterClause(Query $query): void + protected function addAssetVariantToQueryConstraints(QueryInterface $query): void { - $queryBuilder = $query->getQueryBuilder(); - + $variantsConstraints = []; $variantClassNames = $this->reflectionService->getAllImplementationClassNamesForInterface(AssetVariantInterface::class); foreach ($variantClassNames as $variantClassName) { - $queryBuilder->andWhere('e NOT INSTANCE OF ' . $variantClassName); + $variantsConstraints[] = 'e NOT INSTANCE OF ' . $variantClassName; } + + $constraints = $query->getConstraint(); + $query->matching($query->logicalAnd([$constraints, $query->logicalAnd($variantsConstraints)])); } /** @@ -353,7 +354,7 @@ public function findAllIterator(): IterableResult { /** @var Query $query */ $query = $this->createQuery(); - $this->addAssetVariantFilterClause($query); + $this->addAssetVariantToQueryConstraints($query); return $query->getQueryBuilder()->getQuery()->iterate(); }