[BUGFIX] Fix relative path resolution in include static 68/29468/4
authorMarkus Klein <klein.t3@mfc-linz.at>
Mon, 14 Apr 2014 23:01:50 +0000 (01:01 +0200)
committerMarkus Klein <klein.t3@mfc-linz.at>
Thu, 22 May 2014 12:10:38 +0000 (14:10 +0200)
Fix the usage of relative paths in INCLUDE_TYPOSCRIPT inclusions of
static templates from extensions.

EXT:myext/Configuration/TypoScript/setup.txt:
<INCLUDE_TYPOSCRIPT: source="DIR:./Setup/">

EXT:myext/Configuration/TypoScript/Setup/ holds some TS files.

Resolves: #57447
Releases: 6.2
Change-Id: I64ba190fa6959eb27a2d6f1c278cfb9c9c3cbfaf
Reviewed-on: https://review.typo3.org/29468
Reviewed-by: Stefan Neufeind
Reviewed-by: Wouter Wolters
Tested-by: Wouter Wolters
Reviewed-by: Jan Kiesewetter
Tested-by: Jan Kiesewetter
Reviewed-by: Markus Klein
Tested-by: Markus Klein
typo3/sysext/core/Classes/TypoScript/TemplateService.php
typo3/sysext/core/Tests/Unit/TypoScript/TemplateServiceTest.php

index 812a335..e899b1a 100644 (file)
@@ -27,6 +27,7 @@ namespace TYPO3\CMS\Core\TypoScript;
  *  This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
 
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
@@ -185,6 +186,12 @@ class TemplateService {
         */
        public $constants = array();
 
+       /**
+        * Holds the include paths of the templates (empty if from database)
+        * @var array
+        */
+       protected $templateIncludePaths = array();
+
        // For Template Analyser in backend
        /**
         * @todo Define visibility
@@ -620,11 +627,12 @@ class TemplateService {
         * @param array $pid The PID of the input template record
         * @param string $templateID The id of the current template. Same syntax as $idList ids, eg. "sys_123
         * @param string $templateParent Parent template id (during recursive call); Same syntax as $idList ids, eg. "sys_123
+        * @param string $includePath Specifies the path from which the template was included (used with static_includes)
         * @return void
         * @see runThroughTemplates()
         * @todo Define visibility
         */
-       public function processTemplate($row, $idList, $pid, $templateID = '', $templateParent = '') {
+       public function processTemplate($row, $idList, $pid, $templateID = '', $templateParent = '', $includePath = '') {
                // Adding basic template record information to rowSum array
                $this->rowSum[] = array($row['uid'], $row['title'], $row['tstamp']);
                // Processing "Clear"-flags
@@ -707,6 +715,7 @@ class TemplateService {
                // Adding the content of the fields constants (Constants) and config (Setup)
                $this->constants[] = $row['constants'];
                $this->config[] = $row['config'];
+               $this->templateIncludePaths[] = $includePath;
                // For backend analysis (Template Analyser) provide the order of added constants/config template IDs
                $this->clearList_const[] = $templateID;
                $this->clearList_setup[] = $templateID;
@@ -808,7 +817,7 @@ class TemplateService {
                                                                'uid' => $mExtKey
                                                        );
                                                        $subrow = $this->prependStaticExtra($subrow);
-                                                       $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID);
+                                                       $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID, $ISF_filePath);
                                                }
                                        }
                                }
@@ -859,7 +868,8 @@ class TemplateService {
                                        'uid' => $mExtKey
                                );
                                $subrow = $this->prependStaticExtra($subrow);
-                               $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID);
+                               $extPath = ExtensionManagementUtility::extPath($extKey);
+                               $this->processTemplate($subrow, $idList . ',ext_' . $mExtKey, $pid, 'ext_' . $mExtKey, $templateID, $extPath);
                        }
                }
        }
@@ -1053,15 +1063,17 @@ class TemplateService {
                        return;
                }
 
