[TASK] Remove siteRelPath from TYPO3_LOADED_EXT 40/49140/3
authorBenni Mack <benni@typo3.org>
Wed, 20 Jul 2016 22:13:06 +0000 (00:13 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Sat, 23 Jul 2016 15:25:13 +0000 (17:25 +0200)
The siteRelPath information inside TYPO3_LOADED_EXT can
be fetched in uncritical situation (as it is used now) from extPath()
instead, thus removing one more option from the global array.

Resolves: #77183
Releases: master
Change-Id: I8fd77e8c29afe1fb435b3b8165483ea1e1d16091
Reviewed-on: https://review.typo3.org/49140
Tested-by: Bamboo TYPO3com <info@typo3.com>
Reviewed-by: Sascha Egerer <sascha@sascha-egerer.de>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/about/Classes/Domain/Repository/ExtensionRepository.php
typo3/sysext/core/Classes/Compatibility/LoadedExtensionArrayElement.php
typo3/sysext/documentation/Classes/Domain/Repository/DocumentRepository.php
typo3/sysext/documentation/Classes/Service/DocumentationService.php

index c3c7543..8d7ee75 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\About\Domain\Repository;
  * The TYPO3 project - inspiring people to share!
  */
 use TYPO3\CMS\About\Domain\Model\Extension;
+use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
 use TYPO3\CMS\Extbase\Persistence\Repository;
 
@@ -33,7 +34,7 @@ class ExtensionRepository extends Repository
         $loadedExtensionsArray = $GLOBALS['TYPO3_LOADED_EXT'];
         foreach ($loadedExtensionsArray as $extensionKey => $extension) {
             if ((is_array($extension) || $extension instanceof \ArrayAccess) && $extension['type'] !== 'S') {
-                $emconfPath = PATH_site . $extension['siteRelPath'] . 'ext_emconf.php';
+                $emconfPath = GeneralUtility::getFileAbsFileName('EXT:' . $extensionKey . '/ext_emconf.php');
                 if (file_exists($emconfPath)) {
                     include $emconfPath;
                     $extension = $this->objectManager->get(Extension::class);
index fded139..349c99c 100644 (file)
@@ -87,9 +87,8 @@ class LoadedExtensionArrayElement implements \IteratorAggregate, \ArrayAccess, \
                     $packageType = 'T';
                     break;
             }
-            if ($packageType !== null && $relativePackagePathToPathSite !== null) {
+            if ($packageType !== null) {
                 $this->extensionInformation['type'] = $packageType;
-                $this->extensionInformation['siteRelPath'] = $relativePackagePathToPathSite;
             }
         }
     }
index 1dbfef3..7594e7e 100644 (file)
@@ -14,7 +14,16 @@ namespace TYPO3\CMS\Documentation\Domain\Repository;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Core\Localization\Locales;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Core\Utility\PathUtility;
+use TYPO3\CMS\Documentation\Domain\Model\Document;
+use TYPO3\CMS\Documentation\Domain\Model\DocumentFormat;
+use TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation;
+use TYPO3\CMS\Documentation\Utility\MiscUtility;
+use TYPO3\CMS\Extbase\Object\ObjectManagerInterface;
+use TYPO3\CMS\Extbase\Persistence\ObjectStorage;
 
 /**
  * An extension helper repository to be used in ext:documentation context
@@ -29,7 +38,7 @@ class DocumentRepository
     /**
      * @param \TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager
      */
-    public function injectObjectManager(\TYPO3\CMS\Extbase\Object\ObjectManagerInterface $objectManager)
+    public function injectObjectManager(ObjectManagerInterface $objectManager)
     {
         $this->objectManager = $objectManager;
     }
@@ -67,7 +76,7 @@ class DocumentRepository
         // Initialize the dependency of languages
         $languageDependencies = array();
         /** @var $locales \TYPO3\CMS\Core\Localization\Locales */
-        $locales = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Localization\Locales::class);
+        $locales = GeneralUtility::makeInstance(Locales::class);
         // Language is found. Configure it:
         $shortLanguage = $language;
         if (!in_array($shortLanguage, $locales->getLocales()) && strpos($shortLanguage, '_') !== false) {
@@ -113,7 +122,7 @@ class DocumentRepository
                 }
             }
 
