[TASK] Optimize Package State Migration 48/25648/5
authorThomas Maroschik <tmaroschik@dfau.de>
Fri, 22 Nov 2013 16:48:22 +0000 (17:48 +0100)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Wed, 18 Dec 2013 21:29:33 +0000 (22:29 +0100)
Under certain circumstances the Failsafe Package Manager
could interfer with the Update Package Manager in the Install Tool.

In order to reduce this friction the migration logic is integrated
into the migration step.

Resolves: #53886
Releases: 6.2
Change-Id: I0300b9c74736262b03f9f9b59a49576b7edf5b2f
Reviewed-on: https://review.typo3.org/25648
Reviewed-by: Markus Klein
Reviewed-by: Thomas Maroschik
Reviewed-by: Stefan Neufeind
Tested-by: Stefan Neufeind
typo3/sysext/core/Classes/Package/FailsafePackageManager.php
typo3/sysext/install/Classes/Controller/StepController.php
typo3/sysext/install/Classes/Updates/UpdatePackageManager.php [deleted file]

index c52a079..664ceb7 100644 (file)
@@ -92,4 +92,12 @@ class FailsafePackageManager extends \TYPO3\CMS\Core\Package\PackageManager {
                        parent::sortAndSavePackageStates();
                }
        }
+
+       /**
+        * To enable writing of the package states file the package states
+        * migration needs to override eventual failsafe blocks.
+        */
+       public function forceSortAndSavePackageStates() {
+               parent::sortAndSavePackageStates();
+       }
 }
\ No newline at end of file
index e2b9cfa..0bd53f1 100644 (file)
@@ -274,9 +274,41 @@ class StepController extends AbstractController {
                        if (!is_dir(PATH_typo3conf) || (is_dir(PATH_typo3conf) && !$localConfigurationFileExists) || file_exists(PATH_typo3conf . 'PackageStates.php')) {
                                return;
                        }
-                       $bootstrap = \TYPO3\CMS\Core\Core\Bootstrap::getInstance();
-                       $packageManager = new \TYPO3\CMS\Install\Updates\UpdatePackageManager($bootstrap->getEarlyInstance('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager'));
-                       $packageManager->createPackageStatesFile($bootstrap, PATH_site, PATH_typo3conf . 'PackageStates.php');
+                       $loadedExtensions = array();
+                       try {
+                               // Extensions in extListArray
+                               $loadedExtensions = $configurationManager->getLocalConfigurationValueByPath('EXT/extListArray');
+                       } catch (\RuntimeException $exception) {
+                               // Fallback handling if extlist is still a string and not an array
+                               // @deprecated since 6.2, will be removed two versions later without a substitute
+                               try {
+                                       $loadedExtensions = GeneralUtility::trimExplode(',', $configurationManager->getLocalConfigurationValueByPath('EXT/extList'));
+                               } catch (\RuntimeException $exception) {
+                               }
+                       }
+                       /** @var \TYPO3\CMS\Core\Package\FailsafePackageManager $packageManager */
+                       $packageManager = \TYPO3\CMS\Core\Core\Bootstrap::getInstance()->getEarlyInstance('TYPO3\\Flow\\Package\\PackageManager');
+                       foreach ($loadedExtensions as $loadedExtension) {
+                               try {
+                                       $packageManager->activatePackage($loadedExtension);
+                               } catch (\TYPO3\Flow\Package\Exception\UnknownPackageException $exception) {
+                                       // Skip unavailable packages silently
+                               }
+                       }
+                       $packageManager->forceSortAndSavePackageStates();
+
+                       // Backup LocalConfiguration.php
+                       copy(
+                               $configurationManager->getLocalConfigurationFileLocation(),
+                               preg_replace('/\.php$/', '.beforePackageStatesMigration.php', $configurationManager->getLocalConfigurationFileLocation())
+                       );
+                       $configurationManager->updateLocalConfiguration(array(
+                               'EXT' => array(
+                                       'extListArray' => '__UNSET',
+                                       'extList' => '__UNSET',
+                                       'requiredExt' => '__UNSET',
+                               ),
+                       ));
 
                        // Perform a reload to self, so bootstrap now uses new PackageStates.php
                        $this->redirect();
diff --git a/typo3/sysext/install/Classes/Updates/UpdatePackageManager.php b/typo3/sysext/install/Classes/Updates/UpdatePackageManager.php
deleted file mode 100644 (file)
index b738819..0000000
+++ /dev/null
@@ -1,137 +0,0 @@
-<?php
-namespace TYPO3\CMS\Install\Updates;
-
-use TYPO3\CMS\Core\Package\PackageFactory;
-use TYPO3\CMS\Core\Utility\GeneralUtility;
-use TYPO3\Flow\Annotations as Flow;
-
-/**
- * The default TYPO3 Package Manager
- *
- * @api
- * @Flow\Scope("singleton")
- */
-class UpdatePackageManager extends \TYPO3\CMS\Core\Package\PackageManager {
-
-       /**
-        * @var \TYPO3\CMS\Core\Configuration\ConfigurationManager
-        */
-       protected $configurationManager;
-
-       /**
-        */
-       public function __construct() {
-               $this->configurationManager = new \TYPO3\CMS\Core\Configuration\ConfigurationManager;
-               parent::__construct();
-       }
-
-
-       /**
-        * Initializes the package manager
-        *
-        * @param \TYPO3\CMS\Core\Core\Bootstrap $bootstrap The current bootstrap
-        * @param string $packagesBasePath Absolute path of the Packages directory
-        * @param string $packageStatesPathAndFilename
-        * @return void
-        */
-       public function createPackageStatesFile(\TYPO3\CMS\Core\Core\Bootstrap $bootstrap, $packagesBasePath = PATH_site, $packageStatesPathAndFilename = '') {
-
-               $this->bootstrap = $bootstrap;
-               $this->packagesBasePath = $packagesBasePath;
-               $this->packageStatesPathAndFilename = ($packageStatesPathAndFilename === '') ? PATH_typo3conf . 'PackageStates.php' : $packageStatesPathAndFilename;
-               $this->packageFactory = new PackageFactory($this);
-
-               $this->loadPackageStates();
-               $this->activateProtectedPackagesAndLegacyExtensions();
-               $this->sortAndSavePackageStates();
-               $this->removeExtensionListsFromConfiguration();
-       }
-
-       /**
-        *
-        */
-       protected function activateProtectedPackagesAndLegacyExtensions() {
-               $packagesToActivate = array();
-               // Activate protected/required packages
-               foreach ($this->packages as $packageKey => $package) {
-                       if ($package->isProtected() || (isset($this->packageStatesConfiguration['packages'][$packageKey]['state']) && $this->packageStatesConfiguration['packages'][$packageKey]['state'] === 'active')) {
-                               $packagesToActivate[$package->getPackageKey()] = $package;
-                       }
-               }
-               // Activate legacy extensions
-               foreach ($this->getLoadedExtensionKeys() as $loadedExtensionKey) {
-                       try {
-                               $package = $this->getPackage($loadedExtensionKey);
-                               $packagesToActivate[$package->getPackageKey()] = $package;
-                       } catch (\TYPO3\Flow\Package\Exception\UnknownPackageException $exception) {
-                               if (isset($this->packageStatesConfiguration['packages'][$loadedExtensionKey])) {
-                                       unset($this->packageStatesConfiguration['packages'][$loadedExtensionKey]);
-                               }
-                       }
-               }
-               // Activate dependant packages
-               $this->resolvePackageDependencies();
-               foreach ($packagesToActivate as $packageKey => $package) {
-                       foreach ($this->packageStatesConfiguration['packages'][$packageKey]['dependencies'] as $dependantPackageKey) {
-                               if (!isset($packagesToActivate[$dependantPackageKey])) {
-                                       $dependantPackage = $this->getPackage($dependantPackageKey);
-                                       $packagesToActivate[$dependantPackage->getPackageKey()] = $dependantPackage;
-                               }
-                       }
-               }
-               // Make all active
-               foreach ($packagesToActivate as $packageKey => $package) {
-                       $this->packageStatesConfiguration['packages'][$packageKey]['state'] = 'active';
-                       $this->activePackages[$packageKey] = $package;
-               }
-       }
-
-       /**
-        * Loads the states of available packages from the PackageStates.php file.
-        * The result is stored in $this->packageStatesConfiguration.
-        *
-        * @return void
-        */
-       protected function loadPackageStates() {
-               $this->packageStatesConfiguration = array();
-               $this->scanAvailablePackages();
-       }
-
-       /**
-        * @return array|NULL
-        */
-       protected function getLoadedExtensionKeys() {
-               $loadedExtensions = NULL;
-               try {
-                       // Extensions in extListArray
-                       $loadedExtensions = $this->configurationManager->getLocalConfigurationValueByPath('EXT/extListArray');
-               } catch (\RuntimeException $exception) {
-                       // Fallback handling if extlist is still a string and not an array
-                       // @deprecated since 6.2, will be removed two versions later without a substitute
-                       try {
-                               $loadedExtensions = GeneralUtility::trimExplode(',', $this->configurationManager->getLocalConfigurationValueByPath('EXT/extList'));
-                       } catch (\RuntimeException $exception) {
-
-                       }
-               }
-               return $loadedExtensions;
-       }
-
-       /**
-        *
-        */
-       protected function removeExtensionListsFromConfiguration() {
-               copy(
-                       $this->configurationManager->getLocalConfigurationFileLocation(),
-                       preg_replace('/\.php$/', '.beforePackageStatesMigration.php', $this->configurationManager->getLocalConfigurationFileLocation())
-               );
-               $this->configurationManager->updateLocalConfiguration(array(
-                       'EXT' => array(
-                               'extListArray' => '__UNSET',
-                               'extList' => '__UNSET',
-                               'requiredExt' => '__UNSET',
-                       ),
-               ));
-       }
-
-}