[TASK] Install tool: Remove fatal error handling 04/53804/4
authorChristian Kuhn <lolli@schwarzbu.ch>
Thu, 24 Aug 2017 22:11:57 +0000 (00:11 +0200)
committerSusanne Moog <susanne.moog@typo3.org>
Fri, 25 Aug 2017 08:46:09 +0000 (10:46 +0200)
Before refactoring of the install tool with #76084, a
'fatal error handler' was in place to redirect to the
extension checker if a fatal php error was detected
during one of the main "tool" actions.
Now, the main controllers of the install tool never
load non-core extension data anymore, those can't
fail due to issues with specific ext_localconf.php or
ext_tables.php files. This extension loading now happens
only in ajax actions and thus can't kill the whole install
tool anymore.
Left over error handler code is removed from the
ToolController with this patch.

Change-Id: I0d0398f7b66a6a2c64dec48fe60a722698688a59
Resolves: #82200
Related: #76084
Releases: master
Reviewed-on: https://review.typo3.org/53804
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/install/Classes/Controller/Action/AbstractAction.php
typo3/sysext/install/Classes/Controller/Action/ActionInterface.php
typo3/sysext/install/Classes/Controller/ToolController.php
typo3/sysext/install/Resources/Private/Partials/Action/Tool/Maintenance/LastError.html [deleted file]

index 3d544bf..0bbfde1 100644 (file)
@@ -48,11 +48,6 @@ abstract class AbstractAction implements ActionInterface
     protected $postValues = [];
 
     /**
-     * @var array Contains the fatal error array of the last request when passed. Schema is the one returned by error_get_last()
-     */
-    protected $lastError = [];
-
-    /**
      * @var array<\TYPO3\CMS\Install\Status\StatusInterface> Optional status message from controller
      */
     protected $messages = [];
@@ -92,7 +87,6 @@ abstract class AbstractAction implements ActionInterface
             ->assign('token', $this->token)
             ->assign('context', $contextService->getContextString())
             ->assign('contextService', $contextService)
-            ->assign('lastError', $this->lastError)
             ->assign('messages', $this->messages)
             ->assign('typo3Version', TYPO3_version)
             ->assign('siteName', $GLOBALS['TYPO3_CONF_VARS']['SYS']['sitename']);
@@ -147,16 +141,6 @@ abstract class AbstractAction implements ActionInterface
     }
 
     /**
-     * Set the last error array as returned by error_get_last()
-     *
-     * @param array $lastError
-     */
-    public function setLastError(array $lastError)
-    {
-        $this->lastError = $lastError;
-    }
-
-    /**
      * Status messages from controller
      *
      * @param array<\TYPO3\CMS\Install\Status\StatusInterface> $messages
index 68e22e4..01f5e2f 100644 (file)
@@ -56,13 +56,6 @@ interface ActionInterface
     public function setPostValues(array $postValues);
 
     /**
-     * Set the last error array as returned by error_get_last()
-     *
-     * @param array $lastError
-     */
-    public function setLastError(array $lastError);
-
-    /**
      * Status messages from controller
      *
      * @param array<\TYPO3\CMS\Install\Status\StatusInterface> $messages
index 1fc97a5..0f03dc2 100644 (file)
@@ -14,7 +14,6 @@ namespace TYPO3\CMS\Install\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
-use TYPO3\CMS\Core\Utility\GeneralUtility;
 use TYPO3\CMS\Install\Service\EnableFileService;
 
 /**
@@ -52,7 +51,6 @@ class ToolController extends AbstractController
         $this->logoutIfRequested();
         $this->loginIfRequested();
         $this->outputLoginFormIfNotAuthorized();
-        $this->registerExtensionConfigurationErrorHandler();
         $this->dispatchAuthenticationActions();
     }
 
@@ -78,80 +76,6 @@ 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.
-     */
-    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 = [];
-
-                    // 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';
-
-                    // Add error to display a message what triggered the check
-                    $errorEncoded = json_encode($error);
-                    $parameters[] = 'install[lastError]=' . rawurlencode($errorEncoded);
-
-                    // We do not use GeneralUtility here to be sure that hash generation works even if that class might not exist any more.
-                    $parameters[] = 'install[lastErrorHash]=' . hash_hmac('sha1', $errorEncoded, $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . 'InstallToolError');
-
-                    $redirectLocation = GeneralUtility::getIndpEnv('TYPO3_REQUEST_SCRIPT') . '?' . 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>';
-                    }
-                }
-            }
-        });
-    }
-
-    /**
-     * Get last error values of install tool.
-     *
-     * @return array
-     */
-    protected function getLastError()
-    {
-        $getVars = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('install');
-        $lastError = [];
-        if (isset($getVars['lastError']) && isset($getVars['lastErrorHash']) && !empty($GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'])) {
-            $calculatedHash = hash_hmac('sha1', $getVars['lastError'], $GLOBALS['TYPO3_CONF_VARS']['SYS']['encryptionKey'] . 'InstallToolError');
-            if ($calculatedHash === $getVars['lastErrorHash']) {
-                $lastError = json_decode($getVars['lastError'], true);
-            }
-        }
-        return $lastError;
-    }
-
-    /**
      * Call an action that needs authentication
      *
      * @throws Exception
@@ -177,7 +101,6 @@ class ToolController extends AbstractController
         $toolAction->setAction($action);
         $toolAction->setToken($this->generateTokenForAction($action));
         $toolAction->setPostValues($this->getPostValues());
-        $toolAction->setLastError($this->getLastError());
         $this->output($toolAction->handle());
     }
 }
diff --git a/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Maintenance/LastError.html b/typo3/sysext/install/Resources/Private/Partials/Action/Tool/Maintenance/LastError.html
deleted file mode 100644 (file)
index fe1d4f8..0000000
+++ /dev/null
@@ -1,12 +0,0 @@
-<f:if condition="{lastError}">
-       <div class="typo3-message message-warning">
-               <div class="header-container">
-                       <div class="message-header">
-                               <strong>Detected Fatal Error</strong>
-                       </div>
-                       <div class="message-body">
-                               {lastError.message} in {lastError.file} on line {lastError.line}
-                       </div>
-               </div>
-       </div>
-</f:if>
\ No newline at end of file