deactivate plugins that throw a fatal error
made some methods static
This commit is contained in:
		| @@ -84,7 +84,8 @@ class ErrorHandler { | |||||||
|  |  | ||||||
| 		// Build log message | 		// Build log message | ||||||
| 		$errorTag     = $this->getErrorTag($errorNumber); | 		$errorTag     = $this->getErrorTag($errorNumber); | ||||||
| 		$userError = $this->isUserErrorNumber($errorNumber); | 		$isUserError  = self::isUserErrorNumber($errorNumber); | ||||||
|  | 		$isFatalError = self::isFatalError($errorNumber); | ||||||
|  |  | ||||||
| 		$traceString      = null; | 		$traceString      = null; | ||||||
| 		$sourceClass      = null; | 		$sourceClass      = null; | ||||||
| @@ -104,22 +105,28 @@ class ErrorHandler { | |||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		$logMessage = $message . PHP_EOL . 'File&Line: ' . $fileLine; | 		$logMessage = $message . PHP_EOL . 'File&Line: ' . $fileLine; | ||||||
| 		if (!$userError && $traceString) { | 		if (!$isUserError && $traceString) { | ||||||
| 			$logMessage .= PHP_EOL . 'Trace: ' . PHP_EOL . $traceString; | 			$logMessage .= PHP_EOL . 'Trace: ' . PHP_EOL . $traceString; | ||||||
| 		} | 		} | ||||||
| 		$this->maniaControl->log($logMessage); | 		$this->maniaControl->log($logMessage); | ||||||
|  |  | ||||||
| 		if (!DEV_MODE && !$userError && !$suppressed) { | 		if (!DEV_MODE && !$isUserError && !$suppressed) { | ||||||
| 			// Report error | 			// Report error | ||||||
| 			$report            = array(); | 			$report            = array(); | ||||||
| 			$report['Type']    = 'Error'; | 			$report['Type']    = 'Error'; | ||||||
| 			$report['Message'] = $message; | 			$report['Message'] = $message; | ||||||
| 			if ($fileLine) { | 			if ($fileLine) { | ||||||
| 				$report['FileLine'] = $this->stripBaseDir($fileLine); | 				$report['FileLine'] = self::stripBaseDir($fileLine); | ||||||
| 			} | 			} | ||||||
| 			if ($sourceClass) { | 			if ($sourceClass) { | ||||||
| 				$report['SourceClass'] = $sourceClass; | 				$report['SourceClass'] = $sourceClass; | ||||||
| 				$report['PluginId']    = PluginManager::getPluginId($sourceClass); | 				$pluginId              = PluginManager::getPluginId($sourceClass); | ||||||
|  | 				if ($pluginId > 0) { | ||||||
|  | 					$report['PluginId'] = $pluginId; | ||||||
|  | 					if ($isFatalError) { | ||||||
|  | 						$this->maniaControl->pluginManager->deactivatePlugin($sourceClass); | ||||||
|  | 					} | ||||||
|  | 				} | ||||||
| 			} | 			} | ||||||
| 			if ($traceString) { | 			if ($traceString) { | ||||||
| 				$report['Backtrace'] = $traceString; | 				$report['Backtrace'] = $traceString; | ||||||
| @@ -152,7 +159,7 @@ class ErrorHandler { | |||||||
| 			} | 			} | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| 		if (self::isFatalError($errorNumber)) { | 		if ($isFatalError) { | ||||||
| 			$this->maniaControl->quit('Quitting ManiaControl after Fatal Error.'); | 			$this->maniaControl->quit('Quitting ManiaControl after Fatal Error.'); | ||||||
| 		} | 		} | ||||||
|  |  | ||||||
| @@ -202,11 +209,22 @@ class ErrorHandler { | |||||||
| 	 * @param int $errorNumber | 	 * @param int $errorNumber | ||||||
| 	 * @return bool | 	 * @return bool | ||||||
| 	 */ | 	 */ | ||||||
| 	private function isUserErrorNumber($errorNumber) { | 	private static function isUserErrorNumber($errorNumber) { | ||||||
| 		return ($errorNumber & E_USER_ERROR || $errorNumber & E_USER_WARNING || $errorNumber & E_USER_NOTICE | 		return ($errorNumber & E_USER_ERROR || $errorNumber & E_USER_WARNING || $errorNumber & E_USER_NOTICE | ||||||
| 		        || $errorNumber & E_USER_DEPRECATED); | 		        || $errorNumber & E_USER_DEPRECATED); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | 	/** | ||||||
|  | 	 * Test whether the given Error Number represents a Fatal Error | ||||||
|  | 	 * | ||||||
|  | 	 * @param int $errorNumber | ||||||
|  | 	 * @return bool | ||||||
|  | 	 */ | ||||||
|  | 	public static function isFatalError($errorNumber) { | ||||||
|  | 		$fatalError = (E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR); | ||||||
|  | 		return ($errorNumber & $fatalError); | ||||||
|  | 	} | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Parse the Debug Backtrace into a String for the Error Report | 	 * Parse the Debug Backtrace into a String for the Error Report | ||||||
| 	 * | 	 * | ||||||
| @@ -238,7 +256,7 @@ class ErrorHandler { | |||||||
| 			} | 			} | ||||||
| 			if (isset($traceStep['file']) && !$skipStep) { | 			if (isset($traceStep['file']) && !$skipStep) { | ||||||
| 				$traceString .= ' in File '; | 				$traceString .= ' in File '; | ||||||
| 				$traceString .= $this->stripBaseDir($traceStep['file']); | 				$traceString .= self::stripBaseDir($traceStep['file']); | ||||||
| 			} | 			} | ||||||
| 			if (isset($traceStep['line']) && !$skipStep) { | 			if (isset($traceStep['line']) && !$skipStep) { | ||||||
| 				$traceString .= ' on Line '; | 				$traceString .= ' on Line '; | ||||||
| @@ -343,7 +361,7 @@ class ErrorHandler { | |||||||
| 	 * @param string $path | 	 * @param string $path | ||||||
| 	 * @return string | 	 * @return string | ||||||
| 	 */ | 	 */ | ||||||
| 	private function stripBaseDir($path) { | 	private static function stripBaseDir($path) { | ||||||
| 		return str_replace(ManiaControlDir, '', $path); | 		return str_replace(ManiaControlDir, '', $path); | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -368,17 +386,6 @@ class ErrorHandler { | |||||||
| 		return $className; | 		return $className; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	/** |  | ||||||
| 	 * Test whether the given Error Number represents a Fatal Error |  | ||||||
| 	 * |  | ||||||
| 	 * @param int $errorNumber |  | ||||||
| 	 * @return bool |  | ||||||
| 	 */ |  | ||||||
| 	public static function isFatalError($errorNumber) { |  | ||||||
| 		$fatalError = (E_ERROR | E_PARSE | E_CORE_ERROR | E_COMPILE_ERROR | E_USER_ERROR | E_RECOVERABLE_ERROR); |  | ||||||
| 		return ($errorNumber & $fatalError); |  | ||||||
| 	} |  | ||||||
|  |  | ||||||
| 	/** | 	/** | ||||||
| 	 * Handle PHP Process Shutdown | 	 * Handle PHP Process Shutdown | ||||||
| 	 */ | 	 */ | ||||||
| @@ -433,7 +440,7 @@ class ErrorHandler { | |||||||
| 			$report['Type']            = 'Exception'; | 			$report['Type']            = 'Exception'; | ||||||
| 			$report['Message']         = $message; | 			$report['Message']         = $message; | ||||||
| 			$report['Class']           = $exceptionClass; | 			$report['Class']           = $exceptionClass; | ||||||
| 			$report['FileLine']        = $this->stripBaseDir($exception->getFile()) . ': ' . $exception->getLine(); | 			$report['FileLine']        = self::stripBaseDir($exception->getFile()) . ': ' . $exception->getLine(); | ||||||
| 			$report['SourceClass']     = $sourceClass; | 			$report['SourceClass']     = $sourceClass; | ||||||
| 			$report['PluginId']        = PluginManager::getPluginId($sourceClass); | 			$report['PluginId']        = PluginManager::getPluginId($sourceClass); | ||||||
| 			$report['Backtrace']       = $traceString; | 			$report['Backtrace']       = $traceString; | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user