improved plugin activation code

This commit is contained in:
Steffen Schröder 2014-05-04 16:53:36 +02:00
parent 5219e0206c
commit 32889034a0

View File

@ -329,31 +329,26 @@ class PluginManager {
* @return bool * @return bool
*/ */
public function activatePlugin($pluginClass, $adminLogin = null) { public function activatePlugin($pluginClass, $adminLogin = null) {
if (!is_string($pluginClass)) {
return false;
}
if (!$this->isPluginClass($pluginClass)) { if (!$this->isPluginClass($pluginClass)) {
return false; return false;
} }
if ($this->isPluginActive($pluginClass)) { if ($this->isPluginActive($pluginClass)) {
return false; return false;
} }
/** @var Plugin $plugin */
$plugin = new $pluginClass(); $plugin = new $pluginClass();
/**
* @var Plugin $plugin
*/
$this->activePlugins[$pluginClass] = $plugin;
$this->savePluginStatus($pluginClass, true);
try { try {
$plugin->load($this->maniaControl); $plugin->load($this->maniaControl);
} catch (\Exception $e) { } catch (\Exception $e) {
$this->maniaControl->chat->sendError('Error while plugin activating ' . $pluginClass . ': ' . $e->getMessage(), $adminLogin); $message = "Error during Plugin Activation of '{$pluginClass}': '{$e->getMessage()}'";
$this->maniaControl->log('Error while plugin activation: ' . $pluginClass . ': ' . $e->getMessage()); $this->maniaControl->chat->sendError($message, $adminLogin);
unset($this->activePlugins[$pluginClass]); $this->maniaControl->log($message);
$this->savePluginStatus($pluginClass, false); $this->savePluginStatus($pluginClass, false);
return false; return false;
} }
$this->activePlugins[$pluginClass] = $plugin;
$this->savePluginStatus($pluginClass, true); $this->savePluginStatus($pluginClass, true);
return true; return true;
} }