Fix exception if none available category is selected

This commit is contained in:
Daniel Siepmann 2022-07-12 07:22:48 +02:00
parent 0fe793307a
commit 7e604504a3
2 changed files with 21 additions and 20 deletions

View file

@ -45,19 +45,10 @@ class DateRepository extends Repository
{ {
$query = $this->createQuery(); $query = $this->createQuery();
$constraints = []; $constraints = [];
$categories = $demand->getCategories();
if ($categories) { $categoriesConstraint = $this->createCategoryConstraint($query, $demand);
$categoryConstraints = $this->createCategoryConstraint( if ($categoriesConstraint instanceof ConstraintInterface) {
$query, $constraints['categories'] = $categoriesConstraint;
$categories,
$demand->getIncludeSubCategories()
);
if ($demand->getCategoryCombination() === 'or') {
$constraints['categories'] = $query->logicalOr($categoryConstraints);
} else {
$constraints['categories'] = $query->logicalAnd($categoryConstraints);
}
} }
if ($demand->getFeatures() !== []) { if ($demand->getFeatures() !== []) {
@ -170,21 +161,30 @@ class DateRepository extends Repository
protected function createCategoryConstraint( protected function createCategoryConstraint(
QueryInterface $query, QueryInterface $query,
string $categories, DateDemand $demand
bool $includeSubCategories = false ): ?ConstraintInterface {
): array { $categories = $demand->getCategories();
$constraints = []; $constraints = [];
if ($includeSubCategories) { if ($demand->getIncludeSubCategories()) {
$categoryService = GeneralUtility::makeInstance(CategoryService::class); $categories = GeneralUtility::makeInstance(CategoryService::class)
$categories = $categoryService->getChildrenCategories($categories); ->getChildrenCategories($categories);
} }
$categories = GeneralUtility::intExplode(',', $categories, true); $categories = GeneralUtility::intExplode(',', $categories, true);
foreach ($categories as $category) { foreach ($categories as $category) {
$constraints[] = $query->contains('event.categories', $category); $constraints[] = $query->contains('event.categories', $category);
} }
return $constraints;
if ($constraints === []) {
return null;
}
if ($demand->getCategoryCombination() === 'or') {
return $query->logicalOr($constraints);
}
return $query->logicalAnd($constraints);
} }
private function createFeaturesConstraint( private function createFeaturesConstraint(

View file

@ -47,7 +47,8 @@ Features
Fixes Fixes
----- -----
Nothing * Do not break within repository if no longer existing category is requested.
The code didn't catch that situation and would fail with an TYPO3 exception.
Tasks Tasks
----- -----