+               $paths = $this->templateIncludePaths;
                $files = array();
                foreach ($this->constants as &$value) {
-                       $includeData = \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines($value, 1, TRUE);
+                       $includeData = \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines($value, 1, TRUE, array_shift($paths));
                        $files = array_merge($files, $includeData['files']);
                        $value = $includeData['typoscript'];
                }
                unset($value);
+               $paths = $this->templateIncludePaths;
                foreach ($this->config as &$value) {
-                       $includeData = \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines($value, 1, TRUE);
+                       $includeData = \TYPO3\CMS\Core\TypoScript\Parser\TypoScriptParser::checkIncludeLines($value, 1, TRUE, array_shift($paths));
                        $files = array_merge($files, $includeData['files']);
                        $value = $includeData['typoscript'];
                }
@@ -1658,9 +1670,10 @@ class TemplateService {
                if (!$this->isDefaultTypoScriptAdded) {
                        // adding default setup and constants
                        // defaultTypoScript_setup is *very* unlikely to be empty
-                       // the count of elements in ->constants and ->config have to be in sync so we always add *both*
+                       // the count of elements in ->constants, ->config and ->templateIncludePaths have to be in sync
                        array_unshift($this->constants, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_constants']);
                        array_unshift($this->config, (string)$GLOBALS['TYPO3_CONF_VARS']['FE']['defaultTypoScript_setup']);
+                       array_unshift($this->templateIncludePaths, '');
                        // prepare a proper entry to hierachyInfo (used by TemplateAnalyzer in BE)
                        $rootTemplateId = $this->hierarchyInfo[count($this->hierarchyInfo)-1]['templateID'];
                        $defaultTemplateInfo = array(
index fd816c3..2620749 100644 (file)
@@ -23,6 +23,8 @@ namespace TYPO3\CMS\Core\Tests\Unit\TypoScript;
  *
  * This copyright notice MUST APPEAR in all copies of the script!
  ***************************************************************/
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 
 /**
  * Testcase for \TYPO3\CMS\Core\TypoScript\TemplateService
@@ -78,7 +80,7 @@ class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $identifier = uniqid('test');
                $GLOBALS['TYPO3_LOADED_EXT'] = array(
                        $identifier => array(
-                               'ext_typoscript_setup.txt' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath(
+                               'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
                                        'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
                                ),
                        ),
@@ -97,17 +99,29 @@ class TemplateServiceTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
                $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'
-                               ),
+                               'ext_typoscript_setup.txt' => ExtensionManagementUtility::extPath(
+                                               'core', 'Tests/Unit/TypoScript/Fixtures/ext_typoscript_setup.txt'
+                                       ),
+                               'ext_typoscript_constants.txt' => ''
                        ),
                );
 
+               $mockPackage = $this->getMock('TYPO3\\CMS\\Core\\Package\\Package', array('getPackagePath'), array(), '', FALSE);
+               $mockPackage->expects($this->any())->method('getPackagePath')->will($this->returnValue(''));
+
+               $mockPackageManager = $this->getMock('TYPO3\\CMS\\Core\\Package\\PackageManager', array('isPackageActive' , 'getPackage'));
+               $mockPackageManager->expects($this->any())->method('isPackageActive')->will($this->returnValue(TRUE));
+               $mockPackageManager->expects($this->any())->method('getPackage')->will($this->returnValue($mockPackage));
+               ExtensionManagementUtility::setPackageManager($mockPackageManager);
+
                $this->templateService->setProcessExtensionStatics(TRUE);
                $this->templateService->runThroughTemplates(array(), 0);
+
                $this->assertTrue(
                        in_array('test.Core.TypoScript = 1', $this->templateService->config)
                );
+
+               ExtensionManagementUtility::setPackageManager(GeneralUtility::makeInstance('TYPO3\\CMS\\Core\\Package\\PackageManager'));
        }
 
        /**