[BUGFIX] ext:install Better error handling in first folder step
[Packages/TYPO3.CMS.git] / typo3 / sysext / install / Classes / Controller / StepController.php
index 16d6215..19ec296 100644 (file)
@@ -52,13 +52,13 @@ class StepController extends AbstractController {
                $this->loadBaseExtensions();
                $this->initializeObjectManager();
 
-               // Warning: Order of this methods is security relevant and interferes with different access
+               // Warning: Order of these methods is security relevant and interferes with different access
                // conditions (new/existing installation). See the single method comments for details.
                $this->outputInstallToolNotEnabledMessageIfNeeded();
                $this->migrateLocalconfToLocalConfigurationIfNeeded();
                $this->outputInstallToolPasswordNotSetMessageIfNeeded();
                $this->executeOrOutputFirstInstallStepIfNeeded();
-               $this->generateEncryptionKeyIfNeeded();
+               $this->executeSilentConfigurationUpgradesIfNeeded();
                $this->initializeSession();
                $this->checkSessionToken();
                $this->checkSessionLifetime();
@@ -111,7 +111,15 @@ class StepController extends AbstractController {
                $stepAction->setToken($this->generateTokenForAction($action));
                $stepAction->setPostValues($this->getPostValues());
 
-               if ($stepAction->needsExecution()) {
+               try {
+                       // needsExecution() may throw a RedirectException to communicate that it changed
+                       // configuration parameters and need an application reload.
+                       $needsExecution = $stepAction->needsExecution();
+               } catch (Exception\RedirectException $e) {
+                       $this->redirect();
+               }
+
+               if ($needsExecution) {
                        $stepAction->setMessages($this->session->getMessagesAndFlush());
                        $this->output($stepAction->handle());
                } else {
@@ -223,7 +231,9 @@ class StepController extends AbstractController {
 
                        // Build new TYPO3_CONF_VARS array
                        $TYPO3_CONF_VARS = NULL;
-                       eval(implode(LF, $typo3ConfigurationVariables));
+                       // Issue #39434: Combining next two lines into one triggers a weird issue in some PHP versions
+                       $evalData = implode(LF, $typo3ConfigurationVariables);
+                       eval($evalData);
 
                        // Add db settings to array
                        $TYPO3_CONF_VARS['DB'] = $typo3DatabaseVariables;
@@ -277,10 +287,16 @@ class StepController extends AbstractController {
 
                /** @var \TYPO3\CMS\Install\Controller\Action\Step\StepInterface $action */
                $action = $this->objectManager->get('TYPO3\\CMS\\Install\\Controller\\Action\\Step\\EnvironmentAndFolders');
-               $needsExecution = $action->needsExecution();
 
-               if (!is_dir(PATH_typo3conf)
-                       || count($errorMessagesFromExecute) > 0
+               try {
+                       // needsExecution() may throw a RedirectException to communicate that it changed
+                       // configuration parameters and need an application reload.
+                       $needsExecution = $action->needsExecution();
+               } catch (Exception\RedirectException $e) {
+                       $this->redirect();
+               }
+
+               if (!@is_dir(PATH_typo3conf)
                        || $needsExecution
                ) {
                        /** @var \TYPO3\CMS\Install\Controller\Action\Step\StepInterface $action */
@@ -299,19 +315,18 @@ class StepController extends AbstractController {
        }
 
        /**
-        * "Silent" upgrade: The encryption key is crucial for securing form tokens
-        * and the whole TYPO3 link rendering later on. A random key is set here in
-        * LocalConfiguration if it does not exist yet. This might possible happen
-        * during upgrading and will happen during first install.
+        * Call silent upgrade class, redirect to self if configuration was changed.
         *
         * @return void
         */
-       protected function generateEncryptionKeyIfNeeded() {
-               if (empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
-                       $randomKey = GeneralUtility::getRandomHexString(96);
-                       /** @var \TYPO3\CMS\Core\Configuration\ConfigurationManager $configurationManager */
-                       $configurationManager = $this->objectManager->get('TYPO3\\CMS\\Core\\Configuration\\ConfigurationManager');
-                       $configurationManager->setLocalConfigurationValueByPath('SYS/encryptionKey', $randomKey);
+       protected function executeSilentConfigurationUpgradesIfNeeded() {
+               /** @var \TYPO3\CMS\Install\Service\SilentConfigurationUpgradeService $upgradeService */
+               $upgradeService = $this->objectManager->get(
+                       'TYPO3\\CMS\\Install\\Service\\SilentConfigurationUpgradeService'
+               );
+               try {
+                       $upgradeService->execute();
+               } catch (Exception\RedirectException $e) {
                        $this->redirect();
                }
        }