diff options
-rw-r--r-- | index.php | 13 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/Controller.php | 40 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/templates/macros.twig | 3 | ||||
-rw-r--r-- | plugins/CorePluginsAdmin/templates/safemode.twig | 61 |
4 files changed, 115 insertions, 2 deletions
@@ -52,6 +52,19 @@ if (!defined('PIWIK_ENABLE_ERROR_HANDLER') || PIWIK_ENABLE_ERROR_HANDLER) { ExceptionHandler::setUp(); } +register_shutdown_function(function () { + + $lastError = error_get_last(); + + if (!empty($lastError) && $lastError['type'] == E_ERROR) { + $controller = FrontController::getInstance(); + $controller->init(); + $message = $controller->dispatch('CorePluginsAdmin', 'safemode', array($lastError)); + + echo $message; + } +}); + if (!defined('PIWIK_ENABLE_DISPATCH') || PIWIK_ENABLE_DISPATCH) { $controller = FrontController::getInstance(); $controller->init(); diff --git a/plugins/CorePluginsAdmin/Controller.php b/plugins/CorePluginsAdmin/Controller.php index 4ecc22d184..dd80a86a8b 100644 --- a/plugins/CorePluginsAdmin/Controller.php +++ b/plugins/CorePluginsAdmin/Controller.php @@ -21,6 +21,7 @@ use Piwik\Plugin; use Piwik\Settings\Manager as SettingsManager; use Piwik\Url; use Piwik\View; +use Exception; /** * @package CorePluginsAdmin @@ -310,6 +311,45 @@ class Controller extends Plugin\ControllerAdmin return $pluginsFiltered; } + public function safemode($lastError) + { + $outputFormat = Common::getRequestVar('format', 'html', 'string'); + $outputFormat = strtolower($outputFormat); + + if (!empty($outputFormat) && 'html' !== $outputFormat) { + + $errorMessage = $lastError['message']; + + if (Piwik::isUserIsAnonymous()) { + $errorMessage = 'A fatal error occurred.'; + } + + $response = new \Piwik\API\ResponseBuilder($outputFormat); + $message = $response->getResponseException(new Exception($errorMessage)); + + return $message; + } + + $view = new View('@CorePluginsAdmin/safemode'); + $view->lastError = $lastError; + $view->isSuperUser = Piwik::isUserIsSuperUser(); + $view->isAnonymousUser = Piwik::isUserIsAnonymous(); + $view->plugins = Plugin\Manager::getInstance()->returnLoadedPluginsInfo(); + $view->deactivateNonce = Nonce::getNonce(static::DEACTIVATE_NONCE); + $view->uninstallNonce = Nonce::getNonce(static::UNINSTALL_NONCE); + $view->pluginCausesIssue = ''; + + if (!empty($lastError['file'])) { + preg_match('/piwik\/plugins\/(.*)\//', $lastError['file'], $matches); + + if (!empty($matches[1])) { + $view->pluginCausesIssue = $matches[1]; + } + } + + return $view->render(); + } + public function deactivate($redirectAfter = true) { $pluginName = $this->initPluginModification(static::DEACTIVATE_NONCE); diff --git a/plugins/CorePluginsAdmin/templates/macros.twig b/plugins/CorePluginsAdmin/templates/macros.twig index 2a71be2f8a..fd775c4c59 100644 --- a/plugins/CorePluginsAdmin/templates/macros.twig +++ b/plugins/CorePluginsAdmin/templates/macros.twig @@ -146,8 +146,7 @@ {{ 'CorePluginsAdmin_Active'|translate }} {% else %} {{ 'CorePluginsAdmin_Inactive'|translate }} <br/> - - {% if plugin.uninstallable %}<a data-pluginName="{{ name|escape('html_attr') }}" class="uninstall" href='index.php?module=CorePluginsAdmin&action=uninstall&pluginName={{ name }}&nonce={{ - uninstallNonce }}'>{{ 'CorePluginsAdmin_ActionUninstall'|translate }}</a>{% endif %} + - {% if plugin.uninstallable %}<a data-pluginName="{{ name|escape('html_attr') }}" class="uninstall" href='index.php?module=CorePluginsAdmin&action=uninstall&pluginName={{ name }}&nonce={{ uninstallNonce }}'>{{ 'CorePluginsAdmin_ActionUninstall'|translate }}</a>{% endif %} {% endif %} </td> diff --git a/plugins/CorePluginsAdmin/templates/safemode.twig b/plugins/CorePluginsAdmin/templates/safemode.twig new file mode 100644 index 0000000000..54d2b3c7b4 --- /dev/null +++ b/plugins/CorePluginsAdmin/templates/safemode.twig @@ -0,0 +1,61 @@ +<h1>An error occurred</h1> + +<div style="width: 640px"> + +{% if not isAnonymousUser %} + <p> + The following error just broke Piwik: + <pre>{{ lastError.message }}</pre> + + in + <pre>{{ lastError.file }} line {{ lastError.line }}</pre> + </p> +{% endif %} + +{% if isSuperUser %} + <p> + If this error continues to happen, there is a good chance to fix this issue by disabling one or more of + the Third-Party plugins. You can enable them again in the + <a target="_blank" href="#">Plugins</a> or <a target="_blank" href="#">Themes</a> page under + settings at any time. + + {% if pluginCausesIssue %} + Based on the error message, the issue is probably caused by the plugin <strong>{{ pluginCausesIssue }}</strong>. + {% endif %} + </p> + + <table border="1"> + {% for pluginName, plugin in plugins if plugin.uninstallable %} + <tr> + <td style="min-width:200px"> + {{ pluginName }} + </td> + <td> + {% if plugin.activated %} + <a href="index.php?module=CorePluginsAdmin&action=deactivate&pluginName={{ pluginName }}&nonce={{ deactivateNonce }}" + target="_blank">deactivate</a> + {% else %} + <a href="index.php?module=CorePluginsAdmin&action=uninstall&pluginName={{ pluginName }}&nonce={{ uninstallNonce }}" + target="_blank">uninstall</a> + {% endif %} + </td> + </tr> + {% endfor %} + </table> + + <p> + We appreciate if you send the + <a href="mailto:xxx?subject=Fatal%20Error20%in%20Piwik&body=MESSAGE.FILE.LINE">error report</a> + to the Piwik team. + </p> + +{% elseif isAnonymousUser %} + + <p>Please contact the system administrator.</p> + +{% else %} + <p>If this error continues to happen you may want to inform your system administrator + about this incident: <a href="mailto: xxx?subject=Fatal%20Error20%in%20Piwik&body=MESSAGE.FILE.LINE"></a></p> +{% endif %} + +</div>
\ No newline at end of file |