-            $newTranslations = new \TYPO3\CMS\Extbase\Persistence\ObjectStorage();
+            $newTranslations = new ObjectStorage();
             $document->setTranslations($newTranslations);
             if ($selectedTranslation !== null) {
                 $document->addTranslation($selectedTranslation);
@@ -140,10 +149,10 @@ class DocumentRepository
         }
 
         foreach ($documentKeys as $documentKey) {
-            $icon = \TYPO3\CMS\Documentation\Utility\MiscUtility::getIcon($documentKey);
+            $icon = MiscUtility::getIcon($documentKey);
 
             /** @var \TYPO3\CMS\Documentation\Domain\Model\Document $document */
-            $document = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\Document::class)
+            $document = $this->objectManager->get(Document::class)
                 ->setPackageKey($documentKey)
                 ->setIcon($icon);
 
@@ -156,7 +165,7 @@ class DocumentRepository
                 }
 
                 /** @var \TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation */
-                $documentTranslation = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation::class)
+                $documentTranslation = $this->objectManager->get(DocumentTranslation::class)
                     ->setLanguage($language)
                     ->setTitle($metadata['title'])
                     ->setDescription($metadata['description']);
@@ -186,7 +195,7 @@ class DocumentRepository
                     }
                     if (!empty($documentFile)) {
                         /** @var \TYPO3\CMS\Documentation\Domain\Model\DocumentFormat $documentFormat */
-                        $documentFormat = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\DocumentFormat::class)
+                        $documentFormat = $this->objectManager->get(DocumentFormat::class)
                             ->setFormat($format)
                             ->setPath($formatPath . $format . '/' . $documentFile);
 
@@ -214,29 +223,29 @@ class DocumentRepository
         $documents = array();
         $language = 'default';
 
-        foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extensionKey => $extensionData) {
-            $path = $extensionData['siteRelPath'] . 'doc/';
-            if (is_file(PATH_site . $path . 'manual.sxw')) {
+        foreach (array_keys($GLOBALS['TYPO3_LOADED_EXT']) as $extensionKey) {
+            $path = GeneralUtility::getFileAbsFileName('EXT:' . $extensionKey . '/doc/');
+            if (is_file($path . 'manual.sxw')) {
                 $documentKey = 'typo3cms.extensions.' . $extensionKey;
-                $icon = \TYPO3\CMS\Documentation\Utility\MiscUtility::getIcon($documentKey);
+                $icon = MiscUtility::getIcon($documentKey);
 
                 /** @var \TYPO3\CMS\Documentation\Domain\Model\Document $document */
-                $document = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\Document::class)
+                $document = $this->objectManager->get(Document::class)
                     ->setPackageKey($documentKey)
                     ->setExtensionKey($extensionKey)
                     ->setIcon($icon);
 
                 $metadata = $this->getMetadata($documentKey, $language);
                 /** @var \TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation $documentTranslation */
-                $documentTranslation = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\DocumentTranslation::class)
+                $documentTranslation = $this->objectManager->get(DocumentTranslation::class)
                     ->setLanguage($language)
                     ->setTitle($metadata['title'])
                     ->setDescription($metadata['description']);
 
                 /** @var \TYPO3\CMS\Documentation\Domain\Model\DocumentFormat $documentFormat */
-                $documentFormat = $this->objectManager->get(\TYPO3\CMS\Documentation\Domain\Model\DocumentFormat::class)
+                $documentFormat = $this->objectManager->get(DocumentFormat::class)
                     ->setFormat('sxw')
-                    ->setPath($path . 'manual.sxw');
+                    ->setPath(PathUtility::stripPathSitePrefix($path . 'manual.sxw'));
 
                 $documentTranslation->addFormat($documentFormat);
                 $document->addTranslation($documentTranslation);
@@ -263,8 +272,8 @@ class DocumentRepository
         );
         if (GeneralUtility::isFirstPartOfStr($documentKey, 'typo3cms.extensions.')) {
             $extensionKey = substr($documentKey, 20);
-            if (\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded($extensionKey)) {
-                $metadata = \TYPO3\CMS\Documentation\Utility\MiscUtility::getExtensionMetaData($extensionKey);
+            if (ExtensionManagementUtility::isLoaded($extensionKey)) {
+                $metadata = MiscUtility::getExtensionMetaData($extensionKey);
             }
         } elseif (is_file($documentPath . 'composer.json')) {
             $info = json_decode(file_get_contents($documentPath . 'composer.json'), true);
index 44b1eb2..3b8fe81 100644 (file)
@@ -15,7 +15,11 @@ namespace TYPO3\CMS\Documentation\Service;
  */
 
 use TYPO3\CMS\Core\Http\RequestFactory;
+use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
 use TYPO3\CMS\Core\Utility\GeneralUtility;
+use TYPO3\CMS\Documentation\Exception\Document;
+use TYPO3\CMS\Documentation\Utility\MiscUtility;
+use TYPO3\CMS\Lang\Exception\XmlParser;
 
 /**
  * Service class to connect to docs.typo3.org.
@@ -35,7 +39,7 @@ class DocumentationService
         if ($json) {
             $documents = json_decode($json, true);
             foreach ($documents as &$document) {
-                $document['icon'] = \TYPO3\CMS\Documentation\Utility\MiscUtility::getIcon($document['key']);
+                $document['icon'] = MiscUtility::getIcon($document['key']);
             }
 
             // Cache file locally to be able to create a composer.json file when fetching a document
@@ -55,9 +59,9 @@ class DocumentationService
         $documents = array();
 
         foreach ($GLOBALS['TYPO3_LOADED_EXT'] as $extensionKey => $extensionData) {
-            $absoluteExtensionPath = GeneralUtility::getFileAbsFileName($extensionData['siteRelPath']);
+            $absoluteExtensionPath = ExtensionManagementUtility::extPath($extensionKey);
             if (is_file($absoluteExtensionPath . 'README.rst') || is_file($absoluteExtensionPath . 'Documentation' . DIRECTORY_SEPARATOR . 'Index.rst')) {
-                $metadata = \TYPO3\CMS\Documentation\Utility\MiscUtility::getExtensionMetaData($extensionKey);
+                $metadata = MiscUtility::getExtensionMetaData($extensionKey);
                 if ($extensionData['type'] === 'S') {
                     $version = TYPO3_branch;
                 } else {
@@ -67,7 +71,7 @@ class DocumentationService
                 $documentKey = 'typo3cms.extensions.' . $extensionKey;
                 $documents[] = array(
                     'title'   => $metadata['title'],
-                    'icon'    => \TYPO3\CMS\Documentation\Utility\MiscUtility::getIcon($documentKey),
+                    'icon'    => MiscUtility::getIcon($documentKey),
                     'type'    => 'Extension',
                     'key'     => $documentKey,
                     'shortcut' => $extensionKey,
@@ -241,7 +245,7 @@ class DocumentationService
      * Parses content of packages.xml into a suitable array.
      *
      * @param string $string: XML data to parse
-     * @throws \TYPO3\CMS\Documentation\Exception\XmlParser
+     * @throws XmlParser
      * @return array Array representation of XML data
      */
     protected function parsePackagesXML($string)
@@ -251,7 +255,7 @@ class DocumentationService
         $data = json_decode(json_encode((array)simplexml_load_string($string)), true);
         libxml_disable_entity_loader($previousValueOfEntityLoader);
         if (count($data) !== 2) {
-            throw new \TYPO3\CMS\Documentation\Exception\XmlParser('Error in XML parser while decoding packages XML file.', 1374222437);
+            throw new XmlParser('Error in XML parser while decoding packages XML file.', 1374222437);
         }
 
         // SimpleXML does not properly handle arrays with only 1 item
@@ -299,21 +303,22 @@ class DocumentationService
                         $absoluteTargetPath = GeneralUtility::getFileAbsFileName($path . implode('/', $zipEntryPathSegments) . '/' . $fileName);
                         if (trim($absoluteTargetPath) !== '') {
                             $return = GeneralUtility::writeFile(
-                                $absoluteTargetPath, zip_entry_read($zipEntry, zip_entry_filesize($zipEntry))
+                                $absoluteTargetPath,
+                                zip_entry_read($zipEntry, zip_entry_filesize($zipEntry))
                             );
                             if ($return === false) {
-                                throw new \TYPO3\CMS\Documentation\Exception\Document('Could not write file ' . $zipEntryName, 1374161546);
+                                throw new Document('Could not write file ' . $zipEntryName, 1374161546);
                             }
                         } else {
-                            throw new \TYPO3\CMS\Documentation\Exception\Document('Could not write file ' . $zipEntryName, 1374161532);
+                            throw new Document('Could not write file ' . $zipEntryName, 1374161532);
                         }
                     }
                 } else {
-                    throw new \TYPO3\CMS\Documentation\Exception\Document('Extension directory missing in zip file!', 1374161519);
+                    throw new Document('Extension directory missing in zip file!', 1374161519);
                 }
             }
         } else {
-            throw new \TYPO3\CMS\Documentation\Exception\Document('Unable to open zip file ' . $file, 1374161508);
+            throw new Document('Unable to open zip file ' . $file, 1374161508);
         }
 
         return $result;