[BUGFIX] TS is fetched from cache incorrectly sometimes
[Packages/TYPO3.CMS.git] / typo3 / sysext / core / Classes / TypoScript / TemplateService.php
index 773013a..649f619 100644 (file)
@@ -309,6 +309,15 @@ class TemplateService {
         */
        protected $processExtensionStatics = FALSE;
 
+       /**
+        * Set to TRUE after the default TypoScript was added during parsing.
+        * This prevents double inclusion of the same TypoScript code.
+        *
+        * @see addDefaultTypoScript()
+        * @var boolean
+        */
+       protected $isDefaultTypoScriptAdded = FALSE;
+
        /**
         * @return boolean
         */
@@ -471,7 +480,14 @@ class TemplateService {
                        if ($setupData && !$this->forceTemplateParsing) {
                                // If TypoScript setup structure was cached we unserialize it here:
                                $this->setup = unserialize($setupData);
+                               if ($this->tt_track) {
+                                       $GLOBALS['TT']->setTSLogMessage('Using cached TS template data');
+                               }
                        } else {
+                               if ($this->tt_track) {
+                                       $GLOBALS['TT']->setTSLogMessage('Not using any cached TS data');
+                               }
+
                                // Make configuration
                                $this->generateConfig();
                                // This stores the template hash thing
@@ -536,8 +552,9 @@ class TemplateService {
                $this->config = array();
                $this->rowSum = array();
                $this->hierarchyInfoToRoot = array();
-               // Is the TOTAL rootline
                $this->absoluteRootLine = $theRootLine;
+               $this->isDefaultTyposcriptAdded = FALSE;
+
                reset($this->absoluteRootLine);
                $c = count($this->absoluteRootLine);
                for ($a = 0; $a < $c; $a++) {
@@ -570,10 +587,15 @@ 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());
                }
+
+               // Add the global default TypoScript from the TYPO3_CONF_VARS
+               $this->addDefaultTypoScript();
+
                $this->processIncludes();
        }
 
@@ -882,11 +904,9 @@ class TemplateService {
         * @todo Define visibility
         */
        public function generateConfig() {
-               // Add default TS for all three code types:
-               array_unshift($this->constants, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
-               // Adding default TS/constants
-               array_unshift($this->config, '' . $GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
-               // Adding default TS/setup
+               // Add default TS for all code types
+               $this->addDefaultTypoScript();
+
                // Parse the TypoScript code text for include-instructions!
                $this->processIncludes();
                // These vars are also set lateron...
@@ -1598,7 +1618,27 @@ class TemplateService {
                }
        }
 
-}
+       /**
+        * Adds the TypoScript from the global array.
+        * The class property isDefaultTypoScriptAdded ensures
+        * that the adding only happens once.
+        *
+        * @return void
+        * @see isDefaultTypoScriptAdded
+        */
+       protected function addDefaultTypoScript() {
+                       // Add default TS for all code types, if not done already
+               if (!$this->isDefaultTypoScriptAdded) {
+                       if (!empty($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants'])) {
+                               array_unshift($this->constants, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
+                       }
+                       if (!empty($GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup'])) {
+                               array_unshift($this->config, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
+                       }
+                       $this->isDefaultTypoScriptAdded = TRUE;
+               }
+       }
 
+}
 
 ?>