[BUGFIX] Exception with EXT:sys_note is installed 86/19286/2
authorOliver Hader <oliver@typo3.org>
Thu, 21 Mar 2013 15:03:26 +0000 (16:03 +0100)
committerOliver Hader <oliver.hader@typo3.org>
Tue, 26 Mar 2013 09:42:52 +0000 (10:42 +0100)
If extension sys_note is installed, and the first page does not
have a TypoScript Template with an accordant root flag, a
system exception is thrown, pointing out that the table
"tx_extbase_domain_model_backenduser" could not be found.

The reason for that is:
* the sys_note backend behaviour is based on Extbase
* Extbase is being configured using (front-end) TypoScript
* ext_typoscript_setup.txt files are not processed if there's
  no accordant root template for the current rootline
* the persistence mapping from "be_users" to the mentioned
  "tx_extbase_domain_model_backenduser" would have been defined
  in the external TypoScript file

The solution is to check, whether these external files got
processed during TypoScript parsing and will be processed
explicitely if they have not been integrated yet.

Change-Id: I06a7edecd5cdac9dd7ab3918b281712602ad6b36
Fixes: #46250
Related: #46511
Release: 6.0, 6.1
Reviewed-on: https://review.typo3.org/19286
Reviewed-by: Oliver Hader
Tested-by: Oliver Hader
typo3/sysext/core/Classes/TypoScript/TemplateService.php
typo3/sysext/core/Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt [new file with mode: 0644]
typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php

index 4c6a475..4b84b03 100644 (file)
@@ -295,6 +295,38 @@ class TemplateService {
        public $MPmap = '';
 
        /**
+        * Indicator that extension statics are processed.
+        *
+        * These files are considered if either a root template
+        * has been processed or the $processExtensionStatics
+        * property has been set to TRUE.
+        *
+        * @var boolean
+        */
+       protected $extensionStaticsProcessed = FALSE;
+
+       /**
+        * Trigger value, to ensure that extension statics are processed.
+        *
+        * @var boolean
+        */
+       protected $processExtensionStatics = FALSE;
+
+       /**
+        * @return boolean
+        */
+       public function getProcessExtensionStatics() {
+               return $this->processExtensionStatics;
+       }
+
+       /**
+        * @param boolean $processExtensionStatics
+        */
+       public function setProcessExtensionStatics($processExtensionStatics) {
+               $this->processExtensionStatics = (bool) $processExtensionStatics;
+       }
+
+       /**
         * Initialize
         * MUST be called directly after creating a new template-object
         *
@@ -543,6 +575,10 @@ class TemplateService {
                        $GLOBALS['TYPO3_DB']->sql_free_result($res);
                        $this->rootLine[] = $this->absoluteRootLine[$a];
                }
+               // Process extension static files if not done yet, but explicitly requested
+               if (!$this->extensionStaticsProcessed && $this->processExtensionStatics) {
+                       $this->addExtensionStatics('sys_0', 'sys_0', 0, array());
+               }
                $this->processIncludes();
        }
 
@@ -749,6 +785,8 @@ class TemplateService {
         * @todo Define visibility
         */
        public function addExtensionStatics($idList, $templateID, $pid, $row) {
+               $this->extensionStaticsProcessed = TRUE;
+
                foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extKey => $files) {
                        if (is_array($files) && ($files['ext_typoscript_constants.txt'] || $files['ext_typoscript_setup.txt'])) {
                                $mExtKey = str_replace('_', '', $extKey);
@@ -1530,4 +1568,4 @@ class TemplateService {
 }
 
 
-?>
\ No newline at end of file
+?>
diff --git a/typo3/sysext/core/Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt b/typo3/sysext/core/Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt
new file mode 100644 (file)
index 0000000..b843d96
--- /dev/null
@@ -0,0 +1 @@
+test.Core.TypoScript = 1
\ No newline at end of file
index 9375300..5813e0f 100644 (file)
@@ -39,6 +39,29 @@ class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
        protected $backupGlobals = TRUE;
 
        /**
+        * @var \TYPO3\CMS\Core\TypoScript\TemplateService
+        */
+       protected $templateService;
+
+       /**
+        * Sets up this test case.
+        *
+        * @return void
+        */
+       protected function setUp() {
+               $this->templateService = new \TYPO3\CMS\Core\TypoScript\TemplateService();
+       }
+
+       /**
+        * Tears down this test case.
+        *
+        * @return void
+        */
+       protected function tearDown() {
+               unset($this->templateService);
+       }
+
+       /**
         * @test
         */
        public function versionOlCallsVersionOlOfPageSelectClassWithGivenRow() {
@@ -47,8 +70,46 @@ class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $sysPageMock = $this->getMock('TYPO3\\CMS\\Frontend\\Page\\PageRepository');
                $sysPageMock->expects($this->once())->method('versionOL')->with('sys_template', $row);
                $GLOBALS['TSFE']->sys_page = $sysPageMock;
-               $instance = new \TYPO3\CMS\Core\TypoScript\TemplateService();
-               $instance->versionOL($row);
+               $this->templateService->versionOL($row);
+       }
+
+       /**
+        * @test
+        */
+       public function extensionStaticFilesAreNotProcessedIfNotExplicitlyRequested() {
+               $identifier = uniqid('test');
+               $GLOBALS['TYPO3_LOADED_EXT'] = array(
+                       $identifier => array(
+                               'ext_typoscript_setup.txt' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
+                                       'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
+                               ),
+                       ),
+               );
+
+               $this->templateService->runThroughTemplates(array(), 0);
+               $this->assertFalse(
+                       in_array('test.Core.TypoScript = 1', $this->templateService->config)
+               );
+       }
+
+       /**
+        * @test
+        */
+       public function extensionStaticsAreProcessedIfExplicitlyRequested() {
+               $identifier = uniqid('test');
+               $GLOBALS['TYPO3_LOADED_EXT'] = array(
+                       $identifier => array(
+                               'ext_typoscript_setup.txt' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
+                                       'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
+                               ),
+                       ),
+               );
+
+               $this->templateService->setProcessExtensionStatics(TRUE);
+               $this->templateService->runThroughTemplates(array(), 0);
+               $this->assertTrue(
+                       in_array('test.Core.TypoScript = 1', $this->templateService->config)
+               );
        }
 
 }