[BUGFIX] Respect endOfRange in pagination 50/57650/4
authorGuido Schmechel <guido.schmechel@brandung.de>
Sat, 21 Jul 2018 12:55:14 +0000 (14:55 +0200)
committerBenni Mack <benni@typo3.org>
Mon, 29 Oct 2018 10:59:08 +0000 (11:59 +0100)
If prepareObjectsSlice is called in the pagination with a QueryResult,
the endOfRange is calculated and used for each page.

This ensures that the maximum limit is not exceeded.

Resolves: #85585
Releases: master
Change-Id: I13f2ce910cbb4102782aafffca0ff7d193620735
Reviewed-on: https://review.typo3.org/57650
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Daniel Goerz <daniel.goerz@posteo.de>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/fluid/Classes/ViewHelpers/Widget/Controller/PaginateController.php

index 9fa4224..d1cf639 100644 (file)
@@ -170,10 +170,16 @@ class PaginateController extends AbstractWidgetController
     protected function prepareObjectsSlice($itemsPerPage, $offset)
     {
         if ($this->objects instanceof QueryResultInterface) {
+            $currentRange = $offset + $itemsPerPage;
+            $endOfRange = min($currentRange, count($this->objects));
             $query = $this->objects->getQuery();
             $query->setLimit($itemsPerPage);
             if ($offset > 0) {
                 $query->setOffset($offset);
+                if ($currentRange > $endOfRange) {
+                    $newLimit = $endOfRange - $offset;
+                    $query->setLimit($newLimit);
+                }
             }
             $modifiedObjects = $query->execute();
             return $modifiedObjects;