updatemanager improvements
This commit is contained in:
parent
2283da2365
commit
377cb9a8b6
@ -37,6 +37,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
*/
|
*/
|
||||||
private $maniaControl = null;
|
private $maniaControl = null;
|
||||||
private $coreUpdateData = null;
|
private $coreUpdateData = null;
|
||||||
|
private $currentBuiltDate = "";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new Update Manager
|
* Create a new Update Manager
|
||||||
@ -66,6 +67,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
// Register for chat commands
|
// Register for chat commands
|
||||||
$this->maniaControl->commandManager->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true);
|
$this->maniaControl->commandManager->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true);
|
||||||
$this->maniaControl->commandManager->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true);
|
$this->maniaControl->commandManager->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true);
|
||||||
|
|
||||||
|
$this->currentBuiltDate = $this->getNightlyBuildDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -83,14 +86,16 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$updateData = $this->checkCoreUpdate();
|
//Check if a new Core Update is Available
|
||||||
if (!$updateData) {
|
$this->checkCoreUpdateAsync(function ($updateData) use ($time) {
|
||||||
return;
|
$buildDate = strtotime($this->currentBuiltDate);
|
||||||
}
|
$releaseTime = strtotime($updateData->release_date);
|
||||||
$this->maniaControl->log('New ManiaControl Version ' . $updateData->version . ' available!');
|
if ($buildDate < $releaseTime) {
|
||||||
$this->coreUpdateData = $updateData;
|
$this->maniaControl->log('New ManiaControl Version ' . $updateData->version . ' available!');
|
||||||
|
$this->coreUpdateData = $updateData;
|
||||||
$this->autoUpdate($time);
|
$this->autoUpdate($time);
|
||||||
|
}
|
||||||
|
}, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -107,7 +112,12 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
|
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
|
|
||||||
|
$buildDate = strtotime($this->currentBuiltDate);
|
||||||
|
$releaseTime = strtotime($this->coreUpdateData->release_date);
|
||||||
|
if ($buildDate < $releaseTime) {
|
||||||
|
$this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -126,17 +136,22 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$updateData = $this->checkCoreUpdate(true);
|
if (!$this->coreUpdateData) {
|
||||||
if (!$updateData) {
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maniaControl->log("Starting Update to Version v{$updateData->version}...");
|
$buildDate = strtotime($this->currentBuiltDate);
|
||||||
|
$releaseTime = strtotime($this->coreUpdateData->release_date);
|
||||||
|
if ($buildDate && $buildDate >= $releaseTime) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->maniaControl->log("Starting Update to Version v{$this->coreUpdateData->version}...");
|
||||||
$performBackup = $this->maniaControl->settingManager->getSetting($this, self::SETTING_PERFORM_BACKUPS);
|
$performBackup = $this->maniaControl->settingManager->getSetting($this, self::SETTING_PERFORM_BACKUPS);
|
||||||
if ($performBackup && !$this->performBackup()) {
|
if ($performBackup && !$this->performBackup()) {
|
||||||
$this->maniaControl->log("Creating Backup failed!");
|
$this->maniaControl->log("Creating Backup failed!");
|
||||||
}
|
}
|
||||||
$this->performCoreUpdate($updateData);
|
$this->performCoreUpdate($this->coreUpdateData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -163,11 +178,11 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
} else {
|
} else {
|
||||||
// Special nightly channel updating
|
// Special nightly channel updating
|
||||||
$updateData = $this->checkCoreUpdate(true);
|
$updateData = $this->checkCoreUpdate(true);
|
||||||
$buildDate = $this->getNightlyBuildDate();
|
$buildDate = $this->currentBuiltDate;
|
||||||
$releaseTime = strtotime($updateData->release_date);
|
$releaseTime = strtotime($updateData->release_date);
|
||||||
if ($buildDate) {
|
if ($buildDate) {
|
||||||
$buildTime = strtotime($buildDate);
|
$buildTime = strtotime($buildDate);
|
||||||
if ($buildTime >= $releaseTime) { //FIXME will ever fail, releaseTime > buildTime (because releaseTime "2014-02-01 14:59:49")
|
if ($buildTime >= $releaseTime) {
|
||||||
$this->maniaControl->chat->sendInformation('No new Build available, current build: ' . date("Y-m-d", $buildTime) . '!', $player->login);
|
$this->maniaControl->chat->sendInformation('No new Build available, current build: ' . date("Y-m-d", $buildTime) . '!', $player->login);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -192,6 +207,19 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
return $fileContent;
|
return $fileContent;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the Build Date of the local Nightly Build Version
|
||||||
|
*
|
||||||
|
* @param $date
|
||||||
|
* @return mixed
|
||||||
|
*/
|
||||||
|
private function setNightlyBuildDate($date) {
|
||||||
|
$nightlyBuildDateFile = ManiaControlDir . '/core/nightly_build.txt';
|
||||||
|
$success = file_put_contents($nightlyBuildDateFile, $date);
|
||||||
|
$this->currentBuiltDate = $date;
|
||||||
|
return $success;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handle //coreupdate command
|
* Handle //coreupdate command
|
||||||
*
|
*
|
||||||
@ -246,6 +274,31 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
return $pluginData;
|
return $pluginData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Checks a core update Asynchrnously
|
||||||
|
*
|
||||||
|
* @param $function
|
||||||
|
* @param bool $ignoreVersion
|
||||||
|
*/
|
||||||
|
private function checkCoreUpdateAsync($function, $ignoreVersion = false) {
|
||||||
|
$updateChannel = $this->getCurrentUpdateChannelSetting();
|
||||||
|
$url = self::URL_WEBSERVICE . 'versions?update=1¤t=1&channel=' . $updateChannel;
|
||||||
|
|
||||||
|
$this->maniaControl->fileReader->loadFile($url, function ($dataJson, $error) use (&$function, $ignoreVersion) {
|
||||||
|
$versions = json_decode($dataJson);
|
||||||
|
if (!$versions || !isset($versions[0])) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
$updateData = $versions[0];
|
||||||
|
if (!$ignoreVersion && $updateData->version <= ManiaControl::VERSION) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
call_user_func($function, $updateData);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for Update of ManiaControl
|
* Check for Update of ManiaControl
|
||||||
*
|
*
|
||||||
@ -334,7 +387,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
* @param Players\Player $player
|
* @param Players\Player $player
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function performCoreUpdate($updateData = null, Player $player = null) {
|
private function performCoreUpdate($updateData, Player $player = null) {
|
||||||
if (!$this->checkPermissions()) {
|
if (!$this->checkPermissions()) {
|
||||||
if ($player != null) {
|
if ($player != null) {
|
||||||
$this->maniaControl->chat->sendError('Update failed: Incorrect Filesystem permissions!', $player->login);
|
$this->maniaControl->chat->sendError('Update failed: Incorrect Filesystem permissions!', $player->login);
|
||||||
@ -343,15 +396,12 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$updateData) {
|
if (!isset($updateData->url) && !isset($updateData->release_date)) {
|
||||||
$updateData = $this->checkCoreUpdate();
|
if ($player != null) {
|
||||||
if (!$updateData) {
|
$this->maniaControl->chat->sendError('Update failed: No update Data available!', $player->login);
|
||||||
if ($player != null) {
|
|
||||||
$this->maniaControl->chat->sendError('Update failed: No update Data available!', $player->login);
|
|
||||||
}
|
|
||||||
$this->maniaControl->log('Update failed: No update Data available!');
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
$this->maniaControl->log('Update failed: No update Data available!');
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use (&$updateData, &$player) {
|
$this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use (&$updateData, &$player) {
|
||||||
@ -361,7 +411,6 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
}
|
}
|
||||||
$updateFileName = $tempDir . basename($updateData->url);
|
$updateFileName = $tempDir . basename($updateData->url);
|
||||||
|
|
||||||
|
|
||||||
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
||||||
if (!$bytes || $bytes <= 0) {
|
if (!$bytes || $bytes <= 0) {
|
||||||
trigger_error("Couldn't save Update Zip.");
|
trigger_error("Couldn't save Update Zip.");
|
||||||
@ -385,6 +434,9 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
unlink($updateFileName);
|
unlink($updateFileName);
|
||||||
@rmdir($tempDir);
|
@rmdir($tempDir);
|
||||||
|
|
||||||
|
//Set the Nightly Build Date
|
||||||
|
$this->setNightlyBuildDate($updateData->release_date);
|
||||||
|
|
||||||
if ($player != null) {
|
if ($player != null) {
|
||||||
$this->maniaControl->chat->sendSuccess('Update finished!', $player->login);
|
$this->maniaControl->chat->sendSuccess('Update finished!', $player->login);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user