async plugin update check
This commit is contained in:
parent
1011fbdde1
commit
9dc3ba395b
@ -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]);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -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;
|
||||||
@ -162,7 +162,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
$version = $this->maniaControl->client->getVersion();
|
$version = $this->maniaControl->client->getVersion();
|
||||||
if($this->coreUpdateData->minDedicatedBuild > $version->build){
|
if ($this->coreUpdateData->minDedicatedBuild > $version->build) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -203,7 +203,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
$version = $self->maniaControl->client->getVersion();
|
$version = $self->maniaControl->client->getVersion();
|
||||||
if($updateData->minDedicatedBuild > $version->build){
|
if ($updateData->minDedicatedBuild > $version->build) {
|
||||||
$self->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login);
|
$self->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -220,7 +220,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
$version = $self->maniaControl->client->getVersion();
|
$version = $self->maniaControl->client->getVersion();
|
||||||
if($updateData->minDedicatedBuild > $version->build){
|
if ($updateData->minDedicatedBuild > $version->build) {
|
||||||
$self->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login);
|
$self->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -253,20 +253,20 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
$login = $callback[1][1];
|
$login = $callback[1][1];
|
||||||
$player = $this->maniaControl->playerManager->getPlayer($login);
|
$player = $this->maniaControl->playerManager->getPlayer($login);
|
||||||
|
|
||||||
if($update) {
|
if ($update) {
|
||||||
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
|
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
|
||||||
if($pluginClass == 'All') {
|
if ($pluginClass == 'All') {
|
||||||
$this->checkPluginsUpdate($player);
|
$this->checkPluginsUpdate($player);
|
||||||
} else {
|
} else {
|
||||||
$newUpdate = $this->checkPluginUpdate($pluginClass);
|
$newUpdate = $this->checkPluginUpdate($pluginClass);
|
||||||
if($newUpdate != false) {
|
if ($newUpdate != false) {
|
||||||
$newUpdate->pluginClass = $pluginClass;
|
$newUpdate->pluginClass = $pluginClass;
|
||||||
$this->updatePlugin($newUpdate, $player, true);
|
$this->updatePlugin($newUpdate, $player, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if($install) {
|
if ($install) {
|
||||||
$pluginId = substr($actionId, strlen(PluginInstallMenu::ACTION_PREFIX_INSTALLPLUGIN));
|
$pluginId = substr($actionId, strlen(PluginInstallMenu::ACTION_PREFIX_INSTALLPLUGIN));
|
||||||
|
|
||||||
$url = ManiaControl::URL_WEBSERVICE . 'plugins?id=' . $pluginId;
|
$url = ManiaControl::URL_WEBSERVICE . 'plugins?id=' . $pluginId;
|
||||||
@ -328,13 +328,13 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self,&$player) {
|
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self, &$player) {
|
||||||
if (!$updateData) {
|
if (!$updateData) {
|
||||||
$self->maniaControl->chat->sendError('Update is currently not possible!', $player->login);
|
$self->maniaControl->chat->sendError('Update is currently not possible!', $player->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$version = $self->maniaControl->client->getVersion();
|
$version = $self->maniaControl->client->getVersion();
|
||||||
if($updateData->minDedicatedBuild > $version->build){
|
if ($updateData->minDedicatedBuild > $version->build) {
|
||||||
$self->maniaControl->chat->sendError("ManiaControl update version requires a newer Dedicated Server version!", $player->login);
|
$self->maniaControl->chat->sendError("ManiaControl update version requires a newer Dedicated Server version!", $player->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -449,14 +464,14 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
/** @var Plugin $pluginClass */
|
/** @var Plugin $pluginClass */
|
||||||
foreach($this->maniaControl->pluginManager->getPluginClasses() as $pluginClass) {
|
foreach($this->maniaControl->pluginManager->getPluginClasses() as $pluginClass) {
|
||||||
$pluginId = $pluginClass::getId();
|
$pluginId = $pluginClass::getId();
|
||||||
if(array_key_exists($pluginId, $pluginsWS)) {
|
if (array_key_exists($pluginId, $pluginsWS)) {
|
||||||
if($pluginsWS[$pluginId]->currentVersion->version > $pluginClass::getVersion()) {
|
if ($pluginsWS[$pluginId]->currentVersion->version > $pluginClass::getVersion()) {
|
||||||
$pluginUpdates[$pluginId] = $pluginsWS[$pluginId];
|
$pluginUpdates[$pluginId] = $pluginsWS[$pluginId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(empty($pluginUpdates)) {
|
if (empty($pluginUpdates)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return $pluginUpdates;
|
return $pluginUpdates;
|
||||||
@ -472,9 +487,9 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
private function updatePlugin($pluginData, Player $player = null, $reopen = false) {
|
private function updatePlugin($pluginData, Player $player = null, $reopen = false) {
|
||||||
$self = $this;
|
$self = $this;
|
||||||
$this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($updateFileContent, $error) use (&$self, &$updateData, &$player, &$pluginData, &$reopen) {
|
$this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($updateFileContent, $error) use (&$self, &$updateData, &$player, &$pluginData, &$reopen) {
|
||||||
$self->maniaControl->log('[UPDATE] Now updating '.$pluginData->name.' ...');
|
$self->maniaControl->log('[UPDATE] Now updating ' . $pluginData->name . ' ...');
|
||||||
if ($player) {
|
if ($player) {
|
||||||
$self->maniaControl->chat->sendInformation('Now updating '.$pluginData->name.' ...', $player->login);
|
$self->maniaControl->chat->sendInformation('Now updating ' . $pluginData->name . ' ...', $player->login);
|
||||||
}
|
}
|
||||||
$tempDir = ManiaControlDir . '/temp/';
|
$tempDir = ManiaControlDir . '/temp/';
|
||||||
if (!is_dir($tempDir)) {
|
if (!is_dir($tempDir)) {
|
||||||
@ -500,14 +515,14 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip->extractTo(ManiaControlDir.'/plugins');
|
$zip->extractTo(ManiaControlDir . '/plugins');
|
||||||
$zip->close();
|
$zip->close();
|
||||||
unlink($updateFileName);
|
unlink($updateFileName);
|
||||||
@rmdir($tempDir);
|
@rmdir($tempDir);
|
||||||
|
|
||||||
$self->maniaControl->log('[UPDATE] Successfully updated '.$pluginData->name.'!');
|
$self->maniaControl->log('[UPDATE] Successfully updated ' . $pluginData->name . '!');
|
||||||
if ($player) {
|
if ($player) {
|
||||||
$self->maniaControl->chat->sendSuccess('Successfully updated '.$pluginData->name.'!', $player->login);
|
$self->maniaControl->chat->sendSuccess('Successfully updated ' . $pluginData->name . '!', $player->login);
|
||||||
$self->maniaControl->pluginManager->deactivatePlugin($pluginData->pluginClass);
|
$self->maniaControl->pluginManager->deactivatePlugin($pluginData->pluginClass);
|
||||||
$self->maniaControl->pluginManager->activatePlugin($pluginData->pluginClass);
|
$self->maniaControl->pluginManager->activatePlugin($pluginData->pluginClass);
|
||||||
|
|
||||||
@ -532,8 +547,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
$pluginsDirectory = ManiaControlDir . '/plugins/';
|
$pluginsDirectory = ManiaControlDir . '/plugins/';
|
||||||
$pluginFiles = scandir($pluginsDirectory);
|
$pluginFiles = scandir($pluginsDirectory);
|
||||||
|
|
||||||
$self->maniaControl->log('[UPDATE] Now installing '.$pluginData->name.' ...');
|
$self->maniaControl->log('[UPDATE] Now installing ' . $pluginData->name . ' ...');
|
||||||
$self->maniaControl->chat->sendInformation('Now installing '.$pluginData->name.' ...', $player->login);
|
$self->maniaControl->chat->sendInformation('Now installing ' . $pluginData->name . ' ...', $player->login);
|
||||||
|
|
||||||
$tempDir = ManiaControlDir . '/temp/';
|
$tempDir = ManiaControlDir . '/temp/';
|
||||||
if (!is_dir($tempDir)) {
|
if (!is_dir($tempDir)) {
|
||||||
@ -555,7 +570,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$zip->extractTo(ManiaControlDir.'/plugins');
|
$zip->extractTo(ManiaControlDir . '/plugins');
|
||||||
$zip->close();
|
$zip->close();
|
||||||
unlink($installFileName);
|
unlink($installFileName);
|
||||||
@rmdir($tempDir);
|
@rmdir($tempDir);
|
||||||
@ -601,8 +616,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$self->maniaControl->log('[UPDATE] Successfully installed '.$pluginData->name.'!');
|
$self->maniaControl->log('[UPDATE] Successfully installed ' . $pluginData->name . '!');
|
||||||
$self->maniaControl->chat->sendSuccess('Successfully installed '.$pluginData->name.'!', $player->login);
|
$self->maniaControl->chat->sendSuccess('Successfully installed ' . $pluginData->name . '!', $player->login);
|
||||||
|
|
||||||
if ($reopen) {
|
if ($reopen) {
|
||||||
$menuId = $self->maniaControl->configurator->getMenuId('Install Plugins');
|
$menuId = $self->maniaControl->configurator->getMenuId('Install Plugins');
|
||||||
@ -687,11 +702,11 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$excludes = array('.', '..');
|
$excludes = array('.', '..');
|
||||||
$pathInfo = pathInfo(ManiaControlDir.'/plugins');
|
$pathInfo = pathInfo(ManiaControlDir . '/plugins');
|
||||||
$parentPath = $pathInfo['dirname'] . '/';
|
$parentPath = $pathInfo['dirname'] . '/';
|
||||||
$dirName = $pathInfo['basename'];
|
$dirName = $pathInfo['basename'];
|
||||||
$backupZip->addEmptyDir($dirName);
|
$backupZip->addEmptyDir($dirName);
|
||||||
$this->zipDirectory($backupZip, ManiaControlDir.'/plugins', strlen($parentPath), $excludes);
|
$this->zipDirectory($backupZip, ManiaControlDir . '/plugins', strlen($parentPath), $excludes);
|
||||||
$backupZip->close();
|
$backupZip->close();
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user