fixed //checkupdate

This commit is contained in:
Steffen Schröder 2014-04-29 23:53:55 +02:00
parent 200f199c06
commit ab375e636e

View File

@ -41,7 +41,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
* Private Properties
*/
private $maniaControl = null;
/** @var UpdateData $coreUpdateData */
/**
*
* @var UpdateData $coreUpdateData
*/
private $coreUpdateData = null;
private $currentBuildDate = "";
@ -68,7 +71,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'autoUpdate');
$this->maniaControl->callbackManager->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
//define Permissions
// define Permissions
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATECHECK, AuthenticationManager::AUTH_LEVEL_MODERATOR);
@ -95,17 +98,18 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return;
}
//Check if a new Core Update is Available
// Check if a new Core Update is Available
$self = $this;
$maniaControl = $this->maniaControl;
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use ($self, $maniaControl, $time) {
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use($self, $maniaControl, $time) {
$buildDate = strtotime($self->getCurrentBuildDate());
$releaseTime = strtotime($updateData->releaseDate);
if ($buildDate < $releaseTime) {
$updateChannel = $maniaControl->settingManager->getSetting($self, UpdateManager::SETTING_UPDATECHECK_CHANNEL);
if ($updateChannel != UpdateManager::CHANNEL_NIGHTLY) {
$maniaControl->log('New ManiaControl Version ' . $updateData->version . ' available!');
} else {
}
else {
$maniaControl->log('New Nightly Build (' . $updateData->releaseDate . ') available!');
}
$self->setCoreUpdateData($updateData);
@ -134,7 +138,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL);
if ($updateChannel != self::CHANNEL_NIGHTLY) {
$this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
} else {
}
else {
$this->maniaControl->chat->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login);
}
}
@ -178,7 +183,6 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$this->performCoreUpdate($this->coreUpdateData);
}
/**
* Handle //checkupdate command
*
@ -191,27 +195,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return;
}
$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL);
if ($updateChannel != self::CHANNEL_NIGHTLY) {
// Check update and send result message
$self = $this;
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self, &$player) {
if (!$updateData) {
$self->maniaControl->chat->sendInformation('No Update available!', $player->login);
return;
}
$version = $self->maniaControl->client->getVersion();
if ($updateData->minDedicatedBuild > $version->build) {
$self->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login);
return;
}
$self->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
});
} else {
if ($updateChannel === self::CHANNEL_NIGHTLY) {
// Special nightly channel updating
$self = $this;
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self, &$player) {
$this->checkCoreUpdateAsync(function ($updateData) use(&$self, &$player) {
if (!$updateData) {
$self->maniaControl->chat->sendInformation('No Update available!', $player->login);
return;
@ -231,11 +218,32 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return;
}
$self->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->releaseDate . ') available, current build: ' . $self->currentBuildDate . '!', $player->login);
} else {
}
else {
$self->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->releaseDate . ') available!', $player->login);
}
}, true);
}
else {
// Check update and send result message
$self = $this;
$this->checkCoreUpdateAsync(function ($updateData) use(&$self, &$player) {
if (!$updateData) {
$self->maniaControl->chat->sendInformation('No Update available!', $player->login);
return;
}
$version = $self->maniaControl->client->getVersion();
if ($updateData->minDedicatedBuild > $version->build) {
$self->maniaControl->chat->sendError("No new Build for this Server-version available!", $player->login);
return;
}
$self->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
});
}
}
/**
@ -255,7 +263,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
if ($pluginClass == 'All') {
$this->checkPluginsUpdate($player);
} else {
}
else {
$newUpdate = $this->checkPluginUpdate($pluginClass);
if ($newUpdate != false) {
$newUpdate->pluginClass = $pluginClass;
@ -326,7 +335,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
}
$self = $this;
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use (&$self, &$player) {
$this->checkCoreUpdateAsync(function (UpdateData $updateData) use(&$self, &$player) {
if (!$updateData) {
$self->maniaControl->chat->sendError('Update is currently not possible!', $player->login);
return;
@ -373,7 +382,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$this->maniaControl->log('[UPDATE] Checking plugins for newer versions ...');
$self = $this;
$this->maniaControl->pluginManager->fetchPluginList(function ($data, $error) use (&$self, &$player) {
$this->maniaControl->pluginManager->fetchPluginList(function ($data, $error) use(&$self, &$player) {
$outdatedPlugins = array();
if (!$data || $error) {
@ -383,8 +392,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$pluginClasses = $self->maniaControl->pluginManager->getPluginClasses();
foreach($data as $plugin) {
foreach($pluginClasses as $pluginClass) {
foreach ($data as $plugin) {
foreach ($pluginClasses as $pluginClass) {
$id = $pluginClass::getId();
if ($plugin->id == $id) {
if ($plugin->currentVersion->version > $pluginClass::getVersion()) {
@ -401,10 +410,11 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$self->maniaControl->chat->sendInformation('Checking plugins: COMPLETE, there are ' . count($outdatedPlugins) . ' outdated plugins, now updating ...', $player->login);
}
$self->performPluginsBackup();
foreach($outdatedPlugins as $plugin) {
foreach ($outdatedPlugins as $plugin) {
$self->updatePlugin($plugin, $player);
}
} else {
}
else {
$self->maniaControl->log('[UPDATE] Checking plugins: COMPLETE, all plugins are up-to-date!');
if ($player) {
$self->maniaControl->chat->sendInformation('Checking plugins: COMPLETE, all plugins are up-to-date!', $player->login);
@ -423,7 +433,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
if (is_object($pluginClass)) {
$pluginClass = get_class($pluginClass);
}
/** @var Plugin $pluginClass */
/**
*
* @var Plugin $pluginClass
*/
$pluginId = $pluginClass::getId();
$url = ManiaControl::URL_WEBSERVICE . 'plugins?id=' . $pluginId;
$dataJson = FileUtil::loadFile($url);
@ -455,12 +468,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
return false;
}
foreach($pluginVersions as $plugin) {
foreach ($pluginVersions as $plugin) {
$pluginsWS[$plugin->id] = $plugin;
}
/** @var Plugin $pluginClass */
foreach($this->maniaControl->pluginManager->getPluginClasses() as $pluginClass) {
/**
*
* @var Plugin $pluginClass
*/
foreach ($this->maniaControl->pluginManager->getPluginClasses() as $pluginClass) {
$pluginId = $pluginClass::getId();
if (array_key_exists($pluginId, $pluginsWS)) {
if ($pluginsWS[$pluginId]->currentVersion->version > $pluginClass::getVersion()) {
@ -484,7 +500,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
*/
private function updatePlugin($pluginData, Player $player = null, $reopen = false) {
$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 . ' ...');
if ($player) {
$self->maniaControl->chat->sendInformation('Now updating ' . $pluginData->name . ' ...', $player->login);
@ -541,7 +557,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
*/
private function installPlugin($pluginData, Player $player, $reopen = false) {
$self = $this;
$this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($installFileContent, $error) use (&$self, &$updateData, &$player, &$pluginData, &$reopen) {
$this->maniaControl->fileReader->loadFile($pluginData->currentVersion->url, function ($installFileContent, $error) use(&$self, &$updateData, &$player, &$pluginData, &$reopen) {
$pluginsDirectory = ManiaControlDir . '/plugins/';
$pluginFiles = scandir($pluginsDirectory);
@ -577,7 +593,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$newFiles = array_diff($pluginFilesAfter, $pluginFiles);
$classesBefore = get_declared_classes();
foreach($newFiles as $newFile) {
foreach ($newFiles as $newFile) {
$filePath = $pluginsDirectory . $newFile;
if (is_file($filePath)) {
@ -597,12 +613,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$classesAfter = get_declared_classes();
$newClasses = array_diff($classesAfter, $classesBefore);
foreach($newClasses as $className) {
foreach ($newClasses as $className) {
if (!$self->maniaControl->pluginManager->isPluginClass($className)) {
continue;
}
/** @var Plugin $className */
/**
*
* @var Plugin $className
*/
$self->maniaControl->pluginManager->addPluginClass($className);
$className::prepare($self->maniaControl);
@ -641,19 +660,20 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
*/
private function checkCoreUpdateAsync($function, $ignoreVersion = false) {
$updateChannel = $this->getCurrentUpdateChannelSetting();
$url = ManiaControl::URL_WEBSERVICE . 'versions?update=1&current=1&channel=' . $updateChannel;
$url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel;
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use (&$function, $ignoreVersion) {
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use(&$function, $ignoreVersion) {
$versions = json_decode($dataJson);
if (!$versions || !isset($versions[0])) {
return;
}
$updateData = new UpdateData($versions[0]);
if (!$ignoreVersion && $updateData->version <= ManiaControl::VERSION) {
return;
call_user_func($function, null);
}
else {
call_user_func($function, $updateData);
}
});
}
@ -724,7 +744,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
trigger_error("Couldn't open Folder '{$folderName}' for Backup!");
return false;
}
while(false !== ($file = readdir($folderHandle))) {
while (false !== ($file = readdir($folderHandle))) {
if (in_array($file, $excludes)) {
continue;
}
@ -769,7 +789,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
}
$self = $this;
$this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use (&$self, &$updateData, &$player) {
$this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use(&$self, &$updateData, &$player) {
$tempDir = ManiaControlDir . '/temp/';
if (!is_dir($tempDir)) {
mkdir($tempDir);
@ -799,7 +819,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
unlink($updateFileName);
@rmdir($tempDir);
//Set the Nightly Build Date
// Set the Nightly Build Date
$self->setNightlyBuildDate($updateData->releaseDate);
if ($player) {
@ -824,9 +844,9 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$writableDirectories = array('/core/', '/plugins/');
$path = ManiaControlDir;
foreach($writableDirectories as $writableDirecotry) {
foreach ($writableDirectories as $writableDirecotry) {
$dir = new \RecursiveDirectoryIterator($path . $writableDirecotry);
foreach(new \RecursiveIteratorIterator($dir) as $filename => $file) {
foreach (new \RecursiveIteratorIterator($dir) as $filename => $file) {
if (substr($filename, -1) != '.' && substr($filename, -2) != '..') {
if (!is_writable($filename)) {
$this->maniaControl->log('Cannot update: the file/directory "' . $filename . '" is not writable!');