[BUGFIX] Fix SQL error in Livesearch with empty TCA sortby setting
authorLaurent Cherpit <lcherpit@ttree.ch>
Sat, 6 Oct 2012 15:18:43 +0000 (17:18 +0200)
committerXavier Perseguers <xavier@typo3.org>
Tue, 16 Oct 2012 09:06:20 +0000 (11:06 +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: I0457020ef31850458e3bd4286214f8e57278223e
Fixes: #40816
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/15542
Reviewed-by: Wouter Wolters
Reviewed-by: Stefan Neufeind
Reviewed-by: Xavier Perseguers
Tested-by: Xavier Perseguers
t3lib/search/class.t3lib_search_livesearch.php

index 5c79596..6e3a69b 100644 (file)
@@ -411,7 +411,10 @@ class t3lib_search_livesearch {
                $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'];
                }