[BUGFIX] Fix SQL error in Livesearch with empty TCA sortby setting
authorLoek Hilgersom <loek@netcoop.nl>
Tue, 11 Sep 2012 18:54:52 +0000 (20:54 +0200)
committerHelmut Hummel <helmut.hummel@typo3.org>
Thu, 11 Oct 2012 16:34:18 +0000 (18:34 +0200)
If a searchable TCA field has a sortby setting which contains an empty
string or NULL, then BE Livesearch creates a query with one or more
'ORDER BY' without value, generating an SQL error. This fixes that.

Change-Id: I63aabfe860cd37645d9ac2905ed020d572629a1b
Fixes: #40816
Releases: 6.0
Reviewed-on: http://review.typo3.org/14526
Reviewed-by: Dmitry Dulepov
Tested-by: Dmitry Dulepov
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Mattias Nilsson
Tested-by: Mattias Nilsson
Reviewed-by: Helmut Hummel
Tested-by: Helmut Hummel
typo3/sysext/backend/Classes/Search/LiveSearch/LiveSearch.php

index 8025c1c..b9afa1a 100644 (file)
@@ -371,7 +371,10 @@ class LiveSearch {
        protected function makeOrderByTable($tableName) {
                $orderBy = '';
                if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('sortby', $GLOBALS['TCA'][$tableName]['ctrl'])) {
-                       $orderBy = 'ORDER BY ' . $GLOBALS['TCA'][$tableName]['ctrl']['sortby'];
+                       $sortBy = trim($GLOBALS['TCA'][$tableName]['ctrl']['sortby']);
+                       if (!empty($sortBy)) {
+                               $orderBy = 'ORDER BY ' . $sortBy;
+                       }
                } else {
                        $orderBy = $GLOBALS['TCA'][$tableName]['ctrl']['default_sortby'];
                }
@@ -469,4 +472,4 @@ class LiveSearch {
 }
 
 
-?>
\ No newline at end of file
+?>