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