[TASK] Remove superfluous indention level in site configuration yaml 41/58341/3
authorSusanne Moog <susanne.moog@typo3.org>
Wed, 19 Sep 2018 21:02:09 +0000 (23:02 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 20 Sep 2018 07:58:15 +0000 (09:58 +0200)
The site configuration is in folder "sites" in a file called config and
does not need a "site" key to identify its purpose. To keep writing the
config as easy as possible the site configuration moved one level up and
now resides directly in config.yaml.

Additionally on writing top level keys that are not written by the GUI
will be kept, so extension authors can add additional configuration to
the site object without needing to configure the GUI (as that is hardly
extensible in the current state). Array keys // top level objects that
are configurable via GUI are however overwritten completely.

Resolves: #86323
Releases: master
Change-Id: I6100dbf53b0953e593a6156837de1fe013a74fae
Reviewed-on: https://review.typo3.org/58341
Reviewed-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: Tobi Kretschmann <tobi@tobishome.de>
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Classes/Controller/SiteConfigurationController.php
typo3/sysext/core/Classes/Configuration/SiteConfiguration.php
typo3/sysext/core/Documentation/Changelog/master/Deprecation-86323-ConfigurationKeySiteHasBeenDeprecatedInYAMLSiteConfiguration.rst [new file with mode: 0644]

index 34fedaf..3548de2 100644 (file)
@@ -245,14 +245,14 @@ class SiteConfigurationController
         try {
             $newSysSiteData = [];
             // Hard set rootPageId: This is TCA readOnly and not transmitted by FormEngine, but is also the "uid" of the site record
         try {
             $newSysSiteData = [];
             // Hard set rootPageId: This is TCA readOnly and not transmitted by FormEngine, but is also the "uid" of the site record
-            $newSysSiteData['site']['rootPageId'] = $pageId;
+            $newSysSiteData['rootPageId'] = $pageId;
             foreach ($sysSiteRow as $fieldName => $fieldValue) {
                 $type = $siteTca['site']['columns'][$fieldName]['config']['type'];
                 if ($type === 'input') {
                     $fieldValue = $this->validateAndProcessValue('site', $fieldName, $fieldValue);
             foreach ($sysSiteRow as $fieldName => $fieldValue) {
                 $type = $siteTca['site']['columns'][$fieldName]['config']['type'];
                 if ($type === 'input') {
                     $fieldValue = $this->validateAndProcessValue('site', $fieldName, $fieldValue);
-                    $newSysSiteData['site'][$fieldName] = $fieldValue;
+                    $newSysSiteData[$fieldName] = $fieldValue;
                 } elseif ($type === 'inline') {
                 } elseif ($type === 'inline') {
-                    $newSysSiteData['site'][$fieldName] = [];
+                    $newSysSiteData[$fieldName] = [];
                     $childRowIds = GeneralUtility::trimExplode(',', $fieldValue, true);
                     if (!isset($siteTca['site']['columns'][$fieldName]['config']['foreign_table'])) {
                         throw new \RuntimeException('No foreign_table found for inline type', 1521555037);
                     $childRowIds = GeneralUtility::trimExplode(',', $fieldValue, true);
                     if (!isset($siteTca['site']['columns'][$fieldName]['config']['foreign_table'])) {
                         throw new \RuntimeException('No foreign_table found for inline type', 1521555037);
@@ -263,7 +263,7 @@ class SiteConfigurationController
                         if (!isset($data[$foreignTable][$childRowId])) {
                             if (!empty($currentSiteConfiguration[$fieldName][$childRowId])) {
                                 // A collapsed inline record: Fetch data from existing config
                         if (!isset($data[$foreignTable][$childRowId])) {
                             if (!empty($currentSiteConfiguration[$fieldName][$childRowId])) {
                                 // A collapsed inline record: Fetch data from existing config
-                                $newSysSiteData['site'][$fieldName][] = $currentSiteConfiguration[$fieldName][$childRowId];
+                                $newSysSiteData[$fieldName][] = $currentSiteConfiguration[$fieldName][$childRowId];
                                 continue;
                             }
                             throw new \RuntimeException('No data found for table ' . $foreignTable . ' with id ' . $childRowId, 1521555177);
                                 continue;
                             }
                             throw new \RuntimeException('No data found for table ' . $foreignTable . ' with id ' . $childRowId, 1521555177);
@@ -285,15 +285,20 @@ class SiteConfigurationController
                                 throw new \RuntimeException('TCA type ' . $type . ' not implemented in site handling', 1521555340);
                             }
                         }
                                 throw new \RuntimeException('TCA type ' . $type . ' not implemented in site handling', 1521555340);
                             }
                         }
-                        $newSysSiteData['site'][$fieldName][] = $childRowData;
+                        $newSysSiteData[$fieldName][] = $childRowData;
                     }
                 } elseif ($type === 'select') {
                     }
                 } elseif ($type === 'select') {
-                    $newSysSiteData['site'][$fieldName] = (int)$fieldValue;
+                    $newSysSiteData[$fieldName] = (int)$fieldValue;
                 } else {
                     throw new \RuntimeException('TCA type ' . $type . ' not implemented in site handling', 1521032781);
                 }
             }
 
                 } else {
                     throw new \RuntimeException('TCA type ' . $type . ' not implemented in site handling', 1521032781);
                 }
             }
 
+            // keep root config objects not given via GUI
+            // this way extension authors are able to use their own objects on root level
+            // that are not configurable via GUI
+            // however: we overwrite the full subset of any GUI object to make sure we have a clean state
+            $newSysSiteData = array_merge($currentSiteConfiguration, $newSysSiteData);
             $newSiteConfiguration = $this->validateFullStructure($newSysSiteData);
 
             // Persist the configuration
             $newSiteConfiguration = $this->validateFullStructure($newSysSiteData);
 
             // Persist the configuration
@@ -457,10 +462,10 @@ class SiteConfigurationController
     {
         $languageService = $this->getLanguageService();
         // Verify there are not two error handlers with the same error code
     {
         $languageService = $this->getLanguageService();
         // Verify there are not two error handlers with the same error code
-        if (isset($newSysSiteData['site']['errorHandling']) && is_array($newSysSiteData['site']['errorHandling'])) {
+        if (isset($newSysSiteData['errorHandling']) && is_array($newSysSiteData['errorHandling'])) {
             $uniqueCriteria = [];
             $validChildren = [];
             $uniqueCriteria = [];
             $validChildren = [];
-            foreach ($newSysSiteData['site']['errorHandling'] as $child) {
+            foreach ($newSysSiteData['errorHandling'] as $child) {
                 if (!isset($child['errorCode'])) {
                     throw new \RuntimeException('No errorCode found', 1521788518);
                 }
                 if (!isset($child['errorCode'])) {
                     throw new \RuntimeException('No errorCode found', 1521788518);
                 }
@@ -479,11 +484,11 @@ class SiteConfigurationController
                     $defaultFlashMessageQueue->enqueue($flashMessage);
                 }
             }
                     $defaultFlashMessageQueue->enqueue($flashMessage);
                 }
             }
-            $newSysSiteData['site']['errorHandling'] = $validChildren;
+            $newSysSiteData['errorHandling'] = $validChildren;
         }
 
         // Verify there is only one inline child per sys_language record configured.
         }
 
         // Verify there is only one inline child per sys_language record configured.
-        if (!isset($newSysSiteData['site']['languages']) || !is_array($newSysSiteData['site']['languages']) || count($newSysSiteData['site']['languages']) < 1) {
+        if (!isset($newSysSiteData['languages']) || !is_array($newSysSiteData['languages']) || count($newSysSiteData['languages']) < 1) {
             throw new \RuntimeException(
                 'No default language definition found. The interface does not allow this. Aborting',
                 1521789306
             throw new \RuntimeException(
                 'No default language definition found. The interface does not allow this. Aborting',
                 1521789306
@@ -491,7 +496,7 @@ class SiteConfigurationController
         }
         $uniqueCriteria = [];
         $validChildren = [];
         }
         $uniqueCriteria = [];
         $validChildren = [];
-        foreach ($newSysSiteData['site']['languages'] as $child) {
+        foreach ($newSysSiteData['languages'] as $child) {
             if (!isset($child['languageId'])) {
                 throw new \RuntimeException('languageId not found', 1521789455);
             }
             if (!isset($child['languageId'])) {
                 throw new \RuntimeException('languageId not found', 1521789455);
             }
@@ -510,7 +515,7 @@ class SiteConfigurationController
                 $defaultFlashMessageQueue->enqueue($flashMessage);
             }
         }
                 $defaultFlashMessageQueue->enqueue($flashMessage);
             }
         }
-        $newSysSiteData['site']['languages'] = $validChildren;
+        $newSysSiteData['languages'] = $validChildren;
 
         return $newSysSiteData;
     }
 
         return $newSysSiteData;
     }
index 87987c1..aecd628 100644 (file)
@@ -73,9 +73,9 @@ class SiteConfiguration
         $sites = [];
         $siteConfiguration = $this->getAllSiteConfigurationFromFiles();
         foreach ($siteConfiguration as $identifier => $configuration) {
         $sites = [];
         $siteConfiguration = $this->getAllSiteConfigurationFromFiles();
         foreach ($siteConfiguration as $identifier => $configuration) {
-            $rootPageId = (int)($configuration['site']['rootPageId'] ?? 0);
+            $rootPageId = (int)($configuration['rootPageId'] ?? 0);
             if ($rootPageId > 0) {
             if ($rootPageId > 0) {
-                $sites[$identifier] = GeneralUtility::makeInstance(Site::class, $identifier, $rootPageId, $configuration['site']);
+                $sites[$identifier] = GeneralUtility::makeInstance(Site::class, $identifier, $rootPageId, $configuration);
             }
         }
         return $sites;
             }
         }
         return $sites;
@@ -108,6 +108,13 @@ class SiteConfiguration
             foreach ($finder as $fileInfo) {
                 $configuration = $loader->load(GeneralUtility::fixWindowsFilePath((string)$fileInfo));
                 $identifier = basename($fileInfo->getPath());
             foreach ($finder as $fileInfo) {
                 $configuration = $loader->load(GeneralUtility::fixWindowsFilePath((string)$fileInfo));
                 $identifier = basename($fileInfo->getPath());
+                if (isset($configuration['site'])) {
+                    trigger_error(
+                        'Site configuration with key \'site\' has been deprecated, remove indentation level and site key.',
+                        E_USER_DEPRECATED
+                    );
+                    $configuration = $configuration['site'];
+                }
                 $siteConfiguration[$identifier] = $configuration;
             }
             $this->getCache()->set($this->cacheIdentifier, json_encode($siteConfiguration));
                 $siteConfiguration[$identifier] = $configuration;
             }
             $this->getCache()->set($this->cacheIdentifier, json_encode($siteConfiguration));
diff --git a/typo3/sysext/core/Documentation/Changelog/master/Deprecation-86323-ConfigurationKeySiteHasBeenDeprecatedInYAMLSiteConfiguration.rst b/typo3/sysext/core/Documentation/Changelog/master/Deprecation-86323-ConfigurationKeySiteHasBeenDeprecatedInYAMLSiteConfiguration.rst
new file mode 100644 (file)
index 0000000..4278a0d
--- /dev/null
@@ -0,0 +1,33 @@
+.. include:: ../../Includes.txt
+
+=============================================================================================
+Deprecation: #86323 - Configuration key "site" has been deprecated in YAML site configuration
+=============================================================================================
+
+See :issue:`86323`
+
+Description
+===========
+
+The site configuration is in a folder called "sites" in a file called config and does not need a "site" key to identify its purpose. To keep writing the
+config as easy as possible the site configuration moved one level up and now resides directly in config.yaml.
+
+
+Impact
+======
+
+Having the site configuration below the key "site" has been deprecated and will trigger a deprecation warning.
+
+
+Affected Installations
+======================
+
+Installations with a site config that have a key "site" are affected.
+
+
+Migration
+=========
+
+Remove the "site" key and first level indentation either by directly editing the YAML file or by saving via the sites module.
+
+.. index:: Backend, NotScanned, ext:core
\ No newline at end of file