From 75b1e2155a959658423319993d37a2ba255dc475 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Steffen=20Schro=CC=88der?= Date: Mon, 28 Apr 2014 14:14:04 +0200 Subject: [PATCH] setting for disabling automatic mc restart --- application/core/Database/MigrationHelper.php | 2 -- application/core/ErrorHandler.php | 35 +++++++++++++++---- application/core/ManiaControl.php | 2 ++ 3 files changed, 30 insertions(+), 9 deletions(-) diff --git a/application/core/Database/MigrationHelper.php b/application/core/Database/MigrationHelper.php index 9accc25a..fcc074a9 100644 --- a/application/core/Database/MigrationHelper.php +++ b/application/core/Database/MigrationHelper.php @@ -38,8 +38,6 @@ class MigrationHelper { $sourceClass = $this->getClass($sourceClass); $targetClass = $this->getClass($targetClass); - var_dump($sourceClass, $targetClass); - $mysqli = $this->maniaControl->database->mysqli; $query = "INSERT INTO `" . SettingManager::TABLE_SETTINGS . "` (`class`, `setting`, `type`, `value`, `default`) diff --git a/application/core/ErrorHandler.php b/application/core/ErrorHandler.php index 9d55c463..646eae83 100644 --- a/application/core/ErrorHandler.php +++ b/application/core/ErrorHandler.php @@ -4,6 +4,7 @@ namespace ManiaControl; use ManiaControl\Files\FileUtil; use ManiaControl\Update\UpdateManager; +use ManiaControl\Callbacks\Callbacks; /** * Error and Exception Manager Class @@ -17,6 +18,7 @@ class ErrorHandler { * Constants */ const MC_DEBUG_NOTICE = "ManiaControl.DebugNotice"; + const SETTING_RESTART_ON_EXCEPTION = 'Automatically restart on Exceptions'; /* * Private Properties @@ -33,6 +35,13 @@ class ErrorHandler { set_exception_handler(array(&$this, 'exceptionHandler')); } + /** + * Initialize other Error Handler Features + */ + public function init() { + $this->maniaControl->settingManager->initSetting($this, self::SETTING_RESTART_ON_EXCEPTION, true); + } + /** * ManiaControl ExceptionHandler * ManiaControl Shuts down after exception @@ -62,8 +71,7 @@ class ErrorHandler { } if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) { - $error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, - UpdateManager::SETTING_UPDATECHECK_CHANNEL); + $error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL); $error['ManiaControlVersion'] = $this->maniaControl->updateManager->getCurrentBuildDate(); } else { @@ -85,7 +93,9 @@ class ErrorHandler { } } - $this->maniaControl->restart(); + if ($this->shouldRestart()) { + $this->maniaControl->restart(); + } exit(); } @@ -104,8 +114,7 @@ class ErrorHandler { return false; } - $userError = ($errorNumber == E_USER_ERROR || $errorNumber == E_USER_WARNING || $errorNumber == E_USER_NOTICE || - $errorNumber == E_USER_DEPRECATED); + $userError = ($errorNumber == E_USER_ERROR || $errorNumber == E_USER_WARNING || $errorNumber == E_USER_NOTICE || $errorNumber == E_USER_DEPRECATED); // Log error $errorTag = $this->getErrorTag($errorNumber); @@ -129,8 +138,7 @@ class ErrorHandler { } if ($this->maniaControl->settingManager && $this->maniaControl->updateManager) { - $error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, - UpdateManager::SETTING_UPDATECHECK_CHANNEL); + $error['UpdateChannel'] = $this->maniaControl->settingManager->getSetting($this->maniaControl->updateManager, UpdateManager::SETTING_UPDATECHECK_CHANNEL); $error['ManiaControlVersion'] = $this->maniaControl->updateManager->getCurrentBuildDate(); } else { @@ -208,6 +216,19 @@ class ErrorHandler { return "[PHP {$errorLevel}]"; } + /** + * Test if ManiaControl should restart automatically + * + * @return bool + */ + private function shouldRestart() { + if (!$this->maniaControl || !$this->maniaControl->settingManager) { + return false; + } + $setting = $this->maniaControl->settingManager->getSetting($this, self::SETTING_RESTART_ON_EXCEPTION, true); + return $setting; + } + /** * Parse the Debug Backtrace into a String for the Error Report * diff --git a/application/core/ManiaControl.php b/application/core/ManiaControl.php index 381f549a..86df22d7 100644 --- a/application/core/ManiaControl.php +++ b/application/core/ManiaControl.php @@ -130,6 +130,8 @@ class ManiaControl implements CommandListener, TimerListener { //Check connection every 30 seconds $this->timerManager->registerTimerListening($this, 'checkConnection', 1000 * 30); + + $this->errorHandler->init(); } /**