[BUGFIX] Load uncached site configuration in editAction 90/62090/9
authorKevin Appelt <kevin.appelt@icloud.com>
Thu, 24 Oct 2019 07:56:32 +0000 (09:56 +0200)
committerSusanne Moog <look@susi.dev>
Sat, 25 Jan 2020 15:08:18 +0000 (16:08 +0100)
By loading the uncached site configuration, no direct
changes to the configuration files are overridden when
using the Site management module.

Resolves: #89492
Releases: master, 9.5
Change-Id: I4ef3ac08692e709fc2953bc17b5759d6f55f463f
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/62090
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Steffen Frese <steffenf14@gmail.com>
Tested-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Tested-by: Henning Liebe <h.liebe@neusta.de>
Tested-by: Susanne Moog <look@susi.dev>
Reviewed-by: Steffen Frese <steffenf14@gmail.com>
Reviewed-by: Sascha Rademacher <sascha.rademacher+typo3@gmail.com>
Reviewed-by: Henning Liebe <h.liebe@neusta.de>
Reviewed-by: Susanne Moog <look@susi.dev>
typo3/sysext/backend/Classes/Controller/SiteConfigurationController.php
typo3/sysext/core/Classes/Configuration/SiteConfiguration.php
typo3/sysext/core/Classes/Site/SiteFinder.php

index 4c91421..485821f 100644 (file)
@@ -88,6 +88,9 @@ class SiteConfigurationController
      */
     public function handleRequest(ServerRequestInterface $request): ResponseInterface
     {
+        // forcing uncached sites will re-initialize `SiteFinder`
+        // which is used later by FormEngine (implicit behavior)
+        $this->siteFinder->getAllSites(false);
         $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/ContextMenu');
         $this->moduleTemplate->getPageRenderer()->loadRequireJsModule('TYPO3/CMS/Backend/Modal');
         $action = $request->getQueryParams()['action'] ?? $request->getParsedBody()['action'] ?? 'overview';
index 4e630ce..5187cd2 100644 (file)
@@ -76,11 +76,15 @@ class SiteConfiguration implements SingletonInterface
     /**
      * Return all site objects which have been found in the filesystem.
      *
+     * @param bool $useCache
      * @return Site[]
      */
-    public function getAllExistingSites(): array
+    public function getAllExistingSites(bool $useCache = true): array
     {
-        return $this->firstLevelCache ?? $this->resolveAllExistingSites();
+        if ($useCache && $this->firstLevelCache !== null) {
+            return $this->firstLevelCache;
+        }
+        return $this->resolveAllExistingSites($useCache);
     }
 
     /**
index 0329069..7ac8ae3 100644 (file)
@@ -42,30 +42,35 @@ class SiteFinder
     protected $mappingRootPageIdToIdentifier = [];
 
     /**
+     * @var SiteConfiguration
+     */
+    protected $siteConfiguration;
+
+    /**
      * Fetches all existing configurations as Site objects
      *
      * @param SiteConfiguration $siteConfiguration
      */
     public function __construct(SiteConfiguration $siteConfiguration = null)
     {
-        $siteConfiguration = $siteConfiguration ?? GeneralUtility::makeInstance(
+        $this->siteConfiguration = $siteConfiguration ?? GeneralUtility::makeInstance(
             SiteConfiguration::class,
             Environment::getConfigPath() . '/sites'
         );
-        $sites = $siteConfiguration->getAllExistingSites();
-        foreach ($sites as $identifier => $site) {
-            $this->sites[$identifier] = $site;
-            $this->mappingRootPageIdToIdentifier[$site->getRootPageId()] = $identifier;
-        }
+        $this->fetchAllSites();
     }
 
     /**
      * Return a list of all configured sites
      *
+     * @param bool $useCache
      * @return Site[]
      */
-    public function getAllSites(): array
+    public function getAllSites(bool $useCache = true): array
     {
+        if ($useCache === false) {
+            $this->fetchAllSites($useCache);
+        }
         return $this->sites;
     }
 
@@ -132,4 +137,15 @@ class SiteFinder
         }
         throw new SiteNotFoundException('No site found in root line of page ' . $pageId, 1521716622);
     }
+
+    /**
+     * @param bool $useCache
+     */
+    protected function fetchAllSites(bool $useCache = true): void
+    {
+        $this->sites = $this->siteConfiguration->getAllExistingSites($useCache);
+        foreach ($this->sites as $identifier => $site) {
+            $this->mappingRootPageIdToIdentifier[$site->getRootPageId()] = $identifier;
+        }
+    }
 }