TrackManiaControl/application/core/UpdateManager.php

512 lines
17 KiB
PHP
Raw Normal View History

2013-12-17 17:38:44 +01:00
<?php
namespace ManiaControl;
use ManiaControl\Admin\AuthenticationManager;
use ManiaControl\Callbacks\CallbackListener;
2014-01-31 00:04:40 +01:00
use ManiaControl\Callbacks\TimerListener;
2013-12-17 17:38:44 +01:00
use ManiaControl\Commands\CommandListener;
2014-02-10 16:52:16 +01:00
use ManiaControl\Files\FileUtil;
2013-12-17 17:38:44 +01:00
use ManiaControl\Players\Player;
use ManiaControl\Players\PlayerManager;
2014-01-28 16:23:50 +01:00
use ManiaControl\Plugins\Plugin;
2013-12-17 17:38:44 +01:00
/**
2013-12-31 18:42:54 +01:00
* Manager checking for ManiaControl Core and Plugin Updates
2013-12-17 17:38:44 +01:00
*
* @author steeffeen & kremsy
*/
2014-01-31 00:04:40 +01:00
class UpdateManager implements CallbackListener, CommandListener, TimerListener {
2014-01-19 22:32:09 +01:00
/*
2013-12-17 17:38:44 +01:00
* Constants
*/
2014-01-31 16:55:01 +01:00
const SETTING_ENABLEUPDATECHECK = 'Enable Automatic Core Update Check';
const SETTING_UPDATECHECK_INTERVAL = 'Core Update Check Interval (Hours)';
const SETTING_UPDATECHECK_CHANNEL = 'Core Update Channel (release, beta, nightly)';
const SETTING_PERFORM_BACKUPS = 'Perform Backup before Updating';
const SETTING_AUTO_UPDATE = 'Perform update automatically';
const SETTING_PERMISSION_UPDATE = 'Update Core';
const SETTING_PERMISSION_UPDATECHECK = 'Check Core Update';
const URL_WEBSERVICE = 'http://ws.maniacontrol.com/';
const CHANNEL_RELEASE = 'release';
const CHANNEL_BETA = 'beta';
const CHANNEL_NIGHTLY = 'nightly';
2014-01-20 21:54:58 +01:00
2014-01-19 22:32:09 +01:00
/*
2013-12-17 17:38:44 +01:00
* Private Properties
*/
private $maniaControl = null;
private $coreUpdateData = null;
2014-02-10 22:18:03 +01:00
private $currentBuildDate = "";
2013-12-17 17:38:44 +01:00
/**
2014-01-19 22:32:09 +01:00
* Create a new Update Manager
2013-12-17 17:38:44 +01:00
*
2013-12-31 17:17:40 +01:00
* @param ManiaControl $maniaControl
2013-12-17 17:38:44 +01:00
*/
public function __construct(ManiaControl $maniaControl) {
$this->maniaControl = $maniaControl;
2014-01-20 21:54:58 +01:00
2013-12-17 17:38:44 +01:00
// Init settings
$this->maniaControl->settingManager->initSetting($this, self::SETTING_ENABLEUPDATECHECK, true);
2014-01-21 19:12:55 +01:00
$this->maniaControl->settingManager->initSetting($this, self::SETTING_AUTO_UPDATE, true);
2014-02-10 16:46:41 +01:00
$this->maniaControl->settingManager->initSetting($this, self::SETTING_UPDATECHECK_INTERVAL, 1);
2014-01-19 23:32:13 +01:00
$this->maniaControl->settingManager->initSetting($this, self::SETTING_UPDATECHECK_CHANNEL, self::CHANNEL_NIGHTLY); //TODO just temp until release
2013-12-31 18:25:07 +01:00
$this->maniaControl->settingManager->initSetting($this, self::SETTING_PERFORM_BACKUPS, true);
2014-01-20 21:54:58 +01:00
2013-12-17 17:38:44 +01:00
// Register for callbacks
2014-02-10 16:46:41 +01:00
$updateInterval = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_INTERVAL);
$this->maniaControl->timerManager->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval);
2013-12-17 17:38:44 +01:00
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERJOINED, $this, 'handlePlayerJoined');
2014-02-01 18:33:06 +01:00
$this->maniaControl->callbackManager->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECTED, $this, 'autoUpdate');
2014-01-21 19:36:09 +01:00
2014-01-31 16:55:01 +01:00
//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);
2014-01-20 21:54:58 +01:00
2013-12-17 17:38:44 +01:00
// Register for chat commands
$this->maniaControl->commandManager->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true);
2013-12-31 18:25:07 +01:00
$this->maniaControl->commandManager->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true);
2014-02-10 21:32:41 +01:00
2014-02-10 22:18:03 +01:00
$this->currentBuildDate = $this->getNightlyBuildDate();
2013-12-17 17:38:44 +01:00
}
/**
2014-02-10 16:46:41 +01:00
* Perform Hourly Update Check
2013-12-17 17:38:44 +01:00
*
2014-01-31 00:04:40 +01:00
* @param $time
2013-12-17 17:38:44 +01:00
*/
2014-02-01 18:33:06 +01:00
public function hourlyUpdateCheck($time) {
2013-12-17 17:38:44 +01:00
$updateCheckEnabled = $this->maniaControl->settingManager->getSetting($this, self::SETTING_ENABLEUPDATECHECK);
2014-01-28 16:23:50 +01:00
if (!$updateCheckEnabled) {
2013-12-31 17:17:40 +01:00
// Automatic update check disabled
2014-01-28 16:23:50 +01:00
if ($this->coreUpdateData) {
2014-01-20 21:54:58 +01:00
$this->coreUpdateData = null;
}
2013-12-17 17:38:44 +01:00
return;
}
2014-02-01 18:33:06 +01:00
2014-02-10 21:32:41 +01:00
//Check if a new Core Update is Available
$this->checkCoreUpdateAsync(function ($updateData) use ($time) {
2014-02-10 22:18:03 +01:00
$buildDate = strtotime($this->currentBuildDate);
2014-02-10 21:32:41 +01:00
$releaseTime = strtotime($updateData->release_date);
if ($buildDate < $releaseTime) {
2014-02-10 22:18:03 +01:00
$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL);
if ($updateChannel != self::CHANNEL_NIGHTLY) {
$this->maniaControl->log('New ManiaControl Version ' . $updateData->version . ' available!');
} else {
$this->maniaControl->log('New Nightly Build (' . $updateData->release_date . ') available!');
}
2014-02-10 21:32:41 +01:00
$this->coreUpdateData = $updateData;
$this->autoUpdate($time);
}
}, true);
2013-12-17 17:38:44 +01:00
}
/**
* Handle ManiaControl PlayerJoined callback
*
2013-12-31 17:17:40 +01:00
* @param array $callback
2013-12-17 17:38:44 +01:00
*/
public function handlePlayerJoined(array $callback) {
2014-01-28 16:23:50 +01:00
if (!$this->coreUpdateData) {
2014-01-20 21:54:58 +01:00
return;
}
2013-12-31 17:17:40 +01:00
// Announce available update
2013-12-17 17:38:44 +01:00
$player = $callback[1];
2014-01-31 16:55:01 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
2014-01-20 21:54:58 +01:00
return;
}
2014-02-10 21:32:41 +01:00
2014-02-10 22:18:03 +01:00
$buildDate = strtotime($this->currentBuildDate);
2014-02-10 21:32:41 +01:00
$releaseTime = strtotime($this->coreUpdateData->release_date);
if ($buildDate < $releaseTime) {
2014-02-10 22:18:03 +01:00
$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 {
$this->maniaControl->chat->sendSuccess('New Nightly Build (' . $this->coreUpdateData->release_date . ') available!', $player->login);
}
2014-02-10 21:32:41 +01:00
}
2013-12-17 17:38:44 +01:00
}
2014-02-01 18:33:06 +01:00
2014-01-20 21:54:58 +01:00
/**
2014-02-01 18:33:06 +01:00
* Perform automatic update as soon as a the Server is empty (also every hour got checked when its empty)
2014-01-20 21:54:58 +01:00
*
2014-02-01 18:33:06 +01:00
* @param mixed $callback
2014-01-20 21:54:58 +01:00
*/
2014-02-01 18:33:06 +01:00
public function autoUpdate($callback) {
$autoUpdate = $this->maniaControl->settingManager->getSetting($this, self::SETTING_AUTO_UPDATE);
if (!$autoUpdate) {
2014-01-21 19:12:55 +01:00
return;
}
2014-01-28 16:23:50 +01:00
if (count($this->maniaControl->playerManager->getPlayers()) > 0) {
2014-01-20 21:54:58 +01:00
return;
}
2014-02-10 21:32:41 +01:00
if (!$this->coreUpdateData) {
2014-01-20 21:54:58 +01:00
return;
}
2014-02-10 22:18:03 +01:00
$buildDate = strtotime($this->currentBuildDate);
2014-02-10 21:32:41 +01:00
$releaseTime = strtotime($this->coreUpdateData->release_date);
if ($buildDate && $buildDate >= $releaseTime) {
return;
}
$this->maniaControl->log("Starting Update to Version v{$this->coreUpdateData->version}...");
2014-01-20 21:54:58 +01:00
$performBackup = $this->maniaControl->settingManager->getSetting($this, self::SETTING_PERFORM_BACKUPS);
2014-01-28 16:23:50 +01:00
if ($performBackup && !$this->performBackup()) {
2014-01-20 21:54:58 +01:00
$this->maniaControl->log("Creating Backup failed!");
}
2014-02-10 21:32:41 +01:00
$this->performCoreUpdate($this->coreUpdateData);
2014-01-20 21:54:58 +01:00
}
2014-02-01 18:33:06 +01:00
2013-12-17 17:38:44 +01:00
/**
* Handle //checkupdate command
*
2014-01-20 21:54:58 +01:00
* @param array $chatCallback
2013-12-31 17:17:40 +01:00
* @param Player $player
2013-12-17 17:38:44 +01:00
*/
public function handle_CheckUpdate(array $chatCallback, Player $player) {
2014-01-31 16:55:01 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATECHECK)) {
2013-12-17 17:38:44 +01:00
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
2014-01-19 22:32:09 +01:00
$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL);
2014-01-28 16:23:50 +01:00
if ($updateChannel != self::CHANNEL_NIGHTLY) {
2014-01-19 22:32:09 +01:00
// Check update and send result message
2014-02-10 22:18:03 +01:00
$this->checkCoreUpdateAsync(function ($updateData) use (&$player) {
if (!$updateData) {
$this->maniaControl->chat->sendInformation('No Update available!', $player->login);
return;
}
$this->maniaControl->chat->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
});
2014-01-20 21:54:58 +01:00
} else {
2014-01-19 22:32:09 +01:00
// Special nightly channel updating
2014-02-10 22:18:03 +01:00
$this->checkCoreUpdateAsync(function ($updateData) use (&$player) {
if (!$updateData) {
$this->maniaControl->chat->sendInformation('No Update available!', $player->login);
2014-01-19 22:32:09 +01:00
return;
}
2014-02-10 22:18:03 +01:00
$buildTime = strtotime($this->currentBuildDate);
$releaseTime = strtotime($updateData->release_date);
if ($buildTime != '') {
if ($buildTime >= $releaseTime) {
$this->maniaControl->chat->sendInformation('No new Build available, current build: ' . date("Y-m-d", $buildTime) . '!', $player->login);
return;
}
$this->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->release_date . ') available, current build: ' . $this->currentBuildDate . '!', $player->login);
} else {
$this->maniaControl->chat->sendSuccess('New Nightly Build (' . $updateData->release_date . ') available!', $player->login);
}
}, true);
2013-12-17 17:38:44 +01:00
}
2014-01-19 22:32:09 +01:00
}
/**
* Get the Build Date of the local Nightly Build Version
*
2014-02-10 22:18:03 +01:00
* @return String $buildTime
2014-01-19 22:32:09 +01:00
*/
private function getNightlyBuildDate() {
$nightlyBuildDateFile = ManiaControlDir . '/core/nightly_build.txt';
2014-01-28 16:23:50 +01:00
if (!file_exists($nightlyBuildDateFile)) {
2014-02-10 22:18:03 +01:00
return '';
2014-01-20 21:54:58 +01:00
}
2014-01-19 22:32:09 +01:00
$fileContent = file_get_contents($nightlyBuildDateFile);
return $fileContent;
2013-12-17 17:38:44 +01:00
}
2014-02-10 21:32:41 +01:00
/**
* 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);
2014-02-10 22:18:03 +01:00
$this->currentBuildDate = $date;
2014-02-10 21:32:41 +01:00
return $success;
}
2013-12-31 18:25:07 +01:00
/**
* Handle //coreupdate command
*
2014-01-20 21:54:58 +01:00
* @param array $chatCallback
2013-12-31 18:25:07 +01:00
* @param Player $player
*/
public function handle_CoreUpdate(array $chatCallback, Player $player) {
2014-01-28 16:23:50 +01:00
if (!$this->maniaControl->authenticationManager->checkPermission($player, self::SETTING_PERMISSION_UPDATE)) {
2013-12-31 18:25:07 +01:00
$this->maniaControl->authenticationManager->sendNotAllowed($player);
return;
}
2013-12-31 18:42:54 +01:00
$updateData = $this->checkCoreUpdate(true);
2014-01-28 16:23:50 +01:00
if (!$updateData) {
2013-12-31 18:42:54 +01:00
$this->maniaControl->chat->sendError('Update is currently not possible!', $player->login);
return;
}
2014-01-20 21:54:58 +01:00
2014-01-28 16:23:50 +01:00
$this->maniaControl->chat->sendInformation("Starting Update to Version v{$updateData->version}...", $player->login);
$this->maniaControl->log("Starting Update to Version v{$updateData->version}...");
$performBackup = $this->maniaControl->settingManager->getSetting($this, self::SETTING_PERFORM_BACKUPS);
if ($performBackup && !$this->performBackup()) {
$this->maniaControl->chat->sendError('Creating backup failed.', $player->login);
$this->maniaControl->log("Creating backup failed.");
}
$this->performCoreUpdate($updateData, $player);
}
2013-12-17 17:38:44 +01:00
/**
* Check given Plugin Class for Update
*
2013-12-31 17:17:40 +01:00
* @param string $pluginClass
2013-12-17 17:38:44 +01:00
* @return mixed
*/
public function checkPluginUpdate($pluginClass) {
2014-01-28 16:23:50 +01:00
if (is_object($pluginClass)) {
2013-12-17 17:38:44 +01:00
$pluginClass = get_class($pluginClass);
}
2014-01-28 16:23:50 +01:00
/** @var Plugin $pluginClass */
2014-01-20 21:54:58 +01:00
$pluginId = $pluginClass::getId();
$url = self::URL_WEBSERVICE . 'plugins?id=' . $pluginId;
2014-02-10 16:52:16 +01:00
$dataJson = FileUtil::loadFile($url);
2013-12-17 17:38:44 +01:00
$pluginVersions = json_decode($dataJson);
2014-01-28 16:23:50 +01:00
if (!$pluginVersions || !isset($pluginVersions[0])) {
2013-12-17 17:38:44 +01:00
return false;
}
2014-01-20 21:54:58 +01:00
$pluginData = $pluginVersions[0];
2013-12-17 17:38:44 +01:00
$pluginVersion = $pluginClass::getVersion();
2014-01-28 16:23:50 +01:00
if ($pluginData->version <= $pluginVersion) {
2013-12-17 17:38:44 +01:00
return false;
}
return $pluginData;
}
2014-02-10 21:32:41 +01:00
/**
* 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&current=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);
});
}
2013-12-17 17:38:44 +01:00
/**
* Check for Update of ManiaControl
*
* @return mixed
*/
2013-12-31 18:42:54 +01:00
private function checkCoreUpdate($ignoreVersion = false) {
2013-12-27 23:26:27 +01:00
$updateChannel = $this->getCurrentUpdateChannelSetting();
2014-01-20 21:54:58 +01:00
$url = self::URL_WEBSERVICE . 'versions?update=1&current=1&channel=' . $updateChannel;
2014-02-10 16:52:16 +01:00
$dataJson = FileUtil::loadFile($url);
2014-01-20 21:54:58 +01:00
$versions = json_decode($dataJson);
2014-01-28 16:23:50 +01:00
if (!$versions || !isset($versions[0])) {
2013-12-17 17:38:44 +01:00
return false;
}
$updateData = $versions[0];
2014-01-28 16:23:50 +01:00
if (!$ignoreVersion && $updateData->version <= ManiaControl::VERSION) {
2013-12-17 17:38:44 +01:00
return false;
}
return $updateData;
}
2013-12-27 23:26:27 +01:00
2013-12-31 18:25:07 +01:00
/**
* Perform a Backup of ManiaControl
*
* @return bool
*/
private function performBackup() {
$backupFolder = ManiaControlDir . '/backup/';
2014-01-28 16:23:50 +01:00
if (!is_dir($backupFolder)) {
2014-01-20 21:54:58 +01:00
mkdir($backupFolder);
}
2014-01-19 22:32:09 +01:00
$backupFileName = $backupFolder . 'backup_' . ManiaControl::VERSION . '_' . date('y-m-d') . '_' . time() . '.zip';
2014-01-20 21:54:58 +01:00
$backupZip = new \ZipArchive();
2014-01-28 16:23:50 +01:00
if ($backupZip->open($backupFileName, \ZipArchive::CREATE) !== TRUE) {
2013-12-31 18:25:07 +01:00
trigger_error("Couldn't create Backup Zip!");
return false;
}
2014-01-20 21:54:58 +01:00
$excludes = array('.', '..', 'backup', 'logs', 'ManiaControl.log');
$pathInfo = pathInfo(ManiaControlDir);
2013-12-31 18:25:07 +01:00
$parentPath = $pathInfo['dirname'] . '/';
2014-01-20 21:54:58 +01:00
$dirName = $pathInfo['basename'];
2013-12-31 18:25:07 +01:00
$backupZip->addEmptyDir($dirName);
$this->zipDirectory($backupZip, ManiaControlDir, strlen($parentPath), $excludes);
$backupZip->close();
return true;
}
/**
* Add a complete Directory to the ZipArchive
*
* @param \ZipArchive $zipArchive
2014-01-20 21:54:58 +01:00
* @param string $folderName
* @param int $prefixLength
* @param array $excludes
2013-12-31 18:25:07 +01:00
* @return bool
*/
private function zipDirectory(\ZipArchive &$zipArchive, $folderName, $prefixLength, array $excludes = array()) {
$folderHandle = opendir($folderName);
2014-01-28 16:23:50 +01:00
if (!$folderHandle) {
2013-12-31 18:25:07 +01:00
trigger_error("Couldn't open Folder '{$folderName}' for Backup!");
return false;
}
2014-01-20 21:54:58 +01:00
while(false !== ($file = readdir($folderHandle))) {
2014-01-28 16:23:50 +01:00
if (in_array($file, $excludes)) {
2014-01-20 21:54:58 +01:00
continue;
}
$filePath = $folderName . '/' . $file;
2013-12-31 18:25:07 +01:00
$localPath = substr($filePath, $prefixLength);
2014-01-28 16:23:50 +01:00
if (is_file($filePath)) {
2013-12-31 18:25:07 +01:00
$zipArchive->addFile($filePath, $localPath);
continue;
}
2014-01-28 16:23:50 +01:00
if (is_dir($filePath)) {
2013-12-31 18:25:07 +01:00
$zipArchive->addEmptyDir($localPath);
$this->zipDirectory($zipArchive, $filePath, $prefixLength, $excludes);
continue;
}
}
closedir($folderHandle);
return true;
}
2013-12-27 23:26:27 +01:00
/**
* Perform a Core Update
*
* @param object $updateData
* @param Players\Player $player
2013-12-27 23:26:27 +01:00
* @return bool
*/
2014-02-10 21:32:41 +01:00
private function performCoreUpdate($updateData, Player $player = null) {
2014-01-28 16:23:50 +01:00
if (!$this->checkPermissions()) {
if ($player != null) {
$this->maniaControl->chat->sendError('Update failed: Incorrect Filesystem permissions!', $player->login);
}
$this->maniaControl->log('Update failed!');
2014-01-28 16:23:50 +01:00
return false;
}
2014-02-10 21:32:41 +01:00
if (!isset($updateData->url) && !isset($updateData->release_date)) {
if ($player != null) {
$this->maniaControl->chat->sendError('Update failed: No update Data available!', $player->login);
2013-12-27 23:26:27 +01:00
}
2014-02-10 21:32:41 +01:00
$this->maniaControl->log('Update failed: No update Data available!');
return false;
2013-12-27 23:26:27 +01:00
}
$this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use (&$updateData, &$player) {
$tempDir = ManiaControlDir . '/temp/';
if (!is_dir($tempDir)) {
mkdir($tempDir);
}
$updateFileName = $tempDir . basename($updateData->url);
$bytes = file_put_contents($updateFileName, $updateFileContent);
if (!$bytes || $bytes <= 0) {
trigger_error("Couldn't save Update Zip.");
if ($player != null) {
$this->maniaControl->chat->sendError('Update failed: Couldn\'t save Update zip!', $player->login);
}
return false;
}
$zip = new \ZipArchive();
$result = $zip->open($updateFileName);
if ($result !== true) {
trigger_error("Couldn't open Update Zip. ({$result})");
if ($player != null) {
$this->maniaControl->chat->sendError('Update failed: Couldn\'t open Update zip!', $player->login);
}
return false;
}
$zip->extractTo(ManiaControlDir);
$zip->close();
unlink($updateFileName);
@rmdir($tempDir);
2014-02-10 21:32:41 +01:00
//Set the Nightly Build Date
$this->setNightlyBuildDate($updateData->release_date);
if ($player != null) {
$this->maniaControl->chat->sendSuccess('Update finished!', $player->login);
}
$this->maniaControl->log("Update finished!");
$this->maniaControl->restart();
return true;
});
2013-12-27 23:26:27 +01:00
return true;
}
2014-01-28 16:23:50 +01:00
/**
* Function checks if ManiaControl has sufficient access to files to update them.
*
* @return bool
*/
private function checkPermissions() {
$writableDirectories = array('core/', 'plugins/');
$path = str_replace('core', '', realpath(dirname(__FILE__)));
foreach($writableDirectories as $writableDirecotry) {
$files = array();
$di = new \RecursiveDirectoryIterator($path . $writableDirecotry);
foreach(new \RecursiveIteratorIterator($di) as $filename => $file) {
$files[] = $filename;
}
foreach($files as $file) {
if (substr($file, -1) != '.' && substr($file, -2) != '..') {
if (!is_writable($file)) {
$this->maniaControl->log('Cannot update: the file/directory "' . $file . '" is not writable!');
return false;
}
}
}
}
return true;
}
2013-12-27 23:26:27 +01:00
/**
* Retrieve the Update Channel Setting
*
* @return string
*/
private function getCurrentUpdateChannelSetting() {
$updateChannel = $this->maniaControl->settingManager->getSetting($this, self::SETTING_UPDATECHECK_CHANNEL);
$updateChannel = strtolower($updateChannel);
2014-01-28 16:23:50 +01:00
if (!in_array($updateChannel, array(self::CHANNEL_RELEASE, self::CHANNEL_BETA, self::CHANNEL_NIGHTLY))) {
2013-12-27 23:26:27 +01:00
$updateChannel = self::CHANNEL_RELEASE;
}
return $updateChannel;
}
2013-12-17 17:38:44 +01:00
}