async plugin update check

This commit is contained in:
kremsy 2014-04-20 17:49:18 +02:00 committed by Steffen Schröder
parent 1011fbdde1
commit 9dc3ba395b
2 changed files with 75 additions and 68 deletions

View File

@ -38,10 +38,6 @@ class PluginManager {
$this->pluginMenu = new PluginMenu($maniaControl); $this->pluginMenu = new PluginMenu($maniaControl);
$this->maniaControl->configurator->addMenu($this->pluginMenu); $this->maniaControl->configurator->addMenu($this->pluginMenu);
/*$this->fetchPluginList(function ($data) {
var_dump($data);
});*/
} }
/** /**
@ -353,16 +349,12 @@ class PluginManager {
* @param $function * @param $function
* @param bool $ignoreVersion * @param bool $ignoreVersion
*/ */
private 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);
if (!$data || !isset($data[0])) { call_user_func($function, $data, $error);
return;
}
call_user_func($function, $data[0]);
}); });
} }
} }

View File

@ -3,8 +3,8 @@
namespace ManiaControl\Update; namespace ManiaControl\Update;
use ManiaControl\Admin\AuthenticationManager; use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\CallbackListener; use ManiaControl\Callbacks\CallbackListener;
use ManiaControl\Callbacks\CallbackManager;
use ManiaControl\Callbacks\TimerListener; use ManiaControl\Callbacks\TimerListener;
use ManiaControl\Commands\CommandListener; use ManiaControl\Commands\CommandListener;
use ManiaControl\Files\FileUtil; use ManiaControl\Files\FileUtil;
@ -368,36 +368,51 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
/** /**
* Checks if there are outdated plugins active. * Checks if there are outdated plugins active.
*
* @param Player $player * @param Player $player
*/ */
public function checkPluginsUpdate(Player $player = null) { public function checkPluginsUpdate(Player $player = null) {
$this->maniaControl->log('[UPDATE] Checking plugins for newer versions ...'); $this->maniaControl->log('[UPDATE] Checking plugins for newer versions ...');
$self = $this;
$this->maniaControl->pluginManager->fetchPluginList(function ($data, $error) use (&$self, &$player) {
$outdatedPlugins = array(); $outdatedPlugins = array();
foreach ($this->maniaControl->pluginManager->getPluginClasses() as $pluginClass) { if (!$data || $error) {
$pluginData = $this->checkPluginUpdate($pluginClass); $self->maniaControl->log('[UPDATE] Error while checking plugins for newer version');
if ($pluginData != false) { return;
$pluginData->pluginClass = $pluginClass; }
$outdatedPlugins[] = $pluginData;
$this->maniaControl->log('[UPDATE] '.$pluginClass.': There is a newer version available: '.$pluginData->currentVersion->version.'!'); $pluginClasses = $self->maniaControl->pluginManager->getPluginClasses();
foreach($data as $plugin) {
foreach($pluginClasses as $pluginClass) {
$id = $pluginClass::getId();
if ($plugin->id == $id) {
if ($plugin->currentVersion->version > $pluginClass::getVersion()) {
$outdatedPlugins[] = $plugin;
$self->maniaControl->log('[UPDATE] ' . $pluginClass . ': There is a newer version available: ' . $plugin->currentVersion->version . '!');
}
}
} }
} }
if (count($outdatedPlugins) > 0) { if (count($outdatedPlugins) > 0) {
$this->maniaControl->log('[UPDATE] Checking plugins: COMPLETE, there are '.count($outdatedPlugins).' outdated plugins, now updating ...'); $self->maniaControl->log('[UPDATE] Checking plugins: COMPLETE, there are ' . count($outdatedPlugins) . ' outdated plugins, now updating ...');
if ($player) { if ($player) {
$this->maniaControl->chat->sendInformation('Checking plugins: COMPLETE, there are '.count($outdatedPlugins).' outdated plugins, now updating ...', $player->login); $self->maniaControl->chat->sendInformation('Checking plugins: COMPLETE, there are ' . count($outdatedPlugins) . ' outdated plugins, now updating ...', $player->login);
} }
$this->performPluginsBackup(); $self->performPluginsBackup();
foreach($outdatedPlugins as $plugin) { foreach($outdatedPlugins as $plugin) {
$this->updatePlugin($plugin, $player); $self->updatePlugin($plugin, $player);
} }
} else { } else {
$this->maniaControl->log('[UPDATE] Checking plugins: COMPLETE, all plugins are up-to-date!'); $self->maniaControl->log('[UPDATE] Checking plugins: COMPLETE, all plugins are up-to-date!');
if ($player) { if ($player) {
$this->maniaControl->chat->sendInformation('Checking plugins: COMPLETE, all plugins are up-to-date!', $player->login); $self->maniaControl->chat->sendInformation('Checking plugins: COMPLETE, all plugins are up-to-date!', $player->login);
} }
} }
});
} }
/** /**