proper unregistering of deactivated plugins
This commit is contained in:
parent
2befc24d17
commit
cf78a2a141
@ -5,6 +5,8 @@ namespace ManiaControl\Plugins;
|
||||
use ManiaControl\Callbacks\CallbackListener;
|
||||
use ManiaControl\ManiaControl;
|
||||
use ManiaControl\Manialinks\ManialinkPageAnswerListener;
|
||||
use ManiaControl\Callbacks\TimerListener;
|
||||
use ManiaControl\Commands\CommandListener;
|
||||
|
||||
/**
|
||||
* Class managing Plugins
|
||||
@ -135,12 +137,15 @@ class PluginManager {
|
||||
return false;
|
||||
}
|
||||
$plugin = new $pluginClass();
|
||||
/** @var Plugin $plugin */
|
||||
/**
|
||||
* @var Plugin $plugin
|
||||
*/
|
||||
$this->activePlugins[$pluginClass] = $plugin;
|
||||
$this->savePluginStatus($pluginClass, true);
|
||||
try {
|
||||
$plugin->load($this->maniaControl);
|
||||
} catch(\Exception $e) {
|
||||
}
|
||||
catch (\Exception $e) {
|
||||
$this->maniaControl->chat->sendError('Error while plugin activating ' . $pluginClass . ': ' . $e->getMessage(), $adminLogin);
|
||||
$this->maniaControl->log('Error while plugin activation: ' . $pluginClass . ': ' . $e->getMessage());
|
||||
unset($this->activePlugins[$pluginClass]);
|
||||
@ -164,16 +169,24 @@ class PluginManager {
|
||||
return false;
|
||||
}
|
||||
$plugin = $this->activePlugins[$pluginClass];
|
||||
/** @var Plugin $plugin */
|
||||
unset($this->activePlugins[$pluginClass]);
|
||||
/**
|
||||
* @var Plugin $plugin
|
||||
*/
|
||||
$plugin->unload();
|
||||
unset($this->activePlugins[$pluginClass]);
|
||||
if ($plugin instanceof CallbackListener) {
|
||||
$this->maniaControl->callbackManager->unregisterCallbackListener($plugin);
|
||||
$this->maniaControl->callbackManager->unregisterScriptCallbackListener($plugin);
|
||||
}
|
||||
if ($plugin instanceof CommandListener) {
|
||||
$this->maniaControl->commandManager->unregisterCommandListener($plugin);
|
||||
}
|
||||
if ($plugin instanceof ManialinkPageAnswerListener) {
|
||||
$this->maniaControl->manialinkManager->unregisterManialinkPageAnswerListener($plugin);
|
||||
}
|
||||
if ($plugin instanceof TimerListener) {
|
||||
$this->maniaControl->timerManager->unregisterTimerListenings($plugin);
|
||||
}
|
||||
$this->savePluginStatus($pluginClass, false);
|
||||
return true;
|
||||
}
|
||||
@ -189,7 +202,7 @@ class PluginManager {
|
||||
$classesAfter = get_declared_classes();
|
||||
|
||||
$newClasses = array_diff($classesAfter, $classesBefore);
|
||||
foreach($newClasses as $className) {
|
||||
foreach ($newClasses as $className) {
|
||||
if (!$this->isPluginClass($className)) {
|
||||
continue;
|
||||
}
|
||||
@ -215,7 +228,7 @@ class PluginManager {
|
||||
*/
|
||||
public function loadPluginFiles($directory = '') {
|
||||
$pluginFiles = scandir($directory);
|
||||
foreach($pluginFiles as $pluginFile) {
|
||||
foreach ($pluginFiles as $pluginFile) {
|
||||
if (stripos($pluginFile, '.') === 0) {
|
||||
continue;
|
||||
}
|
||||
@ -347,7 +360,7 @@ class PluginManager {
|
||||
public function fetchPluginList($function) {
|
||||
$url = ManiaControl::URL_WEBSERVICE . 'plugins';
|
||||
|
||||
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use (&$function) {
|
||||
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use(&$function) {
|
||||
$data = json_decode($dataJson);
|
||||
call_user_func($function, $data, $error);
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user