[BUGFIX] ExtensionManagementUtility tries to include non-existing files 57/18757/4
authorDmitry Dulepov <dmitry.dulepov@gmail.com>
Wed, 6 Mar 2013 17:51:13 +0000 (21:51 +0400)
committerChristian Kuhn <lolli@schwarzbu.ch>
Thu, 7 Mar 2013 20:47:44 +0000 (21:47 +0100)
Methods createExtLocalconfCacheEntry() and createExtTablesCacheEntry()
attempt to include files without checking if they exist. This causes
PHP warnings about non-existing files and looses time in a call to
GeneralUtility::getUrl().

Change-Id: Icbee0c8e6e9e0ada1dc48ac471006b6dc59adc6d
Resolves: #46074
Releases: 6.0, 6.1
Reviewed-on: https://review.typo3.org/18757
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/sysext/core/Classes/Utility/ExtensionManagementUtility.php
typo3/sysext/core/Tests/Unit/Utility/ExtensionMangementUtilityTest.php

index f44ec52..44d1476 100644 (file)
@@ -1570,20 +1570,22 @@ tt_content.' . $key . $prefix . ' {
                $phpCodeToCache[] = '';
                // Iterate through loaded extensions and add ext_localconf content
                foreach ($extensionInformation as $extensionKey => $extensionDetails) {
-                       // Include a header per extension to make the cache file more readable
-                       $phpCodeToCache[] = '/**';
-                       $phpCodeToCache[] = ' * Extension: ' . $extensionKey;
-                       $phpCodeToCache[] = ' * File: ' . $extensionDetails['ext_localconf.php'];
-                       $phpCodeToCache[] = ' */';
-                       $phpCodeToCache[] = '';
-                       // Set $_EXTKEY and $_EXTCONF for this extension
-                       $phpCodeToCache[] = '$_EXTKEY = \'' . $extensionKey . '\';';
-                       $phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY];';
-                       $phpCodeToCache[] = '';
-                       // Add ext_localconf.php content of extension
-                       $phpCodeToCache[] = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($extensionDetails['ext_localconf.php']));
-                       $phpCodeToCache[] = '';
-                       $phpCodeToCache[] = '';
+                       if (isset($extensionDetails['ext_localconf.php']) && $extensionDetails['ext_localconf.php']) {
+                               // Include a header per extension to make the cache file more readable
+                               $phpCodeToCache[] = '/**';
+                               $phpCodeToCache[] = ' * Extension: ' . $extensionKey;
+                               $phpCodeToCache[] = ' * File: ' . $extensionDetails['ext_localconf.php'];
+                               $phpCodeToCache[] = ' */';
+                               $phpCodeToCache[] = '';
+                               // Set $_EXTKEY and $_EXTCONF for this extension
+                               $phpCodeToCache[] = '$_EXTKEY = \'' . $extensionKey . '\';';
+                               $phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY];';
+                               $phpCodeToCache[] = '';
+                               // Add ext_localconf.php content of extension
+                               $phpCodeToCache[] = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($extensionDetails['ext_localconf.php']));
+                               $phpCodeToCache[] = '';
+                               $phpCodeToCache[] = '';
+                       }
                }
                $phpCodeToCache = implode(LF, $phpCodeToCache);
                // Remove all start and ending php tags from content
@@ -1760,21 +1762,23 @@ tt_content.' . $key . $prefix . ' {
                $phpCodeToCache[] = '';
                // Iterate through loaded extensions and add ext_tables content
                foreach ($extensionInformation as $extensionKey => $extensionDetails) {
-                       // Include a header per extension to make the cache file more readable
-                       $phpCodeToCache[] = '/**';
-                       $phpCodeToCache[] = ' * Extension: ' . $extensionKey;
-                       $phpCodeToCache[] = ' * File: ' . $extensionDetails['ext_tables.php'];
-                       $phpCodeToCache[] = ' */';
-                       $phpCodeToCache[] = '';
-                       // Set $_EXTKEY and $_EXTCONF for this extension
-                       $phpCodeToCache[] = '$_EXTKEY = \'' . $extensionKey . '\';';
-                       $phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY];';
-                       $phpCodeToCache[] = '';
-                       // Add ext_tables.php content of extension
-                       $phpCodeToCache[] = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($extensionDetails['ext_tables.php']));
-                       $phpCodeToCache[] = '';
-                       $phpCodeToCache[] = '\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();';
-                       $phpCodeToCache[] = '';
+                       if (isset($extensionDetails['ext_tables.php']) && $extensionDetails['ext_tables.php']) {
+                               // Include a header per extension to make the cache file more readable
+                               $phpCodeToCache[] = '/**';
+                               $phpCodeToCache[] = ' * Extension: ' . $extensionKey;
+                               $phpCodeToCache[] = ' * File: ' . $extensionDetails['ext_tables.php'];
+                               $phpCodeToCache[] = ' */';
+                               $phpCodeToCache[] = '';
+                               // Set $_EXTKEY and $_EXTCONF for this extension
+                               $phpCodeToCache[] = '$_EXTKEY = \'' . $extensionKey . '\';';
+                               $phpCodeToCache[] = '$_EXTCONF = $GLOBALS[\'TYPO3_CONF_VARS\'][\'EXT\'][\'extConf\'][$_EXTKEY];';
+                               $phpCodeToCache[] = '';
+                               // Add ext_tables.php content of extension
+                               $phpCodeToCache[] = trim(\TYPO3\CMS\Core\Utility\GeneralUtility::getUrl($extensionDetails['ext_tables.php']));
+                               $phpCodeToCache[] = '';
+                               $phpCodeToCache[] = '\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::loadNewTcaColumnsConfigFiles();';
+                               $phpCodeToCache[] = '';
+                       }
                }
                $phpCodeToCache = implode(LF, $phpCodeToCache);
                // Remove all start and ending php tags from content
