[BUGFIX] RespectStoragePage does not respect rootLevel
authorStefan Frömken <sfroemken@jweiland.net>
Thu, 21 Feb 2013 15:41:48 +0000 (16:41 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 12 Apr 2013 11:39:42 +0000 (13:39 +0200)
AdditionalWhereClause pid statement for set rootLevel=-1 will be empty,
and for rootLevel = 1 it will limit the query to pid = 0.
For not set rootLevel or rootLevel = 0 the given Pids are taken into
account.

Fixes: #45715
Releases: 6.1
Change-Id: I5f4cdc23273fef186d620e2596a0e3e1eab313ce
Reviewed-on: https://review.typo3.org/18425
Reviewed-by: Frans Saris
Tested-by: Frans Saris
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Persistence/Generic/Storage/Typo3DbBackend.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Storage/Typo3DbBackendTest.php

index a8cb2a4..5ea5dec 100644 (file)
@@ -1001,7 +1001,14 @@ class Typo3DbBackend implements \TYPO3\CMS\Extbase\Persistence\Generic\Storage\B
                        $this->tableColumnCache->set($tableName, $tableColumns);
                }
                if (is_array($GLOBALS['TCA'][$tableName]['ctrl']) && array_key_exists('pid', $tableColumns)) {
-                       $sql['additionalWhereClause'][] = $tableName . '.pid IN (' . implode(', ', $storagePageIds) . ')';
+                       $rootLevel = (int)$GLOBALS['TCA'][$tableName]['ctrl']['rootLevel'];
+                       if ($rootLevel) {
+                               if ($rootLevel === 1) {
+                                       $sql['additionalWhereClause'][] = $tableName . '.pid = 0';
+                               }
+                       } else {
+                               $sql['additionalWhereClause'][] = $tableName . '.pid IN (' . implode(', ', $storagePageIds) . ')';
+                       }
                }
        }
 
@@ -1244,4 +1251,4 @@ class Typo3DbBackend implements \TYPO3\CMS\Extbase\Persistence\Generic\Storage\B
        }
 }
 
-?>
\ No newline at end of file
+?>
index 527b0fd..9fe1af7 100644 (file)
@@ -472,6 +472,53 @@ class Typo3DbBackendTest extends \TYPO3\CMS\Extbase\Tests\Unit\BaseTestCase {
                $mockTypo3DbBackend->_set('pageRepository', $pageRepositoryMock);
                $this->assertSame(array($comparisonRow), $mockTypo3DbBackend->_call('doLanguageAndWorkspaceOverlay', $sourceMock, array($row), $languageUid, $workspaceUid));
        }
+
+       /**
+        * DataProvider for addPageIdStatement Tests
+        */
+       public function providerForAddPageIdStatementData() {
+               $table = uniqid('tx_coretest_table');
+               return array(
+                       'set Pid to zero if rootLevel = 1' => array(
+                               '1',
+                               $table,
+                               array('additionalWhereClause' => array($table . '.pid = 0'))
+                       ),
+                       'set Pid to given Pids if rootLevel = 0' => array(
+                               '0',
+                               $table,
+                               array('additionalWhereClause' => array($table . '.pid IN (42, 27)'))
+                       ),
+                       'set no statement if rootLevel = -1' => array(
+                               '-1',
+                               $table,
+                               array()
+                       )
+               );
+       }
+
+       /**
+        * @test
+        * @dataProvider providerForAddPageIdStatementData
+        */
+       public function addPageIdStatementSetsPidToZeroIfTableDeclaresRootlevel($rootLevel, $table, $expectedSql) {
+
+               $GLOBALS['TCA'][$table]['ctrl'] = array(
+                       'rootLevel' => $rootLevel
+               );
+               $querySettings = new \TYPO3\CMS\Extbase\Persistence\Generic\Typo3QuerySettings();
+               $querySettings->initializeObject();
+               $sql = array();
+               $storagePageIds = array(42,27);
+               $mockTypo3DbBackend = $this->getAccessibleMock('TYPO3\\CMS\\Extbase\\Persistence\\Generic\\Storage\\Typo3DbBackend', array('dummy'), array(), '', FALSE);
+               $mockFrontendVariableCache = $this->getMock('TYPO3\\CMS\\Core\\Cache\\Frontend\\VariableFrontend', array(), array(), '', FALSE);
+               $mockTypo3DbBackend->_set('tableColumnCache', $mockFrontendVariableCache);
+               $mockFrontendVariableCache->expects($this->once())->method('get')->will($this->returnValue(array('pid' => '42')));
+               $mockTypo3DbBackend->_callRef('addPageIdStatement', $table, $sql, $storagePageIds);
+
+               $this->assertSame($expectedSql, $sql);
+       }
+
 }
 
 ?>
\ No newline at end of file