refactor codestyle (chaining)
This commit is contained in:
@ -40,14 +40,11 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Callbacks
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(CallbackManager::CB_MP_PLAYERMANIALINKPAGEANSWER, $this, 'handleManialinkPageAnswer');
|
||||
|
||||
// Chat commands
|
||||
$this->maniaControl->getCommandManager()
|
||||
->registerCommandListener('checkpluginsupdate', $this, 'handle_CheckPluginsUpdate', true, 'Check for Plugin Updates.');
|
||||
$this->maniaControl->getCommandManager()
|
||||
->registerCommandListener('pluginsupdate', $this, 'handle_PluginsUpdate', true, 'Perform the Plugin Updates.');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('checkpluginsupdate', $this, 'handle_CheckPluginsUpdate', true, 'Check for Plugin Updates.');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('pluginsupdate', $this, 'handle_PluginsUpdate', true, 'Perform the Plugin Updates.');
|
||||
}
|
||||
|
||||
/**
|
||||
@ -57,11 +54,9 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handle_CheckPluginsUpdate(array $chatCallback, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATECHECK)
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATECHECK)
|
||||
) {
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->sendNotAllowed($player);
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -76,65 +71,58 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
public function checkPluginsUpdate(Player $player = null) {
|
||||
$message = 'Checking Plugins for newer Versions...';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation($message, $player);
|
||||
$this->maniaControl->getChat()->sendInformation($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
|
||||
$this->maniaControl->getPluginManager()
|
||||
->fetchPluginList(function ($data, $error) use (&$player) {
|
||||
if (!$data || $error) {
|
||||
$message = 'Error while checking Plugins for newer Versions!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->getPluginManager()->fetchPluginList(function ($data, $error) use (&$player) {
|
||||
if (!$data || $error) {
|
||||
$message = 'Error while checking Plugins for newer Versions!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
|
||||
$pluginsData = $this->parsePluginsData($data);
|
||||
$pluginClasses = $this->maniaControl->getPluginManager()
|
||||
->getPluginClasses();
|
||||
$pluginUpdates = array();
|
||||
$pluginsData = $this->parsePluginsData($data);
|
||||
$pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses();
|
||||
$pluginUpdates = array();
|
||||
|
||||
foreach ($pluginClasses as $pluginClass) {
|
||||
/** @var Plugin $pluginClass */
|
||||
$pluginId = $pluginClass::getId();
|
||||
if (!isset($pluginsData[$pluginId])) {
|
||||
continue;
|
||||
}
|
||||
/** @var PluginUpdateData $pluginData */
|
||||
$pluginData = $pluginsData[$pluginId];
|
||||
$pluginVersion = $pluginClass::getVersion();
|
||||
if ($pluginData->isNewerThan($pluginVersion)) {
|
||||
$pluginUpdates[$pluginId] = $pluginData;
|
||||
$message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
}
|
||||
}
|
||||
foreach ($pluginClasses as $pluginClass) {
|
||||
/** @var Plugin $pluginClass */
|
||||
$pluginId = $pluginClass::getId();
|
||||
if (!isset($pluginsData[$pluginId])) {
|
||||
continue;
|
||||
}
|
||||
/** @var PluginUpdateData $pluginData */
|
||||
$pluginData = $pluginsData[$pluginId];
|
||||
$pluginVersion = $pluginClass::getVersion();
|
||||
if ($pluginData->isNewerThan($pluginVersion)) {
|
||||
$pluginUpdates[$pluginId] = $pluginData;
|
||||
$message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
}
|
||||
}
|
||||
|
||||
if (empty($pluginUpdates)) {
|
||||
$message = 'Plugins Update Check completed: All Plugins are up-to-date!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
} else {
|
||||
$updatesCount = count($pluginUpdates);
|
||||
$message = "Plugins Update Check completed: There are {$updatesCount} Updates available!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
}
|
||||
});
|
||||
if (empty($pluginUpdates)) {
|
||||
$message = 'Plugins Update Check completed: All Plugins are up-to-date!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
} else {
|
||||
$updatesCount = count($pluginUpdates);
|
||||
$message = "Plugins Update Check completed: There are {$updatesCount} Updates available!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -162,11 +150,9 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handle_PluginsUpdate(array $chatCallback, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATE)
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, UpdateManager::SETTING_PERMISSION_UPDATE)
|
||||
) {
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->sendNotAllowed($player);
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -183,8 +169,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
if (empty($pluginsUpdates)) {
|
||||
$message = 'There are no Plugin Updates available!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation($message, $player);
|
||||
$this->maniaControl->getChat()->sendInformation($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
return;
|
||||
@ -192,18 +177,15 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
|
||||
$message = "Starting Plugins Updating...";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation($message, $player);
|
||||
$this->maniaControl->getChat()->sendInformation($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
|
||||
$performBackup = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this->maniaControl->getUpdateManager(), UpdateManager::SETTING_PERFORM_BACKUPS);
|
||||
$performBackup = $this->maniaControl->getSettingManager()->getSettingValue($this->maniaControl->getUpdateManager(), UpdateManager::SETTING_PERFORM_BACKUPS);
|
||||
if ($performBackup && !BackupUtil::performPluginsBackup()) {
|
||||
$message = 'Creating Backup before Plugins Update failed!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
}
|
||||
@ -230,8 +212,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
$pluginsUpdates = $this->parsePluginsData($pluginData);
|
||||
|
||||
$updates = array();
|
||||
$pluginClasses = $this->maniaControl->getPluginManager()
|
||||
->getPluginClasses();
|
||||
$pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses();
|
||||
foreach ($pluginClasses as $pluginClass) {
|
||||
/** @var Plugin $pluginClass */
|
||||
$pluginId = $pluginClass::getId();
|
||||
@ -259,96 +240,86 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
* @param bool $update
|
||||
*/
|
||||
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
|
||||
$this->maniaControl->getFileReader()
|
||||
->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (
|
||||
&$pluginUpdateData, &$player, &$update
|
||||
) {
|
||||
if (!$updateFileContent || $error) {
|
||||
$message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->getFileReader()->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (
|
||||
&$pluginUpdateData, &$player, &$update
|
||||
) {
|
||||
if (!$updateFileContent || $error) {
|
||||
$message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendInformation($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
|
||||
$actionNoun = ($update ? 'Update' : 'Install');
|
||||
$actionVerb = ($update ? 'Updating' : 'Installing');
|
||||
$actionVerbDone = ($update ? 'updated' : 'installed');
|
||||
$actionNoun = ($update ? 'Update' : 'Install');
|
||||
$actionVerb = ($update ? 'Updating' : 'Installing');
|
||||
$actionVerbDone = ($update ? 'updated' : 'installed');
|
||||
|
||||
$message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'...";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
$message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'...";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendInformation($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
|
||||
$tempDir = FileUtil::getTempFolder();
|
||||
$updateFileName = $tempDir . $pluginUpdateData->zipfile;
|
||||
$tempDir = FileUtil::getTempFolder();
|
||||
$updateFileName = $tempDir . $pluginUpdateData->zipfile;
|
||||
|
||||
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
||||
if (!$bytes || $bytes <= 0) {
|
||||
$message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
||||
if (!$bytes || $bytes <= 0) {
|
||||
$message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
$result = $zip->open($updateFileName);
|
||||
if ($result !== true) {
|
||||
$message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
$zip = new \ZipArchive();
|
||||
$result = $zip->open($updateFileName);
|
||||
if ($result !== true) {
|
||||
$message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
|
||||
$zip->extractTo(MANIACONTROL_PATH . 'plugins' . DIRECTORY_SEPARATOR);
|
||||
$zip->close();
|
||||
unlink($updateFileName);
|
||||
FileUtil::deleteTempFolder();
|
||||
$zip->extractTo(MANIACONTROL_PATH . 'plugins' . DIRECTORY_SEPARATOR);
|
||||
$zip->close();
|
||||
unlink($updateFileName);
|
||||
FileUtil::deleteTempFolder();
|
||||
|
||||
$messageExtra = '';
|
||||
if ($update) {
|
||||
$messageExtra = ' (Restart ManiaControl to load the new Version!)';
|
||||
}
|
||||
$message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
$messageExtra = '';
|
||||
if ($update) {
|
||||
$messageExtra = ' (Restart ManiaControl to load the new Version!)';
|
||||
}
|
||||
$message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
|
||||
if (!$update) {
|
||||
$newPluginClasses = $this->maniaControl->getPluginManager()
|
||||
->loadPlugins();
|
||||
if (empty($newPluginClasses)) {
|
||||
$message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
} else {
|
||||
$message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
if (!$update) {
|
||||
$newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins();
|
||||
if (empty($newPluginClasses)) {
|
||||
$message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
} else {
|
||||
$message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
|
||||
$this->maniaControl->getConfigurator()
|
||||
->showMenu($player, InstallMenu::getTitle());
|
||||
}
|
||||
}
|
||||
});
|
||||
$this->maniaControl->getConfigurator()->showMenu($player, InstallMenu::getTitle());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -365,8 +336,7 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
}
|
||||
|
||||
$login = $callback[1][1];
|
||||
$player = $this->maniaControl->getPlayerManager()
|
||||
->getPlayer($login);
|
||||
$player = $this->maniaControl->getPlayerManager()->getPlayer($login);
|
||||
|
||||
if ($update) {
|
||||
$pluginClass = substr($actionId, strlen(PluginMenu::ACTION_PREFIX_UPDATEPLUGIN));
|
||||
@ -378,34 +348,30 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
|
||||
$this->installPlugin($pluginUpdateData, $player, true);
|
||||
} else {
|
||||
$message = 'Error loading Plugin Update Data!';
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$pluginId = substr($actionId, strlen(InstallMenu::ACTION_PREFIX_INSTALL_PLUGIN));
|
||||
|
||||
$url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId;
|
||||
$this->maniaControl->getFileReader()
|
||||
->loadFile($url, function ($data, $error) use (&$player) {
|
||||
if ($error || !$data) {
|
||||
$message = "Error loading Plugin Install Data! {$error}";
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->getFileReader()->loadFile($url, function ($data, $error) use (&$player) {
|
||||
if ($error || !$data) {
|
||||
$message = "Error loading Plugin Install Data! {$error}";
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
return;
|
||||
}
|
||||
|
||||
$data = json_decode($data);
|
||||
if (!$data) {
|
||||
$message = "Error loading Plugin Install Data! {$error}";
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
return;
|
||||
}
|
||||
$data = json_decode($data);
|
||||
if (!$data) {
|
||||
$message = "Error loading Plugin Install Data! {$error}";
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
return;
|
||||
}
|
||||
|
||||
$pluginUpdateData = new PluginUpdateData($data);
|
||||
$this->installPlugin($pluginUpdateData, $player);
|
||||
});
|
||||
$pluginUpdateData = new PluginUpdateData($data);
|
||||
$this->installPlugin($pluginUpdateData, $player);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -60,38 +60,25 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
$this->maniaControl = $maniaControl;
|
||||
|
||||
// Settings
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_ENABLE_UPDATECHECK, true);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_AUTO_UPDATE, true);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_UPDATECHECK_INTERVAL, 1);
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_UPDATECHECK_CHANNEL, $this->getUpdateChannels());
|
||||
$this->maniaControl->getSettingManager()
|
||||
->initSetting($this, self::SETTING_PERFORM_BACKUPS, true);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_ENABLE_UPDATECHECK, true);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_AUTO_UPDATE, true);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_UPDATECHECK_INTERVAL, 1);
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_UPDATECHECK_CHANNEL, $this->getUpdateChannels());
|
||||
$this->maniaControl->getSettingManager()->initSetting($this, self::SETTING_PERFORM_BACKUPS, true);
|
||||
|
||||
// Callbacks
|
||||
$updateInterval = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_UPDATECHECK_INTERVAL);
|
||||
$this->maniaControl->getTimerManager()
|
||||
->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval);
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
||||
$this->maniaControl->getCallbackManager()
|
||||
->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
||||
$updateInterval = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_UPDATECHECK_INTERVAL);
|
||||
$this->maniaControl->getTimerManager()->registerTimerListening($this, 'hourlyUpdateCheck', 1000 * 60 * 60 * $updateInterval);
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERCONNECT, $this, 'handlePlayerJoined');
|
||||
$this->maniaControl->getCallbackManager()->registerCallbackListener(PlayerManager::CB_PLAYERDISCONNECT, $this, 'handlePlayerDisconnect');
|
||||
|
||||
// Permissions
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->definePermissionLevel(self::SETTING_PERMISSION_UPDATECHECK, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_UPDATE, AuthenticationManager::AUTH_LEVEL_ADMIN);
|
||||
$this->maniaControl->getAuthenticationManager()->definePermissionLevel(self::SETTING_PERMISSION_UPDATECHECK, AuthenticationManager::AUTH_LEVEL_MODERATOR);
|
||||
|
||||
// Chat commands
|
||||
$this->maniaControl->getCommandManager()
|
||||
->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true, 'Checks if there is a core update.');
|
||||
$this->maniaControl->getCommandManager()
|
||||
->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true, 'Performs the core update.');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('checkupdate', $this, 'handle_CheckUpdate', true, 'Checks if there is a core update.');
|
||||
$this->maniaControl->getCommandManager()->registerCommandListener('coreupdate', $this, 'handle_CoreUpdate', true, 'Performs the core update.');
|
||||
|
||||
// Children
|
||||
$this->pluginUpdateManager = new PluginUpdateManager($maniaControl);
|
||||
@ -120,8 +107,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* Perform Hourly Update Check
|
||||
*/
|
||||
public function hourlyUpdateCheck() {
|
||||
$updateCheckEnabled = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_ENABLE_UPDATECHECK);
|
||||
$updateCheckEnabled = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_ENABLE_UPDATECHECK);
|
||||
if (!$updateCheckEnabled) {
|
||||
$this->setCoreUpdateData();
|
||||
} else {
|
||||
@ -154,20 +140,19 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
$updateChannel = $this->getCurrentUpdateChannelSetting();
|
||||
$url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel;
|
||||
|
||||
$this->maniaControl->getFileReader()
|
||||
->loadFile($url, function ($dataJson, $error) use (&$function) {
|
||||
if ($error) {
|
||||
Logger::logError('Error on UpdateCheck: ' . $error);
|
||||
return;
|
||||
}
|
||||
$versions = json_decode($dataJson);
|
||||
if (!$versions || !isset($versions[0])) {
|
||||
call_user_func($function);
|
||||
} else {
|
||||
$updateData = new UpdateData($versions[0]);
|
||||
call_user_func($function, $updateData);
|
||||
}
|
||||
});
|
||||
$this->maniaControl->getFileReader()->loadFile($url, function ($dataJson, $error) use (&$function) {
|
||||
if ($error) {
|
||||
Logger::logError('Error on UpdateCheck: ' . $error);
|
||||
return;
|
||||
}
|
||||
$versions = json_decode($dataJson);
|
||||
if (!$versions || !isset($versions[0])) {
|
||||
call_user_func($function);
|
||||
} else {
|
||||
$updateData = new UpdateData($versions[0]);
|
||||
call_user_func($function, $updateData);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@ -176,8 +161,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* @return string
|
||||
*/
|
||||
public function getCurrentUpdateChannelSetting() {
|
||||
$updateChannel = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_UPDATECHECK_CHANNEL);
|
||||
$updateChannel = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_UPDATECHECK_CHANNEL);
|
||||
$updateChannel = strtolower($updateChannel);
|
||||
if (!in_array($updateChannel, $this->getUpdateChannels())) {
|
||||
$updateChannel = self::CHANNEL_RELEASE;
|
||||
@ -275,8 +259,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
return false;
|
||||
}
|
||||
|
||||
$version = $this->maniaControl->getClient()
|
||||
->getVersion();
|
||||
$version = $this->maniaControl->getClient()->getVersion();
|
||||
if ($updateData->minDedicatedBuild > $version->build) {
|
||||
// Server not compatible
|
||||
return false;
|
||||
@ -289,8 +272,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* Check if an automatic Update should be performed
|
||||
*/
|
||||
public function checkAutoUpdate() {
|
||||
$autoUpdate = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_AUTO_UPDATE);
|
||||
$autoUpdate = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_AUTO_UPDATE);
|
||||
if (!$autoUpdate) {
|
||||
// Auto update turned off
|
||||
return;
|
||||
@ -299,8 +281,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
// No update available
|
||||
return;
|
||||
}
|
||||
if ($this->maniaControl->getPlayerManager()
|
||||
->getPlayerCount(false) > 0
|
||||
if ($this->maniaControl->getPlayerManager()->getPlayerCount(false) > 0
|
||||
) {
|
||||
// Server not empty
|
||||
return;
|
||||
@ -319,8 +300,7 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
if (!$this->coreUpdateData) {
|
||||
$message = 'Update failed: No update Data available!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return false;
|
||||
@ -332,92 +312,83 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
if (!FileUtil::checkWritePermissions($directories)) {
|
||||
$message = 'Update not possible: Incorrect File System Permissions!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return false;
|
||||
}
|
||||
|
||||
$performBackup = $this->maniaControl->getSettingManager()
|
||||
->getSettingValue($this, self::SETTING_PERFORM_BACKUPS);
|
||||
$performBackup = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_PERFORM_BACKUPS);
|
||||
if ($performBackup && !BackupUtil::performFullBackup()) {
|
||||
$message = 'Creating Backup before Update failed!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
}
|
||||
|
||||
$updateData = $this->coreUpdateData;
|
||||
$this->maniaControl->getFileReader()
|
||||
->loadFile($updateData->url, function ($updateFileContent, $error) use (
|
||||
$updateData, &$player
|
||||
) {
|
||||
if (!$updateFileContent || $error) {
|
||||
$message = "Update failed: Couldn't load Update zip! {$error}";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
$this->maniaControl->getFileReader()->loadFile($updateData->url, function ($updateFileContent, $error) use (
|
||||
$updateData, &$player
|
||||
) {
|
||||
if (!$updateFileContent || $error) {
|
||||
$message = "Update failed: Couldn't load Update zip! {$error}";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
|
||||
$tempDir = FileUtil::getTempFolder();
|
||||
if (!$tempDir) {
|
||||
$message = "Update failed: Can't save Update zip!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
$updateFileName = $tempDir . basename($updateData->url);
|
||||
$tempDir = FileUtil::getTempFolder();
|
||||
if (!$tempDir) {
|
||||
$message = "Update failed: Can't save Update zip!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
$updateFileName = $tempDir . basename($updateData->url);
|
||||
|
||||
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
||||
if (!$bytes || $bytes <= 0) {
|
||||
$message = "Update failed: Couldn't save Update zip!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
||||
if (!$bytes || $bytes <= 0) {
|
||||
$message = "Update failed: Couldn't save Update zip!";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
return;
|
||||
}
|
||||
|
||||
$zip = new \ZipArchive();
|
||||
$result = $zip->open($updateFileName);
|
||||
if ($result !== true) {
|
||||
$message = "Update failed: Couldn't open Update Zip. ({$result})";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
unlink($updateFileName);
|
||||
return;
|
||||
}
|
||||
$zip = new \ZipArchive();
|
||||
$result = $zip->open($updateFileName);
|
||||
if ($result !== true) {
|
||||
$message = "Update failed: Couldn't open Update Zip. ({$result})";
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendError($message, $player);
|
||||
}
|
||||
Logger::logError($message);
|
||||
unlink($updateFileName);
|
||||
return;
|
||||
}
|
||||
|
||||
$zip->extractTo(MANIACONTROL_PATH);
|
||||
$zip->close();
|
||||
unlink($updateFileName);
|
||||
FileUtil::deleteTempFolder();
|
||||
$zip->extractTo(MANIACONTROL_PATH);
|
||||
$zip->close();
|
||||
unlink($updateFileName);
|
||||
FileUtil::deleteTempFolder();
|
||||
|
||||
// Set the Nightly Build Date
|
||||
$this->setNightlyBuildDate($updateData->releaseDate);
|
||||
// Set the Nightly Build Date
|
||||
$this->setNightlyBuildDate($updateData->releaseDate);
|
||||
|
||||
$message = 'Update finished!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
$message = 'Update finished!';
|
||||
if ($player) {
|
||||
$this->maniaControl->getChat()->sendSuccess($message, $player);
|
||||
}
|
||||
Logger::log($message);
|
||||
|
||||
$this->maniaControl->restart();
|
||||
});
|
||||
$this->maniaControl->restart();
|
||||
});
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -445,18 +416,15 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
return;
|
||||
}
|
||||
// Announce available update
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, self::SETTING_PERMISSION_UPDATE)
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATE)
|
||||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
if ($this->isNightlyUpdateChannel()) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login);
|
||||
$this->maniaControl->getChat()->sendSuccess('New Nightly Build (' . $this->coreUpdateData->releaseDate . ') available!', $player->login);
|
||||
} else {
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
|
||||
$this->maniaControl->getChat()->sendInformation('New ManiaControl Version ' . $this->coreUpdateData->version . ' available!', $player->login);
|
||||
}
|
||||
}
|
||||
|
||||
@ -476,24 +444,20 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handle_CheckUpdate(array $chatCallback, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, self::SETTING_PERMISSION_UPDATECHECK)
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATECHECK)
|
||||
) {
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->sendNotAllowed($player);
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
|
||||
if (!$this->checkUpdateData($updateData)) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation('No Update available!', $player->login);
|
||||
$this->maniaControl->getChat()->sendInformation('No Update available!', $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!$this->checkUpdateDataBuildVersion($updateData)) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login);
|
||||
$this->maniaControl->getChat()->sendError("Please update Your Server to '{$updateData->minDedicatedBuild}' in order to receive further Updates!", $player->login);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -502,20 +466,16 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
$buildDate = $this->getNightlyBuildDate();
|
||||
if ($buildDate) {
|
||||
if ($updateData->isNewerThan($buildDate)) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login);
|
||||
$this->maniaControl->getChat()->sendInformation("No new Build available! (Current Build: '{$buildDate}')", $player->login);
|
||||
return;
|
||||
} else {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login);
|
||||
$this->maniaControl->getChat()->sendSuccess("New Nightly Build ({$updateData->releaseDate}) available! (Current Build: '{$buildDate}')", $player->login);
|
||||
}
|
||||
} else {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login);
|
||||
$this->maniaControl->getChat()->sendSuccess("New Nightly Build ('{$updateData->releaseDate}') available!", $player->login);
|
||||
}
|
||||
} else {
|
||||
$this->maniaControl->getChat()
|
||||
->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
|
||||
$this->maniaControl->getChat()->sendSuccess('Update for Version ' . $updateData->version . ' available!', $player->login);
|
||||
}
|
||||
|
||||
$this->coreUpdateData = $updateData;
|
||||
@ -529,23 +489,19 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
||||
* @param Player $player
|
||||
*/
|
||||
public function handle_CoreUpdate(array $chatCallback, Player $player) {
|
||||
if (!$this->maniaControl->getAuthenticationManager()
|
||||
->checkPermission($player, self::SETTING_PERMISSION_UPDATE)
|
||||
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($player, self::SETTING_PERMISSION_UPDATE)
|
||||
) {
|
||||
$this->maniaControl->getAuthenticationManager()
|
||||
->sendNotAllowed($player);
|
||||
$this->maniaControl->getAuthenticationManager()->sendNotAllowed($player);
|
||||
return;
|
||||
}
|
||||
|
||||
$this->checkCoreUpdateAsync(function (UpdateData $updateData = null) use (&$player) {
|
||||
if (!$updateData) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError('Update is currently not possible!', $player);
|
||||
$this->maniaControl->getChat()->sendError('Update is currently not possible!', $player);
|
||||
return;
|
||||
}
|
||||
if (!$this->checkUpdateDataBuildVersion($updateData)) {
|
||||
$this->maniaControl->getChat()
|
||||
->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player);
|
||||
$this->maniaControl->getChat()->sendError("The Next ManiaControl Update requires a newer Dedicated Server Version!", $player);
|
||||
return;
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user