[BUGFIX] Respect query constraints in suggest receiver count 92/57192/4
authorAlexander Stehlik <alexander.stehlik@gmail.com>
Mon, 11 Jun 2018 18:51:17 +0000 (20:51 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 15 Jun 2018 10:06:15 +0000 (12:06 +0200)
The query builder that fetches the results in the suggest
receiver is re-used to get the correct count of available
results.

Resolves: #85228
Relates: #78129
Releases: master
Change-Id: I2df36d4668cdde616242912e7f0d53bcded18021
Reviewed-on: https://review.typo3.org/57192
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/backend/Classes/Form/Wizard/SuggestWizardDefaultReceiver.php

index b9663a0..0933d6c 100644 (file)
@@ -147,19 +147,20 @@ class SuggestWizardDefaultReceiver
      */
     public function queryTable(&$params, $recursionCounter = 0)
     {
+        $maxQueryResults = 50;
         $rows = [];
         $this->params = &$params;
-        $start = $recursionCounter * 50;
+        $start = $recursionCounter * $maxQueryResults;
         $this->prepareSelectStatement();
         $this->prepareOrderByStatement();
         $result = $this->queryBuilder->select('*')
             ->from($this->table)
             ->setFirstResult($start)
-            ->setMaxResults(50)
+            ->setMaxResults($maxQueryResults)
             ->execute();
-        $allRowsCount = GeneralUtility::makeInstance(ConnectionPool::class)
-            ->getQueryBuilderForTable($this->table)
+        $allRowsCount = $this->queryBuilder
             ->count('uid')
+            ->resetQueryPart('orderBy')
             ->execute()
             ->fetchColumn(0);
         if ($allRowsCount) {
@@ -204,7 +205,7 @@ class SuggestWizardDefaultReceiver
             }
 
             // if there are less records than we need, call this function again to get more records
-            if (count($rows) < $this->maxItems && $allRowsCount >= 50 && $recursionCounter < $this->maxItems) {
+            if (count($rows) < $this->maxItems && $allRowsCount >= $maxQueryResults && $recursionCounter < $this->maxItems) {
                 $tmp = self::queryTable($params, ++$recursionCounter);
                 $rows = array_merge($tmp, $rows);
             }