[BUGFIX] Wrong DB fields usage in TCEmain
authorFelix Nagel <info@felixnagel.com>
Wed, 16 May 2012 13:11:52 +0000 (15:11 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Sun, 20 May 2012 11:24:01 +0000 (13:24 +0200)
The fix for issue #35260 introduced a new bug in method
t3lib_TCEmain::getPreviousLocalizedRecordUid() by adding a
field in a query in the wrong place. In particular, this breaks
the localization of tt_content elements used with IRRE.

This patch fixes the problem by separating the list of fields
used for selecting and for sorting.

Change-Id: Idac10ded43e817f22df34e5156b424829d4601c1
Fixes: #37221
Releases: 6.0, 4.7, 4.6, 4.5
Reviewed-on: http://review.typo3.org/11292
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
t3lib/class.t3lib_tcemain.php

index 05f830e..cfff942 100644 (file)
@@ -6079,21 +6079,22 @@ class t3lib_TCEmain {
                $previousLocalizedRecordUid = $uid;
                if ($GLOBALS['TCA'][$table] && $GLOBALS['TCA'][$table]['ctrl']['sortby']) {
                        $sortRow = $GLOBALS['TCA'][$table]['ctrl']['sortby'];
+                       $select = $sortRow . ',pid,uid';
                                // For content elements, we also need the colPos
                        if ($table === 'tt_content') {
-                               $sortRow .= ',colPos';
+                               $select .= ',colPos';
                        }
                                // Get the sort value of the default language record
-                       $row = t3lib_BEfunc::getRecord($table, $uid, $sortRow . ',pid,uid');
+                       $row = t3lib_BEfunc::getRecord($table, $uid, $select);
                        if (is_array($row)) {
                                        // Find the previous record in default language on the same page
                                $where = 'pid=' . intval($pid) . ' AND ' . 'sys_language_uid=0' . ' AND ' . $sortRow . '<' . intval($row[$sortRow]);
 
                                        // Respect the colPos for content elements
                                if ($table === 'tt_content') {
-                                       $where .= ' AND colPos=' . $row['colPos'];
+                                       $where .= ' AND colPos=' . intval($row['colPos']);
                                }
-                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($sortRow . ',pid,uid', $table, $where . $this->deleteClause($table), '', $sortRow . ' DESC', '1');
+                               $res = $GLOBALS['TYPO3_DB']->exec_SELECTquery($select, $table, $where . $this->deleteClause($table), '', $sortRow . ' DESC', '1');
                                        // If there is an element, find its localized record in specified localization language
                                if ($previousRow = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($res)) {
                                        $previousLocalizedRecord = t3lib_BEfunc::getRecordLocalization($table, $previousRow['uid'], $language);