index c4bd277..8c57498 100644 (file)
@@ -758,11 +758,7 @@ class ExtensionManagementUtilityTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
                $extensionName = uniqid('foo');
                $extLocalconfLocation = PATH_site . 'typo3temp/' . uniqid('test_ext_localconf') . '.php';
                $this->testFilesToDelete[] = $extLocalconfLocation;
-               file_put_contents($extLocalconfLocation, '<?php
-
-throw new \RuntimeException(\'\', 1340559079);
-
-?>');
+               file_put_contents($extLocalconfLocation, "<?php\n\nthrow new RuntimeException('', 1340559079);\n\n?>");
                $GLOBALS['TYPO3_LOADED_EXT'] = array(
                        $extensionName => array(
                                'ext_localconf.php' => $extLocalconfLocation
@@ -782,11 +778,7 @@ throw new \RuntimeException(\'\', 1340559079);
                $extLocalconfLocation = PATH_site . 'typo3temp/' . uniqid('test_ext_localconf') . '.php';
                $this->testFilesToDelete[] = $extLocalconfLocation;
                $uniqueStringInLocalconf = uniqid('foo');
-               file_put_contents($extLocalconfLocation, '<?php
-
-' . $uniqueStringInLocalconf . '
-
-?>');
+               file_put_contents($extLocalconfLocation, "<?php\n\n" . $uniqueStringInLocalconf . "\n\n?>");
                $GLOBALS['TYPO3_LOADED_EXT'] = array(
                        $extensionName => array(
                                'ext_localconf.php' => $extLocalconfLocation
@@ -808,6 +800,29 @@ throw new \RuntimeException(\'\', 1340559079);
        /**
         * @test
         */
+       public function createExtLocalconfCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtLocalconfExists() {
+               $extensionName = uniqid('foo');
+               $GLOBALS['TYPO3_LOADED_EXT'] = array(
+                       $extensionName => array(),
+               );
+               $mockCache = $this->getMock(
+                       'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
+                       array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
+                       array(),
+                       '',
+                       FALSE
+               );
+               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCache->expects($this->once())
+                       ->method('set')
+                       ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
+               \TYPO3\CMS\Core\Utility\ExtensionManagementUtilityAccessibleProxy::createExtLocalconfCacheEntry();
+       }
+
+       /**
+        * @test
+        */
        public function createExtLocalconfCacheEntryWritesCacheEntryWithNoTags() {
                $mockCache = $this->getMock(
                        'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
@@ -977,11 +992,7 @@ throw new \RuntimeException(\'\', 1340559079);
                $extTablesLocation = PATH_site . 'typo3temp/' . uniqid('test_ext_tables') . '.php';
                $this->testFilesToDelete[] = $extTablesLocation;
                $uniqueStringInTables = uniqid('foo');
-               file_put_contents($extTablesLocation, '<?php
-
-' . $uniqueStringInTables . '
-
-?>');
+               file_put_contents($extTablesLocation, "<?php\n\n$uniqueStringInTables\n\n?>");
                $GLOBALS['TYPO3_LOADED_EXT'] = array(
                        $extensionName => array(
                                'ext_tables.php' => $extTablesLocation
@@ -1003,6 +1014,29 @@ throw new \RuntimeException(\'\', 1340559079);
        /**
         * @test
         */
+       public function createExtTablesCacheEntryWritesCacheEntryWithExtensionContentOnlyIfExtTablesExists() {
+               $extensionName = uniqid('foo');
+               $GLOBALS['TYPO3_LOADED_EXT'] = array(
+                       $extensionName => array(),
+               );
+               $mockCache = $this->getMock(
+                       'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',
+                       array('getIdentifier', 'set', 'get', 'getByTag', 'has', 'remove', 'flush', 'flushByTag', 'requireOnce'),
+                       array(),
+                       '',
+                       FALSE
+               );
+               $GLOBALS['typo3CacheManager'] = $this->getMock('TYPO3\\CMS\\Core\\Cache\\CacheManager', array('getCache'));
+               $GLOBALS['typo3CacheManager']->expects($this->any())->method('getCache')->will($this->returnValue($mockCache));
+               $mockCache->expects($this->once())
+                       ->method('set')
+                       ->with($this->anything(), $this->logicalNot($this->stringContains($extensionName)), $this->anything());
+               \TYPO3\CMS\Core\Utility\ExtensionManagementUtilityAccessibleProxy::createExtTablesCacheEntry();
+       }
+
+       /**
+        * @test
+        */
        public function createExtTablesCacheEntryWritesCacheEntryWithNoTags() {
                $mockCache = $this->getMock(
                        'TYPO3\\CMS\\Core\\Cache\\Frontend\\AbstractFrontend',