[TASK] Remove composerName info from PackageStates 87/46387/4
authorBenni Mack <benni@typo3.org>
Sat, 30 Jan 2016 10:32:46 +0000 (11:32 +0100)
committerHelmut Hummel <helmut.hummel@typo3.org>
Sat, 30 Jan 2016 16:45:31 +0000 (17:45 +0100)
The PackageStates.php includes an info about the "composerName"
which is only necessary when dealing with dependencies.

Instead of storing this info inside PackageStates.php, this can be put
and regenerated in the Core Cache functionality.

Resolves: #73025
Releases: master
Change-Id: I63fc863cef06b40a48d7d89104d3d9d7c27e7d08
Reviewed-on: https://review.typo3.org/46387
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Daniel Maier <dani-maier@gmx.de>
Tested-by: Daniel Maier <dani-maier@gmx.de>
Reviewed-by: Helmut Hummel <helmut.hummel@typo3.org>
Tested-by: Helmut Hummel <helmut.hummel@typo3.org>
typo3/sysext/core/Classes/Package/PackageManager.php
typo3/sysext/core/Tests/Unit/Package/PackageManagerTest.php

index bdeca7b..5bd2670 100644 (file)
@@ -177,6 +177,7 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
                 'packageAliasMap' => $this->packageAliasMap,
                 'activePackageKeys' => array_keys($this->activePackages),
                 'loadedExtArray' => $GLOBALS['TYPO3_LOADED_EXT'],
+                'composerNameToPackageKeyMap' => $this->composerNameToPackageKeyMap,
                 'packageObjectsCacheEntryIdentifier' => $packageObjectsCacheEntryIdentifier
             );
             $this->coreCache->set($packageObjectsCacheEntryIdentifier, serialize($this->packages));
@@ -200,6 +201,7 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
         }
         $this->packageStatesConfiguration = $packageCache['packageStatesConfiguration'];
         $this->packageAliasMap = $packageCache['packageAliasMap'];
+        $this->composerNameToPackageKeyMap = $packageCache['composerNameToPackageKeyMap'];
         $GLOBALS['TYPO3_LOADED_EXT'] = $packageCache['loadedExtArray'];
         $GLOBALS['TYPO3_currentPackageManager'] = $this;
         // Strip off PHP Tags from Php Cache Frontend
@@ -297,7 +299,6 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
                 $composerManifest = $this->getComposerManifest($packagePath);
                 $packageKey = $this->getPackageKeyFromManifest($composerManifest, $packagePath);
                 $this->composerNameToPackageKeyMap[strtolower($composerManifest->name)] = $packageKey;
-                $this->packageStatesConfiguration['packages'][$packageKey]['composerName'] = $composerManifest->name;
             } catch (Exception\MissingPackageManifestException $exception) {
                 if (!$this->isPackageKeyValid($packageKey)) {
                     continue;
@@ -465,16 +466,12 @@ class PackageManager implements \TYPO3\CMS\Core\SingletonInterface
         if (isset($this->packageAliasMap[$composerName])) {
             return $this->packageAliasMap[$composerName];
         }
-        if (empty($this->composerNameToPackageKeyMap)) {
-            foreach ($this->packageStatesConfiguration['packages'] as $packageKey => $packageStateConfiguration) {
-                $this->composerNameToPackageKeyMap[strtolower($packageStateConfiguration['composerName'])] = $packageKey;
-            }
-        }
         $lowercasedComposerName = strtolower($composerName);
-        if (!isset($this->composerNameToPackageKeyMap[$lowercasedComposerName])) {
+        if (isset($this->composerNameToPackageKeyMap[$lowercasedComposerName])) {
+            return $this->composerNameToPackageKeyMap[$lowercasedComposerName];
+        } else {
             return $composerName;
         }
-        return $this->composerNameToPackageKeyMap[$lowercasedComposerName];
     }
 
     /**
index ce21542..24ad296 100644 (file)
@@ -223,8 +223,7 @@ class PackageManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
         foreach ($packageKeys as $packageKey) {
             $expectedPackageStatesConfiguration[$packageKey] = array(
                 'state' => 'inactive',
-                'packagePath' => 'Application/' . $packageKey . '/',
-                'composerName' => $packageKey,
+                'packagePath' => 'Application/' . $packageKey . '/'
             );
         }
 
@@ -342,19 +341,20 @@ class PackageManagerTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function getPackageKeyFromComposerNameIgnoresCaseDifferences($composerName, $packageKey)
     {
-        $packageStatesConfiguration = array('packages' =>
-            array(
-                'TYPO3.CMS' => array(
-                    'composerName' => 'typo3/cms'
-                ),
-                'imagine.Imagine' => array(
-                    'composerName' => 'imagine/Imagine'
-                )
-            )
-        );
+        $packageStatesConfiguration = [
+            'packages' => [
+                'TYPO3.CMS',
+                'imagine.Imagine'
+            ]
+        ];
+        $composerNameToPackageKeyMap = [
+            'typo3/cms' => 'TYPO3.CMS',
+            'imagine/imagine' => 'imagine.Imagine'
+        ];
 
         $packageManager = $this->getAccessibleMock(PackageManager::class, array('resolvePackageDependencies'));
         $packageManager->_set('packageStatesConfiguration', $packageStatesConfiguration);
+        $packageManager->_set('composerNameToPackageKeyMap', $composerNameToPackageKeyMap);
 
         $this->assertEquals($packageKey, $packageManager->_call('getPackageKeyFromComposerName', $composerName));
     }