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).

This commit is contained in:
kremsy 2017-05-13 11:50:50 +02:00
parent 6908ff36e4
commit 6eca102233
2 changed files with 25 additions and 7 deletions

View File

@ -11,6 +11,7 @@ use ManiaControl\Files\FileUtil;
use ManiaControl\Logger; use ManiaControl\Logger;
use ManiaControl\ManiaControl; use ManiaControl\ManiaControl;
use ManiaControl\Manialinks\ManialinkPageAnswerListener; use ManiaControl\Manialinks\ManialinkPageAnswerListener;
use ManiaControl\Update\PluginUpdateManager;
use ManiaControl\Utils\ClassUtil; use ManiaControl\Utils\ClassUtil;
use ReflectionClass; use ReflectionClass;
@ -128,7 +129,17 @@ class PluginManager {
$className = end($splitNameSpace); $className = end($splitNameSpace);
} }
if (FileUtil::getFileName($reflector->getFileName()) != $className) { 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; return false;
} }

View File

@ -322,8 +322,9 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
if (!$update) { if (!$update) {
$newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins(); $newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins();
if (empty($newPluginClasses)) { 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) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
@ -405,10 +406,15 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
* Check given Plugin Class for Update * Check given Plugin Class for Update
* *
* @param string $pluginClass * @param string $pluginClass
* @param bool $skipPluginClassFetch
* @return mixed * @return mixed
*/ **/
public function getPluginUpdate($pluginClass) { public static function getPluginUpdate($pluginClass, $skipPluginClassFetch = false) {
if (!$skipPluginClassFetch) {
//Used to avoid recursion in the isPluginClass Method
$pluginClass = PluginManager::getPluginClass($pluginClass); $pluginClass = PluginManager::getPluginClass($pluginClass);
}
/** @var Plugin $pluginClass */ /** @var Plugin $pluginClass */
$pluginId = $pluginClass::getId(); $pluginId = $pluginClass::getId();
$url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId; $url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId;
@ -420,7 +426,8 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
} }
$pluginUpdateData = new PluginUpdateData($pluginVersion); $pluginUpdateData = new PluginUpdateData($pluginVersion);
$version = $pluginClass::getVersion(); $version = $pluginClass::getVersion();
if ($pluginUpdateData->isNewerThan($version)) {
if ($pluginUpdateData->isNewerThan($version) && $pluginUpdateData->minManiaControlVersion >= ManiaControl::VERSION) {
return $pluginUpdateData; return $pluginUpdateData;
} }
return false; return false;