improvements update manager

This commit is contained in:
kremsy 2014-02-01 18:33:06 +01:00 committed by Steffen Schröder
parent dcadd1c1f6
commit 00529d111d

View File

@ -55,9 +55,9 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
// Register for callbacks // Register for callbacks
$this->maniaControl->timerManager->registerTimerListening($this, 'handle1Minute', 1000 * 60); $this->maniaControl->timerManager->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60);
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerJoined'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerJoined');
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'handlePlayerDisconnected'); $this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'autoUpdate');
//define Permissions //define Permissions
$this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN); $this->maniaControl->authenticationManager->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
@ -69,11 +69,11 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
} }
/** /**
* Handle ManiaControl 1Minute callback * Perform Hourly Update Che
* *
* @param $time * @param $time
*/ */
public function handle1Minute($time) { public function hourlyUpdateCheck($time) {
$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 // Automatic update check disabled
@ -82,9 +82,10 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
} }
return; return;
} }
// Only check once per hour // 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;
} }
$this->lastUpdateCheck = time(); $this->lastUpdateCheck = time();
@ -94,6 +95,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
} }
$this->maniaControl->log('New ManiaControl Version ' . $updateData->version . ' available!'); $this->maniaControl->log('New ManiaControl Version ' . $updateData->version . ' available!');
$this->coreUpdateData = $updateData; $this->coreUpdateData = $updateData;
$this->autoUpdate($time);
} }
/** /**
@ -113,18 +116,18 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login); $this->maniaControl->chat->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
} }
/** /**
* Perform automatic update as soon as a the Server is empty * Perform automatic update as soon as a the Server is empty (also every hour got checked when its empty)
* *
* @param array $callback * @param mixed $callback
*/ */
public function handlePlayerDisconnected(array $callback) { public function autoUpdate($callback) {
$performBackup = $this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTO_UPDATE); $autoUpdate = $this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTO_UPDATE);
if (!$performBackup) { if (!$autoUpdate) {
return; return;
} }
if (count($this->maniaControl->playerManager->getPlayers()) > 0) { if (count($this->maniaControl->playerManager->getPlayers()) > 0) {
return; return;
} }
@ -148,6 +151,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$this->maniaControl->restart(); $this->maniaControl->restart();
} }
/** /**
* Handle //checkupdate command * Handle //checkupdate command
* *
@ -175,7 +179,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$releaseTime = strtotime($updateData->release_date); $releaseTime = strtotime($updateData->release_date);
if ($buildDate) { if ($buildDate) {
$buildTime = strtotime($buildDate); $buildTime = strtotime($buildDate);
if ($buildTime >= $releaseTime) { if ($buildTime >= $releaseTime) { //FIXME will ever fail, releaseTime > buildTime (because releaseTime "2014-02-01 14:59:49")
$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;
} }