[BUGFIX] Fix offset and limit in list module 99/54999/3
authorSusanne Moog <susanne.moog@typo3.com>
Sat, 9 Dec 2017 15:01:06 +0000 (16:01 +0100)
committerBenni Mack <benni@typo3.org>
Sat, 9 Dec 2017 21:57:23 +0000 (22:57 +0100)
Offset and limit in a count query do not make sense.

Additionally the hook deprecation was incomplete
as the core also threw deprecation warnings on
list module pagination.

Change-Id: I8435d15c981f47e2940dbbf470e2de84fc3d5055
Resolves: #83269
Releases: master
Reviewed-on: https://review.typo3.org/54999
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/recordlist/Classes/RecordList/DatabaseRecordList.php

index 4f6f7a6..a714577 100644 (file)
@@ -3200,6 +3200,10 @@ class DatabaseRecordList
             $queryBuilder->setMaxResults($this->iLimit);
         }
 
+        if ($this->firstElementNumber > 0) {
+            $queryBuilder->setFirstResult($this->firstElementNumber);
+        }
+
         if ($addSorting) {
             if ($this->sortField && in_array($this->sortField, $this->makeFieldList($table, 1))) {
                 $queryBuilder->orderBy($this->sortField, $this->sortRev ? 'DESC' : 'ASC');
@@ -3284,7 +3288,7 @@ class DatabaseRecordList
                 $queryBuilder->addOrderBy($fieldName, $sorting);
             }
         }
-        if (!empty($parameters['firstResult'])) {
+        if (!empty($parameters['firstResult']) && $parameters['firstResult'] !== $this->firstElementNumber) {
             $this->logDeprecation('firstResult');
             $queryBuilder->setFirstResult((int)$parameters['firstResult']);
         }
@@ -3325,6 +3329,9 @@ class DatabaseRecordList
         }
 
         $queryBuilder = $this->prepareQueryBuilder($table, $pageId, ['*'], $constraints, $queryBuilder, false);
+        // Reset limit and offset for full count query
+        $queryBuilder->setFirstResult(0);
+        $queryBuilder->setMaxResults(1);
 
         $this->totalItems = (int)$queryBuilder->count('*')
             ->execute()