Added update all button on pluginmenu

This commit is contained in:
Max Klaversma 2014-04-16 01:38:28 +02:00 committed by Steffen Schröder
parent b4d131404d
commit 9de5c340c3
2 changed files with 37 additions and 4 deletions

View File

@ -39,6 +39,7 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
const ACTION_SETTING_BOOL = 'PluginMenuActionBoolSetting.';
const ACTION_BACK_TO_PLUGINS = 'PluginMenu.BackToPlugins';
const ACTION_PREFIX_UPDATEPLUGIN = 'PluginMenu.Update.';
const ACTION_UPDATEPLUGINS = 'PluginMenu.Update.All';
const SETTING_PERMISSION_CHANGE_PLUGIN_SETTINGS = 'Change Plugin Settings';
/*
@ -334,6 +335,17 @@ class PluginMenu implements CallbackListener, ConfiguratorMenu, ManialinkPageAns
}
}
$numberOfOutdated = $this->maniaControl->updateManager->getNumberOfOutdatedPlugins();
$updatePluginsButton = new Label_Button();
$frame->add($updatePluginsButton);
$updatePluginsButton->setHAlign(Control::RIGHT);
$updatePluginsButton->setX($width * 0.1);
$updatePluginsButton->setY(-35.5);
$updatePluginsButton->setZ(2);
$updatePluginsButton->setStyle($updatePluginsButton::STYLE_CardButtonSmall);
$updatePluginsButton->setText('Update '.$numberOfOutdated.' plugin(s)');
$updatePluginsButton->setAction(self::ACTION_UPDATEPLUGINS);
return $frame;
}

View File

@ -249,10 +249,14 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if($update) {
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
$newUpdate = $this->checkPluginUpdate($pluginClass);
if($newUpdate != false) {
$newUpdate->pluginClass = $pluginClass;
$this->updatePlugin($newUpdate, $player, true);
if($pluginClass == 'All') {
$this->checkPluginsUpdate($player);
} else {
$newUpdate = $this->checkPluginUpdate($pluginClass);
if($newUpdate != false) {
$newUpdate->pluginClass = $pluginClass;
$this->updatePlugin($newUpdate, $player, true);
}
}
}
}
@ -345,6 +349,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
/**
* Checks if there are outdated plugins active.
* @param Player $player
*/
public function checkPluginsUpdate(Player $player = null) {
$this->maniaControl->log('[UPDATE] Checking plugins for newer versions ...');
@ -376,6 +381,22 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
}
}
/**
* Returns the number of outdated plugins active.
* @return int
*/
public function getNumberOfOutdatedPlugins() {
$number = 0;
foreach ($this->maniaControl->pluginManager->getPluginClasses() as $pluginClass) {
$pluginData = $this->checkPluginUpdate($pluginClass);
if ($pluginData != false) {
$number++;
}
}
return $number;
}
/**
* Check given Plugin Class for Update
*