[BUGFIX] respect rootLevel=-1 in exec_foreign_table_where_query 76/18976/2
authorStefan Froemken <froemken@gmail.com>
Thu, 21 Feb 2013 12:34:22 +0000 (13:34 +0100)
committerBenjamin Mack <benni@typo3.org>
Fri, 5 Apr 2013 19:44:33 +0000 (21:44 +0200)
exec_foreign_table_where_query does not interpret the
rootLevel directive correctly.

Resolves: #45703
Releases: 6.1, 6.0, 4.7, 4.6, 4.5
Change-Id: I2a4dd0335ac5373562f287427d5592cfd406e2f9
Reviewed-on: https://review.typo3.org/18417
Reviewed-by: Benjamin Mack
Tested-by: Benjamin Mack
Reviewed-on: https://review.typo3.org/18976
Reviewed-by: Stefan Neufeind
typo3/sysext/backend/Classes/Utility/BackendUtility.php

index 9009eef..b9c6467 100644 (file)
@@ -3052,13 +3052,16 @@ class BackendUtility {
                $fTWHERE = str_replace('###PAGE_TSCONFIG_ID###', intval($TSconfig[$field]['PAGE_TSCONFIG_ID']), $fTWHERE);
                $fTWHERE = str_replace('###PAGE_TSCONFIG_IDLIST###', $GLOBALS['TYPO3_DB']->cleanIntList($TSconfig[$field]['PAGE_TSCONFIG_IDLIST']), $fTWHERE);
                $fTWHERE = str_replace('###PAGE_TSCONFIG_STR###', $GLOBALS['TYPO3_DB']->quoteStr($TSconfig[$field]['PAGE_TSCONFIG_STR'], $foreign_table), $fTWHERE);
-               // rootLevel = -1 is not handled 'properly' here - it goes as if it was rootLevel = 1 (that is pid=0)
                $wgolParts = $GLOBALS['TYPO3_DB']->splitGroupOrderLimit($fTWHERE);
-               if ($rootLevel) {
+               // rootLevel = -1 means that elements can be on the rootlevel OR on any page (pid!=-1)
+               // rootLevel = 0 means that elements are not allowed on root level
+               // rootLevel = 1 means that elements are only on the root level (pid=0)
+               if ($rootLevel == 1 || $rootLevel == -1) {
+                       $pidWhere = $foreign_table . '.pid' . (($rootLevel == -1) ? '<>-1' : '=0');
                        $queryParts = array(
                                'SELECT' => self::getCommonSelectFields($foreign_table, $foreign_table . '.'),
                                'FROM' => $foreign_table,
-                               'WHERE' => $foreign_table . '.pid=0 ' . self::deleteClause($foreign_table) . ' ' . $wgolParts['WHERE'],
+                               'WHERE' => $pidWhere . ' ' . self::deleteClause($foreign_table) . ' ' . $wgolParts['WHERE'],
                                'GROUPBY' => $wgolParts['GROUPBY'],
                                'ORDERBY' => $wgolParts['ORDERBY'],
                                'LIMIT' => $wgolParts['LIMIT']