[BUGFIX] Catch all errors while starting installer 19/23219/5
authorAlexander Opitz <opitz.alexander@googlemail.com>
Wed, 21 Aug 2013 12:44:19 +0000 (14:44 +0200)
committerChristian Kuhn <lolli@schwarzbu.ch>
Wed, 5 Mar 2014 21:56:23 +0000 (22:56 +0100)
While initializing the installer it can happen that
Exceptions are thrown. As there is no ExceptionHandler
initialized yet, we get a white page and the Fatal error
will be logged.

Mostly it is the problem that typo3conf and/or typo3temp
isn't writeable. But it might something else which throws
an exception.

This patch catches the exception in the initializing
process and shows a page in the layout of the installer.
It shows the exception message, a first hint for the maybe
write permissions problem and a link with the exception number.

Resolves: #11771
Releases: 6.1
Change-Id: Ib99860054b727907a9a84bdfd3e35fe3f2eebe00
Reviewed-on: https://review.typo3.org/23219
Reviewed-by: Markus Klein
Tested-by: Markus Klein
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
typo3/install/index.php
typo3/sysext/install/Classes/InstallBootstrap.php

index 31e5320..1639956 100755 (executable)
@@ -39,22 +39,28 @@ require '../sysext/core/Classes/Core/Bootstrap.php';
 
 require '../sysext/install/Classes/InstallBootstrap.php';
 \TYPO3\CMS\Install\InstallBootstrap::checkEnabledInstallToolOrDie();
-\TYPO3\CMS\Install\InstallBootstrap::createLocalConfigurationIfNotExists();
 
-\TYPO3\CMS\Core\Core\Bootstrap::getInstance()
-       ->startOutputBuffering()
-       ->loadConfigurationAndInitialize()
-       ->loadTypo3LoadedExtAndExtLocalconf(FALSE)
-       ->applyAdditionalConfigurationSettings()
-       ->initializeTypo3DbGlobal()
-       ->checkLockedBackendAndRedirectOrDie()
-       ->checkBackendIpOrDie()
-       ->checkSslBackendAndRedirectIfNeeded();
+try {
+       \TYPO3\CMS\Install\InstallBootstrap::createLocalConfigurationIfNotExists();
+
+       \TYPO3\CMS\Core\Core\Bootstrap::getInstance()
+               ->startOutputBuffering()
+               ->loadConfigurationAndInitialize()
+               ->loadTypo3LoadedExtAndExtLocalconf(FALSE)
+               ->applyAdditionalConfigurationSettings()
+               ->initializeTypo3DbGlobal()
+               ->checkLockedBackendAndRedirectOrDie()
+               ->checkBackendIpOrDie()
+               ->checkSslBackendAndRedirectIfNeeded();
+} catch (\Exception $exception) {
+       \TYPO3\CMS\Install\InstallBootstrap::dieWithExceptionMessage($exception);
+}
 
-       // Run install script
+// Run install script
 if (!\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::isLoaded('install')) {
        die('Install Tool is not loaded as an extension.<br />You must add the key "install" to the list of installed extensions in typo3conf/LocalConfiguration.php, $TYPO3_CONF_VARS[\'EXT\'][\'extListArray\'].');
 }
+
 require_once \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('install') . 'mod/class.tx_install.php';
 $install_check = \TYPO3\CMS\Core\Utility\GeneralUtility::makeInstance('TYPO3\\CMS\\Install\\Installer', TRUE);
 $install_check->init();
index 332c504..c6a4f33 100644 (file)
@@ -91,24 +91,45 @@ class InstallBootstrap {
        }
 
        /**
+        * Exit the script with the message of the exception in install tool layout.
+        *
+        * @param \Exception $exception Exception to shown.
+        * @return void
+        */
+       static public function dieWithExceptionMessage(\Exception $exception) {
+               self::dieWithMessage(
+                       'The Install Tool has encountered a problem.',
+                       '
+                               <p>
+                                       The Install Tool has encountered a problem. In order to fix it please read the following error message carefully:
+                               </p>
+                               <ul>
+                                       <li>
+                                               ' . htmlspecialchars($exception->getMessage()) . '
+                                       </li>
+                               </ul>
+                               <p>
+                                       Usually the problem is a missing write permission for the webserver user to the <code>typo3conf</code> and/or
+                                       <code>typo3temp</code> directory.
+                               </p>
+                       ' .
+                       ($exception->getCode() > 0
+                               ? '<p>More information regarding this error might be available <a href="' .
+                                       TYPO3_URL_EXCEPTION . $exception->getCode() . '" target="_blank">online</a>.</p>'
+                               : ''
+                       )
+               );
+       }
+
+       /**
         * Exit the script with a message that the install tool is locked.
         *
         * @return void
         */
        static protected function dieWithLockedInstallToolMessage() {
-               require_once PATH_site . 'typo3/sysext/core/Classes/Html/HtmlParser.php';
-               // Define the stylesheet
-               $stylesheet = '<link rel="stylesheet" type="text/css" href="' . '../stylesheets/install/install.css" />';
-               $javascript = '<script type="text/javascript" src="' . '../contrib/prototype/prototype.js"></script>';
-               $javascript .= '<script type="text/javascript" src="' . '../sysext/install/Resources/Public/Javascript/install.js"></script>';
-               // Get the template file
-               $template = @file_get_contents((PATH_site . 'typo3/templates/install.html'));
-               // Define the markers content
-               $markers = array(
-                       'styleSheet' => $stylesheet,
-                       'javascript' => $javascript,
-                       'title' => 'The Install Tool is locked',
-                       'content' => '
+               self::dieWithMessage(
+                       'The Install Tool is locked',
+                       '
                                <p>
                                        To enable the Install Tool, the file ENABLE_INSTALL_TOOL must be created.
                                </p>
@@ -132,6 +153,30 @@ class InstallBootstrap {
                                </p>
                        '
                );
+       }
+
+       /**
+        * Exit the script with given title and message in the install tool layout.
+        *
+        * @param string $title Title of the message.
+        * @param string $content Content of the message to show.
+        * @return void
+        */
+       static protected function dieWithMessage($title, $content) {
+               require_once PATH_site . 'typo3/sysext/core/Classes/Html/HtmlParser.php';
+               // Define the stylesheet
+               $stylesheet = '<link rel="stylesheet" type="text/css" href="' . '../stylesheets/install/install.css" />';
+               $javascript = '<script type="text/javascript" src="' . '../contrib/prototype/prototype.js"></script>';
+               $javascript .= '<script type="text/javascript" src="' . '../sysext/install/Resources/Public/Javascript/install.js"></script>';
+               // Get the template file
+               $template = @file_get_contents(PATH_site . 'typo3/templates/install.html');
+               // Define the markers content
+               $markers = array(
+                       'styleSheet' => $stylesheet,
+                       'javascript' => $javascript,
+                       'title' => $title,
+                       'content' => $content,
+               );
                // Fill the markers
                $content = \TYPO3\CMS\Core\Html\HtmlParser::substituteMarkerArray($template, $markers, '###|###', 1, 1);
                // Output the warning message and exit
@@ -144,5 +189,4 @@ class InstallBootstrap {
 
 }
 
-
 ?>
\ No newline at end of file