Bug #100999
closedIncoherent QueryInterface
100%
Description
I just had the requirement to get the total count of a given query.
The query was created with `\TYPO3\CMS\Extbase\Persistence\RepositoryInterface::createQuery`.
The repository interface correctly returns an `\TYPO3\CMS\Extbase\Persistence\QueryInterface`.
From here on this gets pretty incoherent. The first attempt is to simply
$query->setOffset(null);
$query->setLimit(null);
Which is not possible, due to hard type checks. Trying to use a stupid `setLimit(-1)` or `setLimit(0)` just leads to an hard exit `The limit must be an integer >= 1` exception from `\TYPO3\CMS\Extbase\Persistence\Generic\Query::setLimit`, which implements `\TYPO3\CMS\Extbase\Persistence\QueryInterface::setLimit`.
Browsing the `QueryInterface` offers no option to unset the limit in any way. The implementation however seems to support a `\TYPO3\CMS\Extbase\Persistence\Generic\Query::unsetLimit`, which is not a part of the interface, therefore I need to do a
if (!($query instanceof Query)) {
throw new \InvalidArgumentException('Query must be instance of ' . Query::class);
}
on every part where I interact with the repository interface.
It would be nice to have:
- A clean interface that documents how to unset limit (and maybe offset)
- A non-failure on `LIMIT 0`, it is allowed in many drivers. I do not see any reason for the ORM query builder to escalate those those calls, as the result is still valid. It might not be used often though.
Also there is a PHP warning triggered when using `unsetLimit` of the `Query` implementation:
Core: Error handler (FE): PHP Warning: Undefined property: TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Query::$limit in /var/www/html/public/typo3/sysext/extbase/Classes/Persistence/Generic/Query.php line 315
This is due to using `unset($this->limit)` and then returning it with `return $this->limit` during execution without checking for its existance.