[BUGFIX] RootlineUtility does not consider disablefield 00/28400/2
authorChristian Reiter <cr@cxd.de>
Tue, 11 Mar 2014 19:50:01 +0000 (20:50 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 14 Mar 2014 20:49:15 +0000 (21:49 +0100)
Make sure RootlineUtility::enrichWithRelationFields() respects
the setting of $TCA[$table]['ctrl']['enablecolumns']['disabled'] when
fetching foreign data for the rootline.

Otherwise hidden relations from sys_file_reference are added to the
rootline and cause exceptions in the frontend, instead of being ignored.

Resolves: #56150
Releases: 6.2, 6.1
Change-Id: I21917fec1407a10818058da8ea879b0bb39441a4
Reviewed-on: https://review.typo3.org/28400
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/core/Classes/Utility/RootlineUtility.php
typo3/sysext/core/Tests/Unit/Utility/RootlineUtilityTest.php

index 0013898..18b9783 100644 (file)
@@ -285,6 +285,9 @@ class RootlineUtility {
                                                        $whereClauseParts[] = trim($configuration['foreign_table_field']) . ' = \'pages\'';
                                                }
                                        }
+                                       if (isset($GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'])) {
+                                               $whereClauseParts[] = $table . '.' . $GLOBALS['TCA'][$table]['ctrl']['enablecolumns']['disabled'] . ' = 0';
+                                       }
                                        $whereClause = implode(' AND ', $whereClauseParts);
                                        $whereClause .= $this->pageContext->deleteClause($table);
                                        $orderBy = isset($configuration['foreign_sortby']) ? $configuration['foreign_sortby'] : '';
index 35f6557..48d2755 100644 (file)
@@ -295,6 +295,41 @@ class RootlineUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $this->fixture->_set('languageUid', 1);
                $this->assertSame($pageDataTranslated, $this->fixture->_call('getRecordArray', 1));
        }
+
+       /**
+        * @test
+        */
+       public function enrichWithRelationFieldsCreatesWhereClauseForDisabledField() {
+               $mockDatabaseConnection = $this->getMock('\TYPO3\CMS\Core\Database\DatabaseConnection', array('exec_SELECTgetRows'), array(), '', FALSE);
+               $subject = $this->getAccessibleMock('\TYPO3\CMS\Core\Utility\RootlineUtility', array('columnHasRelationToResolve'), array(1, '', $this->pageContextMock));
+               $subject->_set('databaseConnection', $mockDatabaseConnection);
+               $GLOBALS['TYPO3_CONF_VARS']['FE']['pageOverlayFields'] = '';
+               $foreign_table = uniqid('foreign_table');
+               $foreign_field = uniqid('foreign_field');
+               $GLOBALS['TCA'][$foreign_table]['ctrl']['enablecolumns']['disabled'] = uniqid('disabled');
+               $GLOBALS['TCA']['pages']['columns'] = array(
+                       'test' => array(
+                               'config' => array(
+                                       'foreign_table' => $foreign_table,
+                                       'foreign_field' => $foreign_field
+                               )
+                       )
+               );
+               $expected = array(
+                       $foreign_field . ' = 0',
+                       $foreign_table . '.' . $GLOBALS['TCA'][$foreign_table]['ctrl']['enablecolumns']['disabled'] . ' = 0'
+               );
+               $this->pageContextMock->expects($this->once())->method('deleteClause')->will($this->returnValue(''));
+               $mockDatabaseConnection->expects(
+                       $this->once())->
+                       method('exec_SELECTgetRows')->
+                       with('uid', $foreign_table, implode(' AND ', $expected), '', '', '', '')->
+                       // the return value does not matter much, it is only here to prevent error messages from further code execution
+                       will($this->returnValue(array('uid' => 17))
+               );
+               $subject->expects($this->once())->method('columnHasRelationToResolve')->will($this->returnValue(TRUE));
+               $subject->_call('enrichWithRelationFields', 17, array());
+       }
 }
 
-?>
\ No newline at end of file
+?>