From 8760364d826c72acb88346cc491a63a25ba09b9d Mon Sep 17 00:00:00 2001 From: Alexander Nell Date: Tue, 19 May 2020 20:48:56 +0200 Subject: [PATCH] Deactivate a plugin, if it throws an exception --- core/ErrorHandler.php | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/core/ErrorHandler.php b/core/ErrorHandler.php index 05de9916..d139e481 100644 --- a/core/ErrorHandler.php +++ b/core/ErrorHandler.php @@ -122,13 +122,12 @@ class ErrorHandler { $report['FileLine'] = self::stripBaseDir($fileLine); } - if ($sourceClass) { $report['SourceClass'] = $sourceClass; $pluginId = PluginManager::getPluginId($sourceClass); if ($pluginId > 0) { $report['PluginId'] = $pluginId; - + $report['PluginVersion'] = PluginManager::getPluginVersion($sourceClass); if ($isFatalError) { $this->maniaControl->getPluginManager()->deactivatePlugin($sourceClass); @@ -137,9 +136,6 @@ class ErrorHandler { $isPluginError = true; } } - - $report['PluginId'] = $pluginId; - $report['PluginVersion'] = PluginManager::getPluginVersion($sourceClass); } if ($traceString) { @@ -478,9 +474,19 @@ class ErrorHandler { $report['Message'] = $message; $report['Class'] = $exceptionClass; $report['FileLine'] = self::stripBaseDir($exception->getFile()) . ': ' . $exception->getLine(); - $report['SourceClass'] = $sourceClass; - $report['PluginId'] = PluginManager::getPluginId($sourceClass); - $report['PluginVersion'] = PluginManager::getPluginVersion($sourceClass); + if ($sourceClass) { + $report['SourceClass'] = $sourceClass; + $pluginId = PluginManager::getPluginId($sourceClass); + if ($pluginId > 0) { + $report['PluginId'] = $pluginId; + $report['PluginVersion'] = PluginManager::getPluginVersion($sourceClass); + + $this->maniaControl->getPluginManager()->deactivatePlugin($sourceClass); + $this->maniaControl->getChat()->sendError("Plugin " . $sourceClass . " has an Error -> The Plugin will be deactivated and ManiaControl restarted"); + Logger::logError("Plugin " . $sourceClass . " has an Error -> The Plugin will be deactivated and ManiaControl restarted"); + } + } + $report['Backtrace'] = $traceString; $report['OperatingSystem'] = php_uname(); $report['PHPVersion'] = phpversion();