From d8dda294fc9c5daf2e7da1463ff3025b0fbe889b Mon Sep 17 00:00:00 2001
From: Benjamin Franzke <bfr@qbus.de>
Date: Wed, 15 Apr 2020 18:50:46 +0200
Subject: [PATCH] [BUGFIX] Provide symfony container in install tool "Check
 TCA" action
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

A booted symfony container is needed as ext_localconf.php is
loaded since #89713 for the "Check TCA" action.
ext_localconf.php files may depend on a fully-booted
symfony container, therefore we need to provide it in this
case as well – or ext_localconf.php loading may fail.

Adapt the LateBootService to allow to reset to a
previously backuped container (even if it has been
reset in the meantime by another method).

Currently affected extensions were EXT:news before commit
ac0cb20c (which added a workaround for this case).
Thus the bugfix can be verified against the parent of that commit:
georgringer/news:205cb3e

Releases: master
Resolves: #91073
Related: #89713
Change-Id: Iaceb5efae26c1ae2e08e0db31ff2c223cc803ce7
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/64190
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Josef Glatz <josefglatz@gmail.com>
Tested-by: Georg Ringer <georg.ringer@gmail.com>
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Georg Ringer <georg.ringer@gmail.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
---
 .../Classes/Controller/UpgradeController.php      |  3 +++
 .../install/Classes/Service/LateBootService.php   | 15 ++++++++-------
 2 files changed, 11 insertions(+), 7 deletions(-)

diff --git a/typo3/sysext/install/Classes/Controller/UpgradeController.php b/typo3/sysext/install/Classes/Controller/UpgradeController.php
index 60facea7a2b7..6236a0457a55 100644
--- a/typo3/sysext/install/Classes/Controller/UpgradeController.php
+++ b/typo3/sysext/install/Classes/Controller/UpgradeController.php
@@ -789,6 +789,8 @@ class UpgradeController extends AbstractController
         $loadTcaService = GeneralUtility::makeInstance(LoadTcaService::class);
         $loadTcaService->loadExtensionTablesWithoutMigration();
         $baseTca = $GLOBALS['TCA'];
+        $container = $this->lateBootService->getContainer();
+        $backup = $this->lateBootService->makeCurrent($container);
         foreach ($this->packageManager->getActivePackages() as $package) {
             $this->extensionCompatTesterLoadExtLocalconfForExtension($package);
 
@@ -807,6 +809,7 @@ class UpgradeController extends AbstractController
                 $baseTca = $newTca;
             }
         }
+        $this->lateBootService->makeCurrent(null, $backup);
         return new JsonResponse([
             'success' => true,
             'status' => $messageQueue,
diff --git a/typo3/sysext/install/Classes/Service/LateBootService.php b/typo3/sysext/install/Classes/Service/LateBootService.php
index 0a9518b67cf4..b85e860c8e9c 100644
--- a/typo3/sysext/install/Classes/Service/LateBootService.php
+++ b/typo3/sysext/install/Classes/Service/LateBootService.php
@@ -85,15 +85,16 @@ class LateBootService
      * is specified
      *
      * @param ContainerInterface $container
-     * @param array $oldBackup
+     * @param array $backup
      * @return array
      */
-    public function makeCurrent(ContainerInterface $container = null, array $oldBackup = []): array
+    public function makeCurrent(ContainerInterface $container = null, array $backup = []): array
     {
-        $container = $container ?? $this->failsafeContainer;
+        $container = $container ?? $backup['container'] ?? $this->failsafeContainer;
 
-        $backup = [
-            'singletonInstances', GeneralUtility::getSingletonInstances(),
+        $newBackup = [
+            'singletonInstances' => GeneralUtility::getSingletonInstances(),
+            'container' => GeneralUtility::getContainer(),
         ];
 
         GeneralUtility::purgeInstances();
@@ -102,12 +103,12 @@ class LateBootService
         GeneralUtility::setContainer($container);
         ExtensionManagementUtility::setPackageManager($container->get(PackageManager::class));
 
-        $backupSingletonInstances = $oldBackup['singletonInstances'] ?? [];
+        $backupSingletonInstances = $backup['singletonInstances'] ?? [];
         foreach ($backupSingletonInstances as $className => $instance) {
             GeneralUtility::setSingletonInstance($className, $instance);
         }
 
-        return $backup;
+        return $newBackup;
     }
 
     /**
-- 
GitLab