plugin class exception handling

This commit is contained in:
kremsy 2014-01-18 10:42:19 +01:00 committed by Steffen Schröder
parent d173a48159
commit fb30706cd4
2 changed files with 52 additions and 44 deletions

View File

@ -5,8 +5,8 @@ namespace ManiaControl\Plugins;
require_once __DIR__ . '/Plugin.php';
require_once __DIR__ . '/PluginMenu.php';
use ManiaControl\ManiaControl;
use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
/**
@ -123,9 +123,10 @@ class PluginManager {
* Activate and start the plugin with the given name
*
* @param string $pluginClass
* @param string $adminLogin
* @return bool
*/
public function activatePlugin($pluginClass) {
public function activatePlugin($pluginClass, $adminLogin = false) {
if(!is_string($pluginClass)) {
return false;
}
@ -136,7 +137,14 @@ class PluginManager {
return false;
}
$plugin = new $pluginClass();
try {
$plugin->load($this->maniaControl);
} catch(\Exception $e) {
$this->maniaControl->chat->sendError('Error on Plugin activation ' . $e->getMessage(), $adminLogin);
$this->log('Error while plugin activation: ' . $e->getMessage());
return false;
}
$this->activePlugins[$pluginClass] = $plugin;
$this->savePluginStatus($pluginClass, true);
return true;

View File

@ -199,7 +199,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu {
}
if($enable) {
$pluginClass = substr($actionId, strlen(self::ACTION_PREFIX_ENABLEPLUGIN));
$activated = $this->maniaControl->pluginManager->activatePlugin($pluginClass);
$activated = $this->maniaControl->pluginManager->activatePlugin($pluginClass, $player->login);
if($activated) {
$this->maniaControl->chat->sendSuccess($pluginClass::getName() . ' activated!', $player->login);
$this->maniaControl->configurator->showMenu($player);