[FOLLOWUP][TASK] Doctrine: migrate AbstractDatabaseRecordList 48/48948/3
authorMarkus Klein <markus.klein@typo3.org>
Tue, 12 Jul 2016 19:01:12 +0000 (21:01 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Fri, 15 Jul 2016 19:17:27 +0000 (21:17 +0200)
Fix introduced bugs.

Resolves: #77045
Releases: master
Change-Id: I1bd0cef43dfeff30472b3d1f3b8d136a784cca3c
Reviewed-on: https://review.typo3.org/48948
Reviewed-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Morton Jonuschat <m.jonuschat@mojocode.de>
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
typo3/sysext/core/Documentation/Changelog/master/Breaking-76259-ReturnValueOfAbstractDatabaseRecordListmakeSearchStringChanged.rst
typo3/sysext/recordlist/Classes/RecordList/AbstractDatabaseRecordList.php

index 51a24a0..5c1c73d 100644 (file)
@@ -8,7 +8,9 @@ Description
 The value returned by :php:``AbstractDatabaseRecordList::makeSearchString``
 has been adjusted.
 
-The SQL fragment no longer includes the leading ``AND`` SQL operator.
+The SQL fragment no longer includes the leading ``AND`` SQL operator and the
+method returns "1=1" if no search word is specified or if the table contains
+no searchable fields.
 
 
 Impact
index 81f3289..81063d4 100755 (executable)
@@ -324,6 +324,7 @@ class AbstractDatabaseRecordList extends AbstractRecordList
      * @var array
      */
     protected $overridePageIdList = [];
+
     /**
      * Array with before/after setting for tables
      * Structure:
@@ -734,7 +735,7 @@ class AbstractDatabaseRecordList extends AbstractRecordList
      * @param string[] $fields Field list to select, * for all
      * @return \TYPO3\CMS\Core\Database\Query\QueryBuilder
      */
-    protected function getQueryBuilder(
+    public function getQueryBuilder(
         string $table,
         int $pageId,
         array $additionalConstraints = [],
@@ -804,7 +805,7 @@ class AbstractDatabaseRecordList extends AbstractRecordList
         ];
 
         if ($this->sortField && in_array($this->sortField, $this->makeFieldList($table, 1))) {
-            $parameters['orderBy'] = $this->sortRev ? [$this->sortField, 'DESC'] : [$this->sortField, 'ASC'];
+            $parameters['orderBy'][] = $this->sortRev ? [$this->sortField, 'DESC'] : [$this->sortField, 'ASC'];
         } else {
             $orderBy = $GLOBALS['TCA'][$table]['ctrl']['sortby'] ?: $GLOBALS['TCA'][$table]['ctrl']['default_sortby'];
             $parameters['orderBy'] = QueryHelper::parseOrderBy((string)$orderBy);
@@ -895,85 +896,86 @@ class AbstractDatabaseRecordList extends AbstractRecordList
         }
 
         $searchableFields = $this->getSearchFields($table);
-        if (!empty($searchableFields)) {
-            if (MathUtility::canBeInterpretedAsInteger($this->searchString)) {
-                $constraints[] = $expressionBuilder->eq('uid', (int)$this->searchString);
-                foreach ($searchableFields as $fieldName) {
-                    if (!isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) {
-                        continue;
-                    }
-                    $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config'];
-                    $fieldType = $fieldConfig['type'];
-                    $evalRules = $fieldConfig['eval'] ?: '';
-                    if ($fieldType === 'input' && $evalRules && GeneralUtility::inList($evalRules, 'int')) {
-                        if (is_array($fieldConfig['search'])
-                            && in_array('pidonly', $fieldConfig['search'], true)
-                            && $currentPid > 0
-                        ) {
-                            $constraints[] = $expressionBuilder->andX(
-                                $expressionBuilder->eq($fieldName, (int)$this->searchString),
-                                $expressionBuilder->eq($tablePidField, (int)$currentPid)
-                            );
-                        }
-                    } elseif ($fieldType === 'text'
-                        || $fieldType === 'flex'
-                        || ($fieldType === 'input' && (!$evalRules || !preg_match('/date|time|int/', $evalRules)))
+        if (empty($searchableFields)) {
+            return '1=1';
+        }
+        if (MathUtility::canBeInterpretedAsInteger($this->searchString)) {
+            $constraints[] = $expressionBuilder->eq('uid', (int)$this->searchString);
+            foreach ($searchableFields as $fieldName) {
+                if (!isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) {
+                    continue;
+                }
+                $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config'];
+                $fieldType = $fieldConfig['type'];
+                $evalRules = $fieldConfig['eval'] ?: '';
+                if ($fieldType === 'input' && $evalRules && GeneralUtility::inList($evalRules, 'int')) {
+                    if (is_array($fieldConfig['search'])
+                        && in_array('pidonly', $fieldConfig['search'], true)
+                        && $currentPid > 0
                     ) {
-                        $constraints[] = $expressionBuilder->like(
-                            $fieldName,
-                            $queryBuilder->quote('%' . (int)$this->searchString . '%')
+                        $constraints[] = $expressionBuilder->andX(
+                            $expressionBuilder->eq($fieldName, (int)$this->searchString),
+                            $expressionBuilder->eq($tablePidField, (int)$currentPid)
                         );
                     }
+                } elseif ($fieldType === 'text'
+                    || $fieldType === 'flex'
+                    || ($fieldType === 'input' && (!$evalRules || !preg_match('/date|time|int/', $evalRules)))
+                ) {
+                    $constraints[] = $expressionBuilder->like(
+                        $fieldName,
+                        $queryBuilder->quote('%' . (int)$this->searchString . '%')
+                    );
                 }
-            } else {
-                $like = $queryBuilder->quote('%' . $queryBuilder->escapeLikeWildcards($this->searchString) . '%');
-                foreach ($searchableFields as $fieldName) {
-                    if (!isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) {
-                        continue;
+            }
+        } else {
+            $like = $queryBuilder->quote('%' . $queryBuilder->escapeLikeWildcards($this->searchString) . '%');
+            foreach ($searchableFields as $fieldName) {
+                if (!isset($GLOBALS['TCA'][$table]['columns'][$fieldName])) {
+                    continue;
+                }
+                $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config'];
+                $fieldType = $fieldConfig['type'];
+                $evalRules = $fieldConfig['eval'] ?: '';
+                $searchConstraint = $expressionBuilder->andX();
+                if (is_array($fieldConfig['search'])) {
+                    $searchConfig = $fieldConfig['search'];
+                    if (in_array('case', $searchConfig)) {
+                        $searchConstraint->add($expressionBuilder->like($fieldName, $like));
+                    } else {
+                        $searchConstraint->add(
+                            $expressionBuilder->comparison(
+                                'LOWER(' . $queryBuilder->quoteIdentifier($fieldName) . ')',
+                                'LIKE',
+                                'LOWER(' . $like . ')'
+                            )
+                        );
                     }
-                    $fieldConfig = $GLOBALS['TCA'][$table]['columns'][$fieldName]['config'];
-                    $fieldType = $fieldConfig['type'];
-                    $evalRules = $fieldConfig['eval'] ?: '';
-                    $searchConstraint = $expressionBuilder->andX();
-                    if (is_array($fieldConfig['search'])) {
-                        $searchConfig = $fieldConfig['search'];
-                        if (in_array('case', $searchConfig)) {
-                            $searchConstraint->add($expressionBuilder->like($fieldName, $like));
-                        } else {
-                            $searchConstraint->add(
-                                $expressionBuilder->comparison(
-                                    'LOWER(' . $queryBuilder->quoteIdentifier($fieldName) . ')',
-                                    'LIKE',
-                                    'LOWER(' . $like . ')'
-                                )
-                            );
-                        }
-                        if (in_array('pidonly', $searchConfig) && $currentPid > 0) {
-                            $searchConstraint->add($expressionBuilder->eq($tablePidField, (int)$currentPid));
-                        }
-                        if ($searchConfig['andWhere']) {
-                            $searchConstraint->add(
-                                QueryHelper::stripLogicalOperatorPrefix($fieldConfig['search']['andWhere'])
-                            );
-                        }
+                    if (in_array('pidonly', $searchConfig) && $currentPid > 0) {
+                        $searchConstraint->add($expressionBuilder->eq($tablePidField, (int)$currentPid));
                     }
-                    if ($fieldType === 'text'
-                        || $fieldType === 'flex'
-                        || $fieldType === 'input' && (!$evalRules || !preg_match('/date|time|int/', $evalRules))
-                    ) {
-                        if ($searchConstraint->count() !== 0) {
-                            $constraints[] = $searchConstraint;
-                        }
+                    if ($searchConfig['andWhere']) {
+                        $searchConstraint->add(
+                            QueryHelper::stripLogicalOperatorPrefix($fieldConfig['search']['andWhere'])
+                        );
+                    }
+                }
+                if ($fieldType === 'text'
+                    || $fieldType === 'flex'
+                    || $fieldType === 'input' && (!$evalRules || !preg_match('/date|time|int/', $evalRules))
+                ) {
+                    if ($searchConstraint->count() !== 0) {
+                        $constraints[] = $searchConstraint;
                     }
                 }
             }
-            // If no search field conditions have been build ensure no results are returned
-            if (empty($constraints)) {
-                return '0=1';
-            }
-
-            return $expressionBuilder->orX(...$constraints);
         }
+        // If no search field conditions have been build ensure no results are returned
+        if (empty($constraints)) {
+            return '0=1';
+        }
+
+        return $expressionBuilder->orX(...$constraints);
     }
 
     /**
@@ -1392,12 +1394,6 @@ class AbstractDatabaseRecordList extends AbstractRecordList
             ->getConnectionForTable($tableName)
             ->getExpressionBuilder();
 
-        if (!empty($this->getOverridePageIdList())) {
-            $constraint = $expressionBuilder->in(
-                $tableName . '.pid',
-                $this->getOverridePageIdList()
-            );
-        }
         if ($searchLevels === 0) {
             $constraint = $expressionBuilder->eq($tableName . '.pid', (int)$this->id);
         } elseif ($searchLevels > 0) {
@@ -1405,6 +1401,13 @@ class AbstractDatabaseRecordList extends AbstractRecordList
             $constraint = $expressionBuilder->in($tableName . '.pid', array_map('intval', $allowedMounts));
         }
 
+        if (!empty($this->getOverridePageIdList())) {
+            $constraint = $expressionBuilder->in(
+                $tableName . '.pid',
+                $this->getOverridePageIdList()
+            );
+        }
+
         return (string)$constraint;
     }