Since TYPO3 v12 the use of constraints in the repository query is not working like before.
public function findByDate(
$dateFrom = null,
$dateTill = null,
$isAdmin = false,
$tags = [],
$keyword = ''
): QueryResultInterface
{
$query = $this->createQuery();
$query->getQuerySettings()->setIgnoreEnableFields(TRUE);
$query->getQuerySettings()->setEnableFieldsToBeIgnored(['starttime','endtime']);
$constraints = [];
if ($keyword != '') {
$constraints[] = $query->like('titel', '%'.$keyword.'%' );
}else{
if (isset($dateFrom) && isset($dateTill)) {
$constraints[] = $query->logicalAnd(
$query->lessThan('startdate', $dateTill->getTimestamp()),
$query->greaterThan('startdate', $dateFrom->getTimestamp()),
);
}
}
if (count($tags) > 0) {
$constraints[] = $query->logicalOr(
$query->in('tags.uid', $tags)
);
}
if ($isAdmin == false) {
$constraints[] = $query->equals('share', true);
}
$query->matching($query->logicalAnd($constraints));
return $query->execute();
}
Error
TYPO3\CMS\Extbase\Persistence\Generic\Query::logicalAnd(): Argument #1 must be of type TYPO3\CMS\Extbase\Persistence\Generic\Qom\ConstraintInterface, array given
output of the constraints:
Is there still a way to use constraints?
- Query with one condition is working
- LogicalAnd with 2 constraints directly also works
$constraints
to a object class, throwing away collected constraints .. and living with the danger, that collecting code afterwards would override that again you will have broken code. Therefore, this is not a "correct" answer for the given code example. In my answer I mentioned the core signature change and the spread operator needs to be used instead of passing an array. That do not destroyfindByDate
. – Bengaline