update manager improvements

This commit is contained in:
Steffen Schröder 2013-12-31 17:17:40 +01:00
parent dcb4e3f951
commit df4b11cc6b

View File

@ -62,11 +62,13 @@ class UpdateManager implements CallbackListener, CommandListener {
public function handle1Minute(array $callback) { public function handle1Minute(array $callback) {
$updateCheckEnabled = $this->maniaControl->settingManager->getSetting($this, self::SETTING_ENABLEUPDATECHECK); $updateCheckEnabled = $this->maniaControl->settingManager->getSetting($this, self::SETTING_ENABLEUPDATECHECK);
if (!$updateCheckEnabled) { if (!$updateCheckEnabled) {
// Automatic update check disabled
if ($this->coreUpdateData) { if ($this->coreUpdateData) {
$this->coreUpdateData = null; $this->coreUpdateData = null;
} }
return; return;
} }
// Only check once per hour
$updateInterval = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_INTERVAL); $updateInterval = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_INTERVAL);
if ($this->lastUpdateCheck > time() - $updateInterval * 3600.) { if ($this->lastUpdateCheck > time() - $updateInterval * 3600.) {
return; return;
@ -74,6 +76,7 @@ class UpdateManager implements CallbackListener, CommandListener {
$this->lastUpdateCheck = time(); $this->lastUpdateCheck = time();
$updateData = $this->checkCoreUpdate(); $updateData = $this->checkCoreUpdate();
if (!$updateData) { if (!$updateData) {
// No update available
return; return;
} }
$this->maniaControl->log('New ManiaControl Version ' . $updateData->version . ' available!'); $this->maniaControl->log('New ManiaControl Version ' . $updateData->version . ' available!');
@ -89,10 +92,9 @@ class UpdateManager implements CallbackListener, CommandListener {
if (!$this->coreUpdateData) { if (!$this->coreUpdateData) {
return; return;
} }
// Announce available update
$player = $callback[1]; $player = $callback[1];
if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) { if (!AuthenticationManager::checkRight($player, AuthenticationManager::AUTH_LEVEL_SUPERADMIN)) return;
return;
}
$this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!',
$player->login); $player->login);
} }