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:
parent
6908ff36e4
commit
6eca102233
@ -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;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -257,7 +257,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
|||||||
Logger::logError($message);
|
Logger::logError($message);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $pluginUpdateData->url);
|
$asyncHttpRequest = new AsyncHttpRequest($this->maniaControl, $pluginUpdateData->url);
|
||||||
$asyncHttpRequest->setCallable(function ($updateFileContent, $error) use (
|
$asyncHttpRequest->setCallable(function ($updateFileContent, $error) use (
|
||||||
&$pluginUpdateData, &$player, &$update
|
&$pluginUpdateData, &$player, &$update
|
||||||
@ -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) {
|
||||||
$pluginClass = PluginManager::getPluginClass($pluginClass);
|
if (!$skipPluginClassFetch) {
|
||||||
|
//Used to avoid recursion in the isPluginClass Method
|
||||||
|
$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;
|
||||||
|
Loading…
Reference in New Issue
Block a user