From 6eca1022337a491120f01095908f47a7c166a7e4 Mon Sep 17 00:00:00 2001 From: kremsy Date: Sat, 13 May 2017 11:50:50 +0200 Subject: [PATCH] update improvement for plugin files which had no matching names (if theres a new update available, the file will be deleted, theres a log written that you should restart MC and than install the new version). --- core/Plugins/PluginManager.php | 13 ++++++++++++- core/Update/PluginUpdateManager.php | 19 +++++++++++++------ 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/core/Plugins/PluginManager.php b/core/Plugins/PluginManager.php index e7b8ca83..1549fc50 100644 --- a/core/Plugins/PluginManager.php +++ b/core/Plugins/PluginManager.php @@ -11,6 +11,7 @@ use ManiaControl\Files\FileUtil; use ManiaControl\Logger; use ManiaControl\ManiaControl; use ManiaControl\Manialinks\ManialinkPageAnswerListener; +use ManiaControl\Update\PluginUpdateManager; use ManiaControl\Utils\ClassUtil; use ReflectionClass; @@ -128,7 +129,17 @@ class PluginManager { $className = end($splitNameSpace); } if (FileUtil::getFileName($reflector->getFileName()) != $className) { - Logger::logError("Plugin ClassName does not match FileName; Plugin: " . $className); + $updateAvailable = PluginUpdateManager::getPluginUpdate($pluginClass, true); + Logger::logError("FileName does not match Plugin ClassName; Plugin: " . $className); + + if ($updateAvailable) { + //Update Is available, plugin will be deleted + unlink($reflector->getFileName()); + $message = "There is a new version of " . $className . " available, restart ManiaControl and install the new version after from the Install Plugins Menu!"; + Logger::log($message); + Logger::log("File " . $className . " will be deleted!"); + //TODO maybe a better solution, throw exception here and do stuff automatically + } return false; } diff --git a/core/Update/PluginUpdateManager.php b/core/Update/PluginUpdateManager.php index d77c30f2..3220464f 100644 --- a/core/Update/PluginUpdateManager.php +++ b/core/Update/PluginUpdateManager.php @@ -257,7 +257,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis Logger::logError($message); return; } - + $asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $pluginUpdateData->url); $asyncHttpRequest->setCallable(function ($updateFileContent, $error) use ( &$pluginUpdateData, &$player, &$update @@ -322,8 +322,9 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis if (!$update) { $newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins(); + if (empty($newPluginClasses)) { - $message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!"; + $message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed, try to restart ManiaControl!"; if ($player) { $this->maniaControl->getChat()->sendError($message, $player); } @@ -405,10 +406,15 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis * Check given Plugin Class for Update * * @param string $pluginClass + * @param bool $skipPluginClassFetch * @return mixed - */ - public function getPluginUpdate($pluginClass) { - $pluginClass = PluginManager::getPluginClass($pluginClass); + **/ + public static function getPluginUpdate($pluginClass, $skipPluginClassFetch = false) { + if (!$skipPluginClassFetch) { + //Used to avoid recursion in the isPluginClass Method + $pluginClass = PluginManager::getPluginClass($pluginClass); + } + /** @var Plugin $pluginClass */ $pluginId = $pluginClass::getId(); $url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId; @@ -420,7 +426,8 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis } $pluginUpdateData = new PluginUpdateData($pluginVersion); $version = $pluginClass::getVersion(); - if ($pluginUpdateData->isNewerThan($version)) { + + if ($pluginUpdateData->isNewerThan($version) && $pluginUpdateData->minManiaControlVersion >= ManiaControl::VERSION) { return $pluginUpdateData; } return false;