[TASK] Use Environment API instead of PATH_site in em 38/57238/3
authorChristian Kuhn <lolli@schwarzbu.ch>
Fri, 15 Jun 2018 16:07:38 +0000 (18:07 +0200)
committerBenni Mack <benni@typo3.org>
Fri, 15 Jun 2018 19:21:34 +0000 (21:21 +0200)
Resolves: #85281
Releases: master
Change-Id: I8313d9f9b564d8f6ab0f9a91ebbe93aa9c337e31
Reviewed-on: https://review.typo3.org/57238
Reviewed-by: Jan Helke <typo3@helke.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Tested-by: Jan Helke <typo3@helke.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/extensionmanager/Classes/Utility/EmConfUtility.php
typo3/sysext/extensionmanager/Classes/Utility/FileHandlingUtility.php
typo3/sysext/extensionmanager/Classes/Utility/InstallUtility.php
typo3/sysext/extensionmanager/Classes/Utility/ListUtility.php
typo3/sysext/extensionmanager/Classes/ViewHelpers/ReloadSqlDataViewHelper.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/FileHandlingUtilityTest.php
typo3/sysext/extensionmanager/Tests/Unit/Utility/InstallUtilityTest.php

index 4b6295f..4815f23 100644 (file)
@@ -14,10 +14,13 @@ namespace TYPO3\CMS\Extensionmanager\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
+use TYPO3\CMS\Core\SingletonInterface;
+
 /**
  * Utility for dealing with ext_emconf
  */
-class EmConfUtility implements \TYPO3\CMS\Core\SingletonInterface
+class EmConfUtility implements SingletonInterface
 {
     /**
      * Returns the $EM_CONF array from an extensions ext_emconf.php file
@@ -28,7 +31,7 @@ class EmConfUtility implements \TYPO3\CMS\Core\SingletonInterface
     public function includeEmConf(array $extension)
     {
         $_EXTKEY = $extension['key'];
-        $path = PATH_site . $extension['siteRelPath'] . 'ext_emconf.php';
+        $path = Environment::getPublicPath() . '/' . $extension['siteRelPath'] . 'ext_emconf.php';
         $EM_CONF = null;
         if (file_exists($path)) {
             include $path;
index 38ca3f3..7e6650a 100644 (file)
@@ -357,7 +357,7 @@ class FileHandlingUtility implements \TYPO3\CMS\Core\SingletonInterface
      */
     protected function getAbsolutePath($relativePath)
     {
-        $absolutePath = GeneralUtility::getFileAbsFileName(GeneralUtility::resolveBackPath(PATH_site . $relativePath));
+        $absolutePath = GeneralUtility::getFileAbsFileName(GeneralUtility::resolveBackPath(Environment::getPublicPath() . '/' . $relativePath));
         if (empty($absolutePath)) {
             throw new ExtensionManagerException('Illegal relative path given', 1350742864);
         }
index b176edc..b94c742 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Extensionmanager\Utility;
  */
 
 use TYPO3\CMS\Core\Configuration\ExtensionConfiguration;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Database\Schema\SchemaMigrator;
 use TYPO3\CMS\Core\Database\Schema\SqlReader;
 use TYPO3\CMS\Core\Service\OpcodeCacheService;
@@ -353,7 +354,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
      */
     public function processDatabaseUpdates(array $extension)
     {
-        $extTablesSqlFile = PATH_site . $extension['siteRelPath'] . 'ext_tables.sql';
+        $extTablesSqlFile = Environment::getPublicPath() . '/' . $extension['siteRelPath'] . 'ext_tables.sql';
         $extTablesSqlContent = '';
         if (file_exists($extTablesSqlFile)) {
             $extTablesSqlContent .= file_get_contents($extTablesSqlFile);
@@ -564,7 +565,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
             $extensionSiteRelPath . 'Initialisation/data.xml'
         ];
         foreach ($possibleImportFiles as $possibleImportFile) {
-            if (!file_exists(PATH_site . $possibleImportFile)) {
+            if (!file_exists(Environment::getPublicPath() . '/' . $possibleImportFile)) {
                 continue;
             }
             $importFileToUse = $possibleImportFile;
@@ -573,7 +574,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
             /** @var ImportExportUtility $importExportUtility */
             $importExportUtility = $this->objectManager->get(ImportExportUtility::class);
             try {
-                $importResult = $importExportUtility->importT3DFile(PATH_site . $importFileToUse, 0);
+                $importResult = $importExportUtility->importT3DFile(Environment::getPublicPath() . '/' . $importFileToUse, 0);
                 $this->registry->set('extensionDataImport', $extensionSiteRelPath . 'Initialisation/dataImported', 1);
                 $this->emitAfterExtensionT3DImportSignal($importFileToUse, $importResult);
             } catch (\ErrorException $e) {
@@ -605,7 +606,7 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
     {
         $extTablesStaticSqlRelFile = $extensionSiteRelPath . 'ext_tables_static+adt.sql';
         if (!$this->registry->get('extensionDataImport', $extTablesStaticSqlRelFile)) {
-            $extTablesStaticSqlFile = PATH_site . $extTablesStaticSqlRelFile;
+            $extTablesStaticSqlFile = Environment::getPublicPath() . '/' . $extTablesStaticSqlRelFile;
             $shortFileHash = '';
             if (file_exists($extTablesStaticSqlFile)) {
                 $extTablesStaticSqlContent = file_get_contents($extTablesStaticSqlFile);
@@ -638,10 +639,10 @@ class InstallUtility implements \TYPO3\CMS\Core\SingletonInterface
     {
         $importRelFolder = $extensionSiteRelPath . 'Initialisation/Files';
         if (!$this->registry->get('extensionDataImport', $importRelFolder)) {
-            $importFolder = PATH_site . $importRelFolder;
+            $importFolder = Environment::getPublicPath() . '/' . $importRelFolder;
             if (file_exists($importFolder)) {
                 $destinationRelPath = $GLOBALS['TYPO3_CONF_VARS']['BE']['fileadminDir'] . $extensionKey;
-                $destinationAbsolutePath = PATH_site . $destinationRelPath;
+                $destinationAbsolutePath = Environment::getPublicPath() . '/' . $destinationRelPath;
                 if (!file_exists($destinationAbsolutePath) &&
                     GeneralUtility::isAllowedAbsPath($destinationAbsolutePath)
                 ) {
index e487f5e..112548b 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Extensionmanager\Utility;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Package\PackageInterface;
 use TYPO3\CMS\Core\Type\File\ImageInfo;
 use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
@@ -114,7 +115,7 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface
             foreach ($this->packageManager->getAvailablePackages() as $package) {
                 $installationType = $this->getInstallTypeForPackage($package);
                 $this->availableExtensions[$package->getPackageKey()] = [
-                    'siteRelPath' => str_replace(PATH_site, '', $package->getPackagePath()),
+                    'siteRelPath' => str_replace(Environment::getPublicPath() . '/', '', $package->getPackagePath()),
                     'type' => $installationType,
                     'key' => $package->getPackageKey(),
                     'ext_icon' => ExtensionManagementUtility::getExtensionIcon($package->getPackagePath()),
@@ -269,7 +270,7 @@ class ListUtility implements \TYPO3\CMS\Core\SingletonInterface
     public function enrichExtensionsWithIconInformation(array $extensions)
     {
         foreach ($extensions as &$properties) {
-            $extIconPath = PATH_site . $properties['siteRelPath'] . $properties['ext_icon'];
+            $extIconPath = Environment::getPublicPath() . '/' . $properties['siteRelPath'] . $properties['ext_icon'];
             $imageInfo = GeneralUtility::makeInstance(ImageInfo::class, $extIconPath);
             $properties['ext_icon_width'] = $imageInfo->getWidth();
             $properties['ext_icon_height'] = $imageInfo->getHeight();
index 279a7d1..227bf03 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Extensionmanager\ViewHelpers;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Imaging\Icon;
 use TYPO3\CMS\Core\Imaging\IconFactory;
 use TYPO3\CMS\Core\Registry;
@@ -48,7 +49,7 @@ class ReloadSqlDataViewHelper extends ActionViewHelper
         $iconFactory = GeneralUtility::makeInstance(IconFactory::class);
 
         $staticSqlDataFile = $extension['siteRelPath'] . 'ext_tables_static+adt.sql';
-        if (!file_exists(PATH_site . $staticSqlDataFile)) {
+        if (!file_exists(Environment::getPublicPath() . '/' . $staticSqlDataFile)) {
             return '<span class="btn btn-default disabled">' . $iconFactory->getIcon('empty-empty', Icon::SIZE_SMALL)->render() . '</span>';
         }
 
@@ -59,7 +60,7 @@ class ReloadSqlDataViewHelper extends ActionViewHelper
         // We used to only store "1" in the database when data was imported
         // No need to compare file content here and just show the reload icon
         if (!empty($oldMd5Hash) && $oldMd5Hash !== 1) {
-            $currentMd5Hash = md5_file(PATH_site . $staticSqlDataFile);
+            $currentMd5Hash = md5_file(Environment::getPublicPath() . '/' . $staticSqlDataFile);
             $md5HashIsEqual = $oldMd5Hash === $currentMd5Hash;
         }
 
index e45c2f2..79ff414 100644 (file)
@@ -42,7 +42,7 @@ class FileHandlingUtilityTest extends UnitTestCase
     protected function createFakeExtension($extkeyOnly = false)
     {
         $extKey = strtolower($this->getUniqueId('testing'));
-        $absExtPath = PATH_site . 'typo3temp/var/tests/ext-' . $extKey . '/';
+        $absExtPath = Environment::getVarPath() . '/tests/ext-' . $extKey . '/';
         $relPath = 'typo3temp/var/tests/ext-' . $extKey . '/';
         $this->fakedExtensions[$extKey] = [
             'siteRelPath' => $relPath,
@@ -52,7 +52,7 @@ class FileHandlingUtilityTest extends UnitTestCase
             return $extKey;
         }
         GeneralUtility::mkdir($absExtPath);
-        $this->testFilesToDelete[] = PATH_site . 'typo3temp/var/tests/ext-' . $extKey;
+        $this->testFilesToDelete[] = Environment::getVarPath() . '/tests/ext-' . $extKey;
         return $extKey;
     }
 
@@ -65,10 +65,10 @@ class FileHandlingUtilityTest extends UnitTestCase
         $fileHandlerMock = $this->getAccessibleMock(FileHandlingUtility::class, ['removeDirectory', 'addDirectory', 'getExtensionDir'], [], '', false);
         $fileHandlerMock->expects($this->once())
             ->method('removeDirectory')
-            ->with(PATH_site . 'typo3temp/var/tests/ext-' . $extKey . '/');
+            ->with(Environment::getVarPath() . '/tests/ext-' . $extKey . '/');
         $fileHandlerMock->expects($this->any())
             ->method('getExtensionDir')
-            ->willReturn(PATH_site . 'typo3temp/var/tests/ext-' . $extKey . '/');
+            ->willReturn(Environment::getVarPath() . '/tests/ext-' . $extKey . '/');
         $fileHandlerMock->_call('makeAndClearExtensionDir', $extKey);
     }
 
@@ -104,8 +104,8 @@ class FileHandlingUtilityTest extends UnitTestCase
     public function validRelativePathDataProvider()
     {
         return [
-            ['foo/../bar', PATH_site . 'bar'],
-            ['bas', PATH_site . 'bas'],
+            ['foo/../bar', Environment::getPublicPath() . '/bar'],
+            ['bas', Environment::getPublicPath() . '/bas'],
         ];
     }
 
@@ -130,10 +130,10 @@ class FileHandlingUtilityTest extends UnitTestCase
         $fileHandlerMock = $this->getAccessibleMock(FileHandlingUtility::class, ['removeDirectory', 'addDirectory', 'getExtensionDir']);
         $fileHandlerMock->expects($this->once())
             ->method('addDirectory')
-            ->with(PATH_site . 'typo3temp/var/tests/ext-' . $extKey . '/');
+            ->with(Environment::getVarPath() . '/tests/ext-' . $extKey . '/');
         $fileHandlerMock->expects($this->any())
             ->method('getExtensionDir')
-            ->willReturn(PATH_site . 'typo3temp/var/tests/ext-' . $extKey . '/');
+            ->willReturn(Environment::getVarPath() . '/tests/ext-' . $extKey . '/');
         $fileHandlerMock->_call('makeAndClearExtensionDir', $extKey);
     }
 
@@ -155,7 +155,7 @@ class FileHandlingUtilityTest extends UnitTestCase
      */
     public function addDirectoryAddsDirectory()
     {
-        $extDirPath = PATH_site . '/typo3temp/var/tests/' . $this->getUniqueId('test-extensions-');
+        $extDirPath = Environment::getVarPath() . '/tests/' . $this->getUniqueId('test-extensions-');
         $this->testFilesToDelete[] = $extDirPath;
         $fileHandlerMock = $this->getAccessibleMock(FileHandlingUtility::class, ['dummy']);
         $fileHandlerMock->_call('addDirectory', $extDirPath);
@@ -167,7 +167,7 @@ class FileHandlingUtilityTest extends UnitTestCase
      */
     public function removeDirectoryRemovesDirectory()
     {
-        $extDirPath = PATH_site . '/typo3temp/var/tests/' . $this->getUniqueId('test-extensions-');
+        $extDirPath = Environment::getVarPath() . '/tests/' . $this->getUniqueId('test-extensions-');
         @mkdir($extDirPath);
         $fileHandlerMock = $this->getAccessibleMock(FileHandlingUtility::class, ['dummy']);
         $fileHandlerMock->_call('removeDirectory', $extDirPath);
@@ -179,8 +179,8 @@ class FileHandlingUtilityTest extends UnitTestCase
      */
     public function removeDirectoryRemovesSymlink()
     {
-        $absoluteSymlinkPath = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('test_symlink_');
-        $absoluteFilePath = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('test_file_');
+        $absoluteSymlinkPath = Environment::getVarPath() . '/tests/' . $this->getUniqueId('test_symlink_');
+        $absoluteFilePath = Environment::getVarPath() . '/tests/' . $this->getUniqueId('test_file_');
         touch($absoluteFilePath);
         $this->testFilesToDelete[] = $absoluteFilePath;
         symlink($absoluteFilePath, $absoluteSymlinkPath);
@@ -194,8 +194,8 @@ class FileHandlingUtilityTest extends UnitTestCase
      */
     public function removeDirectoryDoesNotRemoveContentOfSymlinkedTargetDirectory()
     {
-        $absoluteSymlinkPath = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('test_symlink_');
-        $absoluteDirectoryPath = PATH_site . 'typo3temp/var/tests/' . $this->getUniqueId('test_dir_') . '/';
+        $absoluteSymlinkPath = Environment::getVarPath() . '/tests/' . $this->getUniqueId('test_symlink_');
+        $absoluteDirectoryPath = Environment::getVarPath() . '/tests/' . $this->getUniqueId('test_dir_') . '/';
         $relativeFilePath = $this->getUniqueId('test_file_');
 
         mkdir($absoluteDirectoryPath);
index 0aa6278..2c5fab9 100644 (file)
@@ -16,6 +16,7 @@ namespace TYPO3\CMS\Extensionmanager\Tests\Unit\Utility;
  */
 
 use TYPO3\CMS\Core\Cache\CacheManager;
+use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\Registry;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extensionmanager\Utility\DependencyUtility;
@@ -101,7 +102,7 @@ class InstallUtilityTest extends UnitTestCase
     protected function tearDown()
     {
         foreach ($this->fakedExtensions as $fakeExtkey => $fakeExtension) {
-            $this->testFilesToDelete[] = PATH_site . 'typo3temp/var/tests/' . $fakeExtkey;
+            $this->testFilesToDelete[] = Environment::getVarPath() . '/tests/' . $fakeExtkey;
         }
         parent::tearDown();
     }
@@ -115,7 +116,7 @@ class InstallUtilityTest extends UnitTestCase
     protected function createFakeExtension(): string
     {
         $extKey = strtolower($this->getUniqueId('testing'));
-        $absExtPath = PATH_site . 'typo3temp/var/tests/' . $extKey;
+        $absExtPath = Environment::getVarPath() . '/tests/' . $extKey;
         $relPath = 'typo3temp/var/tests/' . $extKey . '/';
         GeneralUtility::mkdir($absExtPath);
         $this->fakedExtensions[$extKey] = [
@@ -226,7 +227,7 @@ class InstallUtilityTest extends UnitTestCase
     public function processDatabaseUpdatesCallsUpdateDbWithExtTablesSql()
     {
         $extKey = $this->createFakeExtension();
-        $extPath = PATH_site . 'typo3temp/var/tests/' . $extKey . '/';
+        $extPath = Environment::getVarPath() . '/tests/' . $extKey . '/';
         $extTablesFile = $extPath . 'ext_tables.sql';
         $fileContent = 'DUMMY TEXT TO COMPARE';
         file_put_contents($extTablesFile, $fileContent);
@@ -287,7 +288,7 @@ class InstallUtilityTest extends UnitTestCase
     public function processDatabaseUpdatesCallsImportFile($fileName)
     {
         $extKey = $this->createFakeExtension();
-        $absPath = PATH_site . $this->fakedExtensions[$extKey]['siteRelPath'];
+        $absPath = Environment::getPublicPath() . '/' . $this->fakedExtensions[$extKey]['siteRelPath'];
         GeneralUtility::mkdir($absPath . '/Initialisation');
         file_put_contents($absPath . '/Initialisation/' . $fileName, 'DUMMY');
         $installMock = $this->getAccessibleMock(
@@ -342,7 +343,7 @@ class InstallUtilityTest extends UnitTestCase
     public function importT3DFileDoesNotImportFileIfAlreadyImported($fileName, $registryNameReturnsFalse, $registryNameReturnsTrue)
     {
         $extKey = $this->createFakeExtension();
-        $absPath = PATH_site . $this->fakedExtensions[$extKey]['siteRelPath'];
+        $absPath = Environment::getPublicPath() . '/' . $this->fakedExtensions[$extKey]['siteRelPath'];
         GeneralUtility::mkdir($absPath . 'Initialisation');
         file_put_contents($absPath . 'Initialisation/' . $fileName, 'DUMMY');
         $registryMock = $this->getMockBuilder(Registry::class)