From a65c5c3ae8d59a85538986bdff7f8ce8df4b3909 Mon Sep 17 00:00:00 2001 From: Benni Mack Date: Wed, 9 Jan 2019 21:33:54 +0100 Subject: [PATCH] [BUGFIX] Create default site configuration on installation When a new TYPO3 installation is set up, the user can choose to "create a first site" (page with sys_template). In this step, it should be important that a site configuration should be created as well, in order to use site handling right out-of-the-box. Therefore, this step in the installer now also creates a site configuration (identifier "main") with one language english to get started. Resolves: #87383 Releases: master, 9.5 Change-Id: Ib8ef27c076d8ed24bfeb015aea52bdcf4ec0432c Reviewed-on: https://review.typo3.org/59391 Reviewed-by: Steffen Dietrich Tested-by: Steffen Dietrich Tested-by: TYPO3com Reviewed-by: Georg Ringer Tested-by: Georg Ringer Reviewed-by: Anja Leichsenring Tested-by: Anja Leichsenring --- .../Controller/InstallerController.php | 52 +++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/typo3/sysext/install/Classes/Controller/InstallerController.php b/typo3/sysext/install/Classes/Controller/InstallerController.php index dc3113c9a9d4..89383508bb39 100644 --- a/typo3/sysext/install/Classes/Controller/InstallerController.php +++ b/typo3/sysext/install/Classes/Controller/InstallerController.php @@ -21,6 +21,7 @@ use Psr\Http\Message\ServerRequestInterface; use TYPO3\CMS\Core\Configuration\ConfigurationManager; use TYPO3\CMS\Core\Configuration\ExtensionConfiguration; +use TYPO3\CMS\Core\Configuration\SiteConfiguration; use TYPO3\CMS\Core\Core\Bootstrap; use TYPO3\CMS\Core\Core\Environment; use TYPO3\CMS\Core\Crypto\PasswordHashing\Argon2iPasswordHash; @@ -39,6 +40,7 @@ use TYPO3\CMS\Core\FormProtection\InstallToolFormProtection; use TYPO3\CMS\Core\Http\HtmlResponse; use TYPO3\CMS\Core\Http\JsonResponse; +use TYPO3\CMS\Core\Http\NormalizedParams; use TYPO3\CMS\Core\Messaging\FlashMessage; use TYPO3\CMS\Core\Messaging\FlashMessageQueue; use TYPO3\CMS\Core\Package\PackageInterface; @@ -798,6 +800,8 @@ public function executeDefaultConfigurationAction(ServerRequestInterface $reques For each website you need a TypoScript template on the main page of your website (on the top level). For better maintenance all TypoScript should be extracted into external files via .' ] ); + + $this->createSiteConfiguration('main', (int)$pageUid, $request); break; } @@ -1191,4 +1195,52 @@ protected function loadExtLocalconfDatabaseAndExtTables() \TYPO3\CMS\Core\Core\Bootstrap::loadBaseTca(false); \TYPO3\CMS\Core\Core\Bootstrap::loadExtTables(false); } + + /** + * Creates a site configuration with one language "English" which is the de-facto default language for TYPO3 in general. + * + * @param string $identifier + * @param int $rootPageId + * @param ServerRequestInterface $request + * @throws \TYPO3\CMS\Core\Cache\Exception\NoSuchCacheException + */ + protected function createSiteConfiguration(string $identifier, int $rootPageId, ServerRequestInterface $request) + { + $normalizedParams = $request->getAttribute('normalizedParams', null); + if (!($normalizedParams instanceof NormalizedParams)) { + $normalizedParams = new NormalizedParams( + $request->getServerParams(), + $GLOBALS['TYPO3_CONF_VARS']['SYS'], + Environment::getCurrentScript(), + Environment::getPublicPath() + ); + } + + // Create a default site configuration called "main" as best practice + $siteConfiguration = GeneralUtility::makeInstance( + SiteConfiguration::class, + Environment::getConfigPath() . '/sites' + ); + $siteConfiguration->write($identifier, [ + 'rootPageId' => $rootPageId, + 'base' => $normalizedParams->getSiteUrl(), + 'languages' => [ + 0 => [ + 'title' => 'English', + 'enabled' => true, + 'languageId' => 0, + 'base' => '/en/', + 'typo3Language' => 'default', + 'locale' => 'en_US.UTF-8', + 'iso-639-1' => 'en', + 'navigationTitle' => 'English', + 'hreflang' => 'en-us', + 'direction' => 'ltr', + 'flag' => 'us', + ], + ], + 'errorHandling' => [], + 'routes' => [], + ]); + } }