performed code formatting

This commit is contained in:
Steffen Schröder 2014-08-25 15:33:22 +02:00
parent a224bba6b9
commit 8612521559
12 changed files with 275 additions and 283 deletions

View File

@ -208,8 +208,7 @@ class Chat {
* @param int $minLevel * @param int $minLevel
* @param bool|string $prefix * @param bool|string $prefix
*/ */
public function sendExceptionToAdmins(\Exception $exception, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, public function sendExceptionToAdmins(\Exception $exception, $minLevel = AuthenticationManager::AUTH_LEVEL_MODERATOR, $prefix = true) {
$prefix = true) {
$format = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_FORMAT_ERROR); $format = $this->maniaControl->getSettingManager()->getSettingValue($this, self::SETTING_FORMAT_ERROR);
$message = $format . "Exception: '{$exception->getMessage()}' ({$exception->getCode()})"; $message = $format . "Exception: '{$exception->getMessage()}' ({$exception->getCode()})";
$this->sendMessageToAdmins($message, $minLevel, $prefix); $this->sendMessageToAdmins($message, $minLevel, $prefix);

View File

@ -61,8 +61,7 @@ class CommandManager implements CallbackListener {
* @param string $description * @param string $description
* @return bool * @return bool
*/ */
public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false, public function registerCommandListener($commandName, CommandListener $listener, $method, $adminCommand = false, $description = null) {
$description = null) {
if (is_array($commandName)) { if (is_array($commandName)) {
$success = false; $success = false;
foreach ($commandName as $command) { foreach ($commandName as $command) {

View File

@ -120,8 +120,7 @@ class AsynchronousFileReader {
array_push($this->requests, $request); array_push($this->requests, $request);
} }
public function postDataTest(Request $request, $url, callable $function, $content, $compression = false, public function postDataTest(Request $request, $url, callable $function, $content, $compression = false, $contentType = 'text/xml; charset=UTF-8;') {
$contentType = 'text/xml; charset=UTF-8;') {
$headers = array(); $headers = array();
array_push($headers, 'Content-Type: ' . $contentType); array_push($headers, 'Content-Type: ' . $contentType);
@ -163,8 +162,7 @@ class AsynchronousFileReader {
* @param bool $compression * @param bool $compression
* @param string $contentType * @param string $contentType
*/ */
public function postData($url, callable $function, $content, $compression = false, public function postData($url, callable $function, $content, $compression = false, $contentType = 'text/xml; charset=UTF-8;') {
$contentType = 'text/xml; charset=UTF-8;') {
$headers = array(); $headers = array();
array_push($headers, 'Content-Type: ' . $contentType); array_push($headers, 'Content-Type: ' . $contentType);

View File

@ -68,8 +68,7 @@ abstract class BackupUtil {
* @param array $baseFileNames * @param array $baseFileNames
* @return bool * @return bool
*/ */
private static function zipDirectory(\ZipArchive &$zipArchive, $folderName, $prefixLength, array $excludes = array(), private static function zipDirectory(\ZipArchive &$zipArchive, $folderName, $prefixLength, array $excludes = array(), array $baseFileNames = array()) {
array $baseFileNames = array()) {
$folderHandle = opendir($folderName); $folderHandle = opendir($folderName);
if (!is_resource($folderHandle)) { if (!is_resource($folderHandle)) {
Logger::logError("Couldn't open folder '{$folderName}' for backup!"); Logger::logError("Couldn't open folder '{$folderName}' for backup!");

View File

@ -132,12 +132,12 @@ class ManiaExchangeList implements CallbackListener, ManialinkPageAnswerListener
// search for matching maps // search for matching maps
$this->maniaControl->getMapManager()->getMXManager()->fetchMapsAsync(function (array $maps) use (&$player) { $this->maniaControl->getMapManager()->getMXManager()->fetchMapsAsync(function (array $maps) use (&$player) {
if (!$maps) { if (!$maps) {
$this->maniaControl->getChat()->sendError('No maps found, or MX is down!', $player->login); $this->maniaControl->getChat()->sendError('No maps found, or MX is down!', $player->login);
return; return;
} }
$this->showManiaExchangeList($maps, $player); $this->showManiaExchangeList($maps, $player);
}, $searchString, $author, $environment); }, $searchString, $author, $environment);
} }
/** /**

View File

@ -159,32 +159,32 @@ class ManiaExchangeManager {
$url = "http://api.mania-exchange.com/{$titlePrefix}/maps/?ids={$string}"; $url = "http://api.mania-exchange.com/{$titlePrefix}/maps/?ids={$string}";
$this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use ($titlePrefix, $url) { $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use ($titlePrefix, $url) {
if ($error) { if ($error) {
trigger_error("Error: '{$error}' for Url '{$url}'"); trigger_error("Error: '{$error}' for Url '{$url}'");
return; return;
} }
if (!$mapInfo) { if (!$mapInfo) {
return; return;
} }
$mxMapList = json_decode($mapInfo); $mxMapList = json_decode($mapInfo);
if ($mxMapList === null) { if ($mxMapList === null) {
trigger_error("Can't decode searched JSON Data from Url '{$url}'"); trigger_error("Can't decode searched JSON Data from Url '{$url}'");
return; return;
} }
$maps = array(); $maps = array();
foreach ($mxMapList as $map) { foreach ($mxMapList as $map) {
if ($map) { if ($map) {
$mxMapObject = new MXMapInfo($titlePrefix, $map); $mxMapObject = new MXMapInfo($titlePrefix, $map);
if ($mxMapObject) { if ($mxMapObject) {
array_push($maps, $mxMapObject); array_push($maps, $mxMapObject);
} }
} }
} }
$this->updateMapObjectsWithManiaExchangeIds($maps); $this->updateMapObjectsWithManiaExchangeIds($maps);
}, AsynchronousFileReader::CONTENT_TYPE_JSON); }, AsynchronousFileReader::CONTENT_TYPE_JSON);
} }
/** /**
@ -252,27 +252,26 @@ class ManiaExchangeManager {
$url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $mapId; $url = 'http://api.mania-exchange.com/' . $titlePrefix . '/maps/?ids=' . $mapId;
$this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) { $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix, $url) {
$mxMapInfo = null; $mxMapInfo = null;
if ($error) { if ($error) {
trigger_error($error); trigger_error($error);
} else { } else {
$mxMapList = json_decode($mapInfo); $mxMapList = json_decode($mapInfo);
if (!is_array($mxMapList)) { if (!is_array($mxMapList)) {
trigger_error('Cannot decode searched JSON data from ' . $url); trigger_error('Cannot decode searched JSON data from ' . $url);
} else if (!empty($mxMapList)) { } else if (!empty($mxMapList)) {
$mxMapInfo = new MXMapInfo($titlePrefix, $mxMapList[0]); $mxMapInfo = new MXMapInfo($titlePrefix, $mxMapList[0]);
} }
} }
call_user_func($function, $mxMapInfo); call_user_func($function, $mxMapInfo);
}, AsynchronousFileReader::CONTENT_TYPE_JSON); }, AsynchronousFileReader::CONTENT_TYPE_JSON);
} }
/** /**
* @deprecated * @deprecated
* @see \ManiaControl\ManiaExchange\ManiaExchangeManager::fetchMapsAsync() * @see \ManiaControl\ManiaExchange\ManiaExchangeManager::fetchMapsAsync()
*/ */
public function getMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, public function getMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) {
$searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) {
$this->fetchMapsAsync($function, $name, $author, $env, $maxMapsReturned, $searchOrder); $this->fetchMapsAsync($function, $name, $author, $env, $maxMapsReturned, $searchOrder);
return true; return true;
} }
@ -287,8 +286,7 @@ class ManiaExchangeManager {
* @param int $maxMapsReturned * @param int $maxMapsReturned
* @param int $searchOrder * @param int $searchOrder
*/ */
public function fetchMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, public function fetchMapsAsync(callable $function, $name = '', $author = '', $env = '', $maxMapsReturned = 100, $searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) {
$searchOrder = self::SEARCH_ORDER_UPDATED_NEWEST) {
// TODO: remove $env because it's not really used? // TODO: remove $env because it's not really used?
// Get Title Id // Get Title Id
@ -326,34 +324,34 @@ class ManiaExchangeManager {
} }
$this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix) { $this->maniaControl->getFileReader()->loadFile($url, function ($mapInfo, $error) use (&$function, $titlePrefix) {
if ($error) { if ($error) {
trigger_error($error); trigger_error($error);
return; return;
} }
$mxMapList = json_decode($mapInfo); $mxMapList = json_decode($mapInfo);
if (!isset($mxMapList->results)) { if (!isset($mxMapList->results)) {
trigger_error('Cannot decode searched JSON data'); trigger_error('Cannot decode searched JSON data');
return; return;
} }
$mxMapList = $mxMapList->results; $mxMapList = $mxMapList->results;
if ($mxMapList === null) { if ($mxMapList === null) {
trigger_error('Cannot decode searched JSON data'); trigger_error('Cannot decode searched JSON data');
return; return;
} }
$maps = array(); $maps = array();
foreach ($mxMapList as $map) { foreach ($mxMapList as $map) {
if (!empty($map)) { if (!empty($map)) {
array_push($maps, new MXMapInfo($titlePrefix, $map)); array_push($maps, new MXMapInfo($titlePrefix, $map));
} }
} }
call_user_func($function, $maps); call_user_func($function, $maps);
}, AsynchronousFileReader::CONTENT_TYPE_JSON); }, AsynchronousFileReader::CONTENT_TYPE_JSON);
} }
/** /**

View File

@ -87,8 +87,8 @@ class CustomUIManager implements CallbackListener, TimerListener {
//TODO: validate necessity //TODO: validate necessity
//send it again after 500ms //send it again after 500ms
$this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use (&$player) { $this->maniaControl->getTimerManager()->registerOneTimeListening($this, function () use (&$player) {
$this->updateManialink($player); $this->updateManialink($player);
}, 500); }, 500);
} }
/** /**

View File

@ -179,8 +179,7 @@ class PlayerActions {
* @param int $spectatorState * @param int $spectatorState
* @param bool $releaseSlot * @param bool $releaseSlot
*/ */
public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, public function forcePlayerToSpectator($adminLogin, $targetLogin, $spectatorState = self::SPECTATOR_BUT_KEEP_SELECTABLE, $releaseSlot = true) {
$releaseSlot = true) {
$admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin); $admin = $this->maniaControl->getPlayerManager()->getPlayer($adminLogin);
if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC) if (!$this->maniaControl->getAuthenticationManager()->checkPermission($admin, self::SETTING_PERMISSION_FORCE_PLAYER_SPEC)
) { ) {

View File

@ -475,8 +475,8 @@ class PluginManager {
public function fetchPluginList(callable $function) { public function fetchPluginList(callable $function) {
$url = ManiaControl::URL_WEBSERVICE . 'plugins'; $url = ManiaControl::URL_WEBSERVICE . 'plugins';
$this->maniaControl->getFileReader()->loadFile($url, function ($dataJson, $error) use (&$function) { $this->maniaControl->getFileReader()->loadFile($url, function ($dataJson, $error) use (&$function) {
$data = json_decode($dataJson); $data = json_decode($dataJson);
call_user_func($function, $data, $error); call_user_func($function, $data, $error);
}); });
} }
} }

View File

@ -81,10 +81,10 @@ class UsageReporter implements TimerListener {
$url = ManiaControl::URL_WEBSERVICE . '/usagereport?info=' . urlencode($info); $url = ManiaControl::URL_WEBSERVICE . '/usagereport?info=' . urlencode($info);
$this->maniaControl->getFileReader()->loadFile($url, function ($response, $error) { $this->maniaControl->getFileReader()->loadFile($url, function ($response, $error) {
$response = json_decode($response); $response = json_decode($response);
if ($error || !$response) { if ($error || !$response) {
Logger::logError('Error while Sending data: ' . print_r($error, true)); Logger::logError('Error while Sending data: ' . print_r($error, true));
} }
}); });
} }
} }

View File

@ -76,53 +76,53 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
Logger::log($message); Logger::log($message);
$this->maniaControl->getPluginManager()->fetchPluginList(function ($data, $error) use (&$player) { $this->maniaControl->getPluginManager()->fetchPluginList(function ($data, $error) use (&$player) {
if (!$data || $error) { if (!$data || $error) {
$message = 'Error while checking Plugins for newer Versions!'; $message = 'Error while checking Plugins for newer Versions!';
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
} }
$pluginsData = $this->parsePluginsData($data); $pluginsData = $this->parsePluginsData($data);
$pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses(); $pluginClasses = $this->maniaControl->getPluginManager()->getPluginClasses();
$pluginUpdates = array(); $pluginUpdates = array();
foreach ($pluginClasses as $pluginClass) { foreach ($pluginClasses as $pluginClass) {
/** @var Plugin $pluginClass */ /** @var Plugin $pluginClass */
$pluginId = $pluginClass::getId(); $pluginId = $pluginClass::getId();
if (!isset($pluginsData[$pluginId])) { if (!isset($pluginsData[$pluginId])) {
continue; continue;
} }
/** @var PluginUpdateData $pluginData */ /** @var PluginUpdateData $pluginData */
$pluginData = $pluginsData[$pluginId]; $pluginData = $pluginsData[$pluginId];
$pluginVersion = $pluginClass::getVersion(); $pluginVersion = $pluginClass::getVersion();
if ($pluginData->isNewerThan($pluginVersion)) { if ($pluginData->isNewerThan($pluginVersion)) {
$pluginUpdates[$pluginId] = $pluginData; $pluginUpdates[$pluginId] = $pluginData;
$message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})"; $message = "There is an Update of '{$pluginData->pluginName}' available! ('{$pluginClass}' - Version {$pluginData->version})";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
} }
} }
if (empty($pluginUpdates)) { if (empty($pluginUpdates)) {
$message = 'Plugins Update Check completed: All Plugins are up-to-date!'; $message = 'Plugins Update Check completed: All Plugins are up-to-date!';
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
} else { } else {
$updatesCount = count($pluginUpdates); $updatesCount = count($pluginUpdates);
$message = "Plugins Update Check completed: There are {$updatesCount} Updates available!"; $message = "Plugins Update Check completed: There are {$updatesCount} Updates available!";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
} }
}); });
} }
/** /**
@ -241,85 +241,85 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
*/ */
private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) { private function installPlugin(PluginUpdateData $pluginUpdateData, Player $player = null, $update = false) {
$this->maniaControl->getFileReader()->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use ( $this->maniaControl->getFileReader()->loadFile($pluginUpdateData->url, function ($updateFileContent, $error) use (
&$pluginUpdateData, &$player, &$update &$pluginUpdateData, &$player, &$update
) { ) {
if (!$updateFileContent || $error) { if (!$updateFileContent || $error) {
$message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!"; $message = "Error loading Update Data for '{$pluginUpdateData->pluginName}': {$error}!";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendInformation($message, $player); $this->maniaControl->getChat()->sendInformation($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
} }
$actionNoun = ($update ? 'Update' : 'Install'); $actionNoun = ($update ? 'Update' : 'Install');
$actionVerb = ($update ? 'Updating' : 'Installing'); $actionVerb = ($update ? 'Updating' : 'Installing');
$actionVerbDone = ($update ? 'updated' : 'installed'); $actionVerbDone = ($update ? 'updated' : 'installed');
$message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'..."; $message = "Now {$actionVerb} '{$pluginUpdateData->pluginName}'...";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendInformation($message, $player); $this->maniaControl->getChat()->sendInformation($message, $player);
} }
Logger::log($message); Logger::log($message);
$tempDir = FileUtil::getTempFolder(); $tempDir = FileUtil::getTempFolder();
$updateFileName = $tempDir . $pluginUpdateData->zipfile; $updateFileName = $tempDir . $pluginUpdateData->zipfile;
$bytes = file_put_contents($updateFileName, $updateFileContent); $bytes = file_put_contents($updateFileName, $updateFileContent);
if (!$bytes || $bytes <= 0) { if (!$bytes || $bytes <= 0) {
$message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!"; $message = "Plugin {$actionNoun} failed: Couldn't save {$actionNoun} Zip!";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
} }
$zip = new \ZipArchive(); $zip = new \ZipArchive();
$result = $zip->open($updateFileName); $result = $zip->open($updateFileName);
if ($result !== true) { if ($result !== true) {
$message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})"; $message = "Plugin {$actionNoun} failed: Couldn't open {$actionNoun} Zip! ({$result})";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
} }
$zip->extractTo(MANIACONTROL_PATH . 'plugins' . DIRECTORY_SEPARATOR); $zip->extractTo(MANIACONTROL_PATH . 'plugins' . DIRECTORY_SEPARATOR);
$zip->close(); $zip->close();
unlink($updateFileName); unlink($updateFileName);
FileUtil::deleteTempFolder(); FileUtil::deleteTempFolder();
$messageExtra = ''; $messageExtra = '';
if ($update) { if ($update) {
$messageExtra = ' (Restart ManiaControl to load the new Version!)'; $messageExtra = ' (Restart ManiaControl to load the new Version!)';
} }
$message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}"; $message = "Successfully {$actionVerbDone} '{$pluginUpdateData->pluginName}'!{$messageExtra}";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
if (!$update) { if (!$update) {
$newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins(); $newPluginClasses = $this->maniaControl->getPluginManager()->loadPlugins();
if (empty($newPluginClasses)) { if (empty($newPluginClasses)) {
$message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!"; $message = "Loading fresh installed Plugin '{$pluginUpdateData->pluginName}' failed!";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
Logger::log($message); Logger::log($message);
} else { } else {
$message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!"; $message = "Successfully loaded fresh installed Plugin '{$pluginUpdateData->pluginName}'!";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
$this->maniaControl->getConfigurator()->showMenu($player, InstallMenu::getTitle()); $this->maniaControl->getConfigurator()->showMenu($player, InstallMenu::getTitle());
} }
} }
}); });
} }
/** /**
@ -356,22 +356,22 @@ class PluginUpdateManager implements CallbackListener, CommandListener, TimerLis
$url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId; $url = ManiaControl::URL_WEBSERVICE . 'plugins/' . $pluginId;
$this->maniaControl->getFileReader()->loadFile($url, function ($data, $error) use (&$player) { $this->maniaControl->getFileReader()->loadFile($url, function ($data, $error) use (&$player) {
if ($error || !$data) { if ($error || !$data) {
$message = "Error loading Plugin Install Data! {$error}"; $message = "Error loading Plugin Install Data! {$error}";
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
return; return;
} }
$data = json_decode($data); $data = json_decode($data);
if (!$data) { if (!$data) {
$message = "Error loading Plugin Install Data! {$error}"; $message = "Error loading Plugin Install Data! {$error}";
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
return; return;
} }
$pluginUpdateData = new PluginUpdateData($data); $pluginUpdateData = new PluginUpdateData($data);
$this->installPlugin($pluginUpdateData, $player); $this->installPlugin($pluginUpdateData, $player);
}); });
} }
} }

View File

@ -141,18 +141,18 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel; $url = ManiaControl::URL_WEBSERVICE . 'versions?current=1&channel=' . $updateChannel;
$this->maniaControl->getFileReader()->loadFile($url, function ($dataJson, $error) use (&$function) { $this->maniaControl->getFileReader()->loadFile($url, function ($dataJson, $error) use (&$function) {
if ($error) { if ($error) {
Logger::logError('Error on UpdateCheck: ' . $error); Logger::logError('Error on UpdateCheck: ' . $error);
return; return;
} }
$versions = json_decode($dataJson); $versions = json_decode($dataJson);
if (!$versions || !isset($versions[0])) { if (!$versions || !isset($versions[0])) {
call_user_func($function); call_user_func($function);
} else { } else {
$updateData = new UpdateData($versions[0]); $updateData = new UpdateData($versions[0]);
call_user_func($function, $updateData); call_user_func($function, $updateData);
} }
}); });
} }
/** /**
@ -329,66 +329,66 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
$updateData = $this->coreUpdateData; $updateData = $this->coreUpdateData;
$this->maniaControl->getFileReader()->loadFile($updateData->url, function ($updateFileContent, $error) use ( $this->maniaControl->getFileReader()->loadFile($updateData->url, function ($updateFileContent, $error) use (
$updateData, &$player $updateData, &$player
) { ) {
if (!$updateFileContent || $error) { if (!$updateFileContent || $error) {
$message = "Update failed: Couldn't load Update zip! {$error}"; $message = "Update failed: Couldn't load Update zip! {$error}";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
} }
$tempDir = FileUtil::getTempFolder(); $tempDir = FileUtil::getTempFolder();
if (!$tempDir) { if (!$tempDir) {
$message = "Update failed: Can't save Update zip!"; $message = "Update failed: Can't save Update zip!";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
} }
$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) {
$message = "Update failed: Couldn't save Update zip!"; $message = "Update failed: Couldn't save Update zip!";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
return; return;
} }
$zip = new \ZipArchive(); $zip = new \ZipArchive();
$result = $zip->open($updateFileName); $result = $zip->open($updateFileName);
if ($result !== true) { if ($result !== true) {
$message = "Update failed: Couldn't open Update Zip. ({$result})"; $message = "Update failed: Couldn't open Update Zip. ({$result})";
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendError($message, $player); $this->maniaControl->getChat()->sendError($message, $player);
} }
Logger::logError($message); Logger::logError($message);
unlink($updateFileName); unlink($updateFileName);
return; return;
} }
$zip->extractTo(MANIACONTROL_PATH); $zip->extractTo(MANIACONTROL_PATH);
$zip->close(); $zip->close();
unlink($updateFileName); unlink($updateFileName);
FileUtil::deleteTempFolder(); FileUtil::deleteTempFolder();
// Set the Nightly Build Date // Set the Nightly Build Date
$this->setNightlyBuildDate($updateData->releaseDate); $this->setNightlyBuildDate($updateData->releaseDate);
$message = 'Update finished!'; $message = 'Update finished!';
if ($player) { if ($player) {
$this->maniaControl->getChat()->sendSuccess($message, $player); $this->maniaControl->getChat()->sendSuccess($message, $player);
} }
Logger::log($message); Logger::log($message);
$this->maniaControl->restart(); $this->maniaControl->restart();
}); });
return true; return true;
} }