[BUGFIX] Recreate PackageStates in install tool if missing 90/57690/2
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 26 Jul 2018 11:08:18 +0000 (13:08 +0200)
committerAndreas Wolf <andreas.wolf@typo3.org>
Thu, 26 Jul 2018 12:17:03 +0000 (14:17 +0200)
v8 has a fallback if PackageStates.php vanished on a running instance
and the install tool is called, a default PackageStates file is
generated that comes with a minimal set of active packages that
allow login to the backend and activating further packages again.

This broke in v9 with the install tool refactoring and is fixed
with the patch: The install tool detects after successful login
if PackageStates.php misses and creates a new one. Note this
operation is not yet messaged to the user. This could be added
later if a true recovery procedure is added to the install tool.
For now, the sole purpose of the patch is to resurrect an instance.

Resolves: #85634
Releases: master
Change-Id: I0e72a9e8b4f828892838921d722c61520179af1d
Reviewed-on: https://review.typo3.org/57690
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Tested-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Andreas Wolf <andreas.wolf@typo3.org>
Tested-by: Andreas Wolf <andreas.wolf@typo3.org>
typo3/sysext/install/Classes/Http/RequestHandler.php

index 3befc6b..9fd5919 100644 (file)
@@ -18,6 +18,7 @@ namespace TYPO3\CMS\Install\Http;
 use Psr\Http\Message\ResponseInterface;
 use Psr\Http\Message\ServerRequestInterface;
 use TYPO3\CMS\Core\Configuration\ConfigurationManager;
+use TYPO3\CMS\Core\Core\Bootstrap;
 use TYPO3\CMS\Core\Core\Environment;
 use TYPO3\CMS\Core\FormProtection\FormProtectionFactory;
 use TYPO3\CMS\Core\FormProtection\InstallToolFormProtection;
@@ -26,6 +27,8 @@ use TYPO3\CMS\Core\Http\JsonResponse;
 use TYPO3\CMS\Core\Http\RequestHandlerInterface;
 use TYPO3\CMS\Core\Messaging\FlashMessage;
 use TYPO3\CMS\Core\Messaging\FlashMessageQueue;
+use TYPO3\CMS\Core\Package\PackageInterface;
+use TYPO3\CMS\Core\Package\PackageManager;
 use TYPO3\CMS\Install\Authentication\AuthenticationService;
 use TYPO3\CMS\Install\Controller\AbstractController;
 use TYPO3\CMS\Install\Controller\EnvironmentController;
@@ -177,6 +180,7 @@ class RequestHandler implements RequestHandlerInterface
                     1505215756
                 );
             }
+            $this->recreatePackageStatesFileIfMissing();
             /** @var AbstractController $controller */
             $controller = new $this->controllers[$controllerName];
             if (!method_exists($controller, $action)) {
@@ -307,7 +311,27 @@ class RequestHandler implements RequestHandlerInterface
      */
     protected function checkIfEssentialConfigurationExists(): bool
     {
-        return file_exists($this->configurationManager->getLocalConfigurationFileLocation())
-            && file_exists(Environment::getLegacyConfigPath() . '/PackageStates.php');
+        return file_exists($this->configurationManager->getLocalConfigurationFileLocation());
+    }
+
+    /**
+     * Create PackageStates.php if missing and LocalConfiguration exists.
+     *
+     * It is fired if PackageStates.php is deleted on a running instance,
+     * all packages marked as "part of minimal system" are activated in this case.
+     */
+    protected function recreatePackageStatesFileIfMissing(): void
+    {
+        if (!file_exists(Environment::getLegacyConfigPath() . '/PackageStates.php')) {
+            /** @var \TYPO3\CMS\Core\Package\FailsafePackageManager $packageManager */
+            $packageManager = Bootstrap::getInstance()->getEarlyInstance(PackageManager::class);
+            $packages = $packageManager->getAvailablePackages();
+            foreach ($packages as $package) {
+                if ($package instanceof PackageInterface && $package->isPartOfMinimalUsableSystem()) {
+                    $packageManager->activatePackage($package->getPackageKey());
+                }
+            }
+            $packageManager->forceSortAndSavePackageStates();
+        }
     }
 }