[FEATURE] Capture PHP errors in install tool 40/23440/4
authorNicole Cordes <typo3@cordes.co>
Thu, 29 Aug 2013 00:31:09 +0000 (02:31 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 29 Aug 2013 12:16:40 +0000 (14:16 +0200)
Some parts of the install tool can throw fatal PHP errors if
broken extensions are loaded. Currently the database analyzer and
the upgrade wizards are affected by this.

The patch implements a shutdown function that is called even if a
fatal error is thrown and redirects to a special action that renders
the "Check for broken extensions".

Resolves: #51499
Releases: 6.2
Change-Id: Ie64781e59732fb1ef05efd6bd9da1e136241b22e
Reviewed-on: https://review.typo3.org/23440
Reviewed-by: Christian Kuhn
Tested-by: Christian Kuhn
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/install/Classes/Controller/Action/Tool/LoadExtensions.php [new file with mode: 0644]
typo3/sysext/install/Classes/Controller/ToolController.php
typo3/sysext/install/Resources/Private/Templates/Action/Tool/LoadExtensions.html [new file with mode: 0644]

diff --git a/typo3/sysext/install/Classes/Controller/Action/Tool/LoadExtensions.php b/typo3/sysext/install/Classes/Controller/Action/Tool/LoadExtensions.php
new file mode 100644 (file)
index 0000000..b72bd4b
--- /dev/null
@@ -0,0 +1,47 @@
+<?php
+namespace TYPO3\CMS\Install\Controller\Action\Tool;
+
+/***************************************************************
+ *  Copyright notice
+ *
+ *  (c) 2013 Nicole Cordes <typo3@cordes.co>
+ *  All rights reserved
+ *
+ *  This script is part of the TYPO3 project. The TYPO3 project is
+ *  free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU General Public License as published by
+ *  the Free Software Foundation; either version 2 of the License, or
+ *  (at your option) any later version.
+ *
+ *  The GNU General Public License can be found at
+ *  http://www.gnu.org/copyleft/gpl.html.
+ *
+ *  This script is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  This copyright notice MUST APPEAR in all copies of the script!
+ ***************************************************************/
+
+use TYPO3\CMS\Install\Controller\Action;
+
+/**
+ * Welcome page
+ */
+class LoadExtensions extends Action\AbstractAction implements Action\ActionInterface {
+
+       /**
+        * Handle this action
+        *
+        * @return string content
+        */
+       public function handle() {
+               $this->initializeHandle();
+               $extensionCompatibilityTesterFile = \TYPO3\CMS\Core\Utility\GeneralUtility::getIndpEnv('TYPO3_SITE_URL') . 'typo3temp/ExtensionCompatibilityTester.txt';
+               $this->view->assign('extensionCompatibilityTesterProtocolFile', $extensionCompatibilityTesterFile);
+
+               return $this->view->render();
+       }
+}
+?>
index 2a35d6a..890ff14 100644 (file)
@@ -47,6 +47,7 @@ class ToolController extends AbstractController {
                'updateWizard',
                'allConfiguration',
                'cleanUp',
+               'loadExtensions',
        );
 
        /**
@@ -68,6 +69,7 @@ class ToolController extends AbstractController {
                $this->logoutIfRequested();
                $this->loginIfRequested();
                $this->outputLoginFormIfNotAuthorized();
+               $this->registerExtensionConfigurationErrorHandler();
                $this->dispatchAuthenticationActions();
        }
 
@@ -96,6 +98,56 @@ class ToolController extends AbstractController {
        }
 
        /**
+        * This function registers a shutdown function, which is called even if a fatal error occurs.
+        * The request either gets redirected to an action where all extension configurations are checked for compatibility or
+        * an information with a link to that action.
+        *
+        * @return void
+        */
+       protected function registerExtensionConfigurationErrorHandler() {
+               register_shutdown_function(function() {
+                       $error = error_get_last();
+                       if ($error !== NULL) {
+                               $errorType = $error["type"];
+
+                               if ($errorType & (E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR)) {
+                                       $getPostValues = \TYPO3\CMS\Core\Utility\GeneralUtility::_GP('install');
+
+                                       $parameters = array();
+
+                                       // Add context parameter in case this script was called within backend scope
+                                       $context = 'install[context]=standalone';
+                                       if (isset($getPostValues['context']) && $getPostValues['context'] === 'backend') {
+                                               $context = 'install[context]=backend';
+                                       }
+                                       $parameters[] = $context;
+
+                                       // Add controller parameter
+                                       $parameters[] = 'install[controller]=tool';
+
+                                       // Add action if specified
+                                       $parameters[] = 'install[action]=loadExtensions';
+
+                                       $redirectLocation = 'Install.php?' . implode('&', $parameters);
+
+                                       if (!headers_sent()) {
+                                               \TYPO3\CMS\Core\Utility\HttpUtility::redirect(
+                                                       $redirectLocation,
+                                                       \TYPO3\CMS\Core\Utility\HttpUtility::HTTP_STATUS_303
+                                               );
+                                       } else {
+                                               echo '
+<p><strong>
+       The system detected a fatal error during script execution.
+       Please use the <a href="' . $redirectLocation . '">extension check tool</a> to find incompatible extensions.
+</strong></p>';
+                                       }
+                               }
+                       }
+               });
+       }
+
+       /**
         * Call an action that needs authentication
         *
         * @throws Exception
diff --git a/typo3/sysext/install/Resources/Private/Templates/Action/Tool/LoadExtensions.html b/typo3/sysext/install/Resources/Private/Templates/Action/Tool/LoadExtensions.html
new file mode 100644 (file)
index 0000000..f736a6c
--- /dev/null
@@ -0,0 +1,26 @@
+<f:layout name="ToolAuthenticated" />
+
+<f:section name="Content">
+       <h3>Load extension configuration</h3>
+
+       <f:for each="{actionMessages}" as="statusMessage">
+               <f:render partial="Action/Common/StatusMessage" arguments="{message: statusMessage}" />
+       </f:for>
+
+       <p>
+               The system detected a fatal error during script execution and redirected to this module.
+               Your loaded extensions are now checked for possible problems. After incompatible extensions
+               are unloaded, you can restart the initial action to proceed your request.
+       </p>
+
+       <hr />
+       <f:render partial="Action/Tool/ImportantActions/ExtensionCompatibilityTester" arguments="{_all}"/>
+       <script type="text/javascript">
+               $(document).ready(function() {
+                       $('button', '#checkExtensions').hide();
+                       $('.typo3-message', '#checkExtensions').hide();
+                       $('.message-loading', '#checkExtensions').show();
+                       checkExtensionsCompatibility(true);
+               });
+       </script>
+</f:section>
\ No newline at end of file