performupdate specified message and use asynchrnousfilereader
This commit is contained in:
parent
961b6dd590
commit
d763582f85
@ -91,15 +91,20 @@ class ScriptSettings implements ConfiguratorMenu, CallbackListener {
|
|||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
public function loadSettingsFromDatabase() {
|
public function loadSettingsFromDatabase() {
|
||||||
$scriptSettings = (array)$this->maniaControl->client->getModeScriptSettings();
|
try{
|
||||||
|
$scriptSettings = $this->maniaControl->client->getModeScriptSettings();
|
||||||
|
} catch (\Exception $e){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
if (isset($scriptSettings['faultString'])) {
|
//TODO check error on not script modes, maybe exception happen, or dunno what, there is no faultString property?
|
||||||
|
/*if (isset($scriptSettings['faultString'])) {
|
||||||
if ($scriptSettings['faultString'] == 'Not in script mode.') {
|
if ($scriptSettings['faultString'] == 'Not in script mode.') {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
trigger_error('Error occured: ' . $scriptSettings['faultString']);
|
trigger_error('Error occured: ' . $scriptSettings['faultString']);
|
||||||
return false;
|
return false;
|
||||||
}
|
}*/
|
||||||
|
|
||||||
$mysqli = $this->maniaControl->database->mysqli;
|
$mysqli = $this->maniaControl->database->mysqli;
|
||||||
$serverId = $this->maniaControl->server->index;
|
$serverId = $this->maniaControl->server->index;
|
||||||
|
@ -142,13 +142,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
if ($performBackup && !$this->performBackup()) {
|
if ($performBackup && !$this->performBackup()) {
|
||||||
$this->maniaControl->log("Creating Backup failed!");
|
$this->maniaControl->log("Creating Backup failed!");
|
||||||
}
|
}
|
||||||
if (!$this->performCoreUpdate($updateData)) {
|
|
||||||
$this->maniaControl->log("Update failed!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->maniaControl->log("Update finished!");
|
|
||||||
|
|
||||||
$this->maniaControl->restart();
|
$this->performCoreUpdate($updateData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -228,13 +223,8 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
$this->maniaControl->chat->sendError('Creating backup failed.', $player->login);
|
$this->maniaControl->chat->sendError('Creating backup failed.', $player->login);
|
||||||
$this->maniaControl->log("Creating backup failed.");
|
$this->maniaControl->log("Creating backup failed.");
|
||||||
}
|
}
|
||||||
if (!$this->performCoreUpdate($updateData)) {
|
|
||||||
$this->maniaControl->chat->sendError('Update failed!', $player->login);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
$this->maniaControl->chat->sendSuccess('Update finished!', $player->login);
|
|
||||||
|
|
||||||
$this->maniaControl->restart();
|
$this->performCoreUpdate($updateData, $player);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -347,41 +337,71 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
/**
|
/**
|
||||||
* Perform a Core Update
|
* Perform a Core Update
|
||||||
*
|
*
|
||||||
* @param object $updateData
|
* @param object $updateData
|
||||||
|
* @param Players\Player $player
|
||||||
* @return bool
|
* @return bool
|
||||||
*/
|
*/
|
||||||
private function performCoreUpdate($updateData = null) {
|
private function performCoreUpdate($updateData = null, Player $player = null) {
|
||||||
if (!$this->checkPermissions()) {
|
if (!$this->checkPermissions()) {
|
||||||
|
if ($player != null) {
|
||||||
|
$this->maniaControl->chat->sendError('Update failed: Incorrect Filesystem permissions!', $player->login);
|
||||||
|
}
|
||||||
|
$this->maniaControl->log('Update failed!');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!$updateData) {
|
if (!$updateData) {
|
||||||
$updateData = $this->checkCoreUpdate();
|
$updateData = $this->checkCoreUpdate(true);
|
||||||
if (!$updateData) {
|
if (!$updateData) {
|
||||||
|
if ($player != null) {
|
||||||
|
$this->maniaControl->chat->sendError('Update failed: No update Data available!', $player->login);
|
||||||
|
}
|
||||||
|
$this->maniaControl->log('Update failed: No update Data available!');
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$updateFileContent = file_get_contents($updateData->url);
|
|
||||||
$tempDir = ManiaControlDir . '/temp/';
|
$this->maniaControl->fileReader->loadFile($updateData->url, function ($updateFileContent, $error) use (&$updateData, &$player) {
|
||||||
if (!is_dir($tempDir)) {
|
$tempDir = ManiaControlDir . '/temp/';
|
||||||
mkdir($tempDir);
|
if (!is_dir($tempDir)) {
|
||||||
}
|
mkdir($tempDir);
|
||||||
$updateFileName = $tempDir . basename($updateData->url);
|
}
|
||||||
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
$updateFileName = $tempDir . basename($updateData->url);
|
||||||
if (!$bytes || $bytes <= 0) {
|
|
||||||
trigger_error("Couldn't save Update Zip.");
|
|
||||||
return false;
|
$bytes = file_put_contents($updateFileName, $updateFileContent);
|
||||||
}
|
if (!$bytes || $bytes <= 0) {
|
||||||
$zip = new \ZipArchive();
|
trigger_error("Couldn't save Update Zip.");
|
||||||
$result = $zip->open($updateFileName);
|
if ($player != null) {
|
||||||
if ($result !== true) {
|
$this->maniaControl->chat->sendError('Update failed: Couldn\'t save Update zip!', $player->login);
|
||||||
trigger_error("Couldn't open Update Zip. ({$result})");
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$zip->extractTo(ManiaControlDir);
|
$zip = new \ZipArchive();
|
||||||
$zip->close();
|
$result = $zip->open($updateFileName);
|
||||||
unlink($updateFileName);
|
if ($result !== true) {
|
||||||
@rmdir($tempDir);
|
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);
|
||||||
|
|
||||||
|
if ($player != null) {
|
||||||
|
$this->maniaControl->chat->sendSuccess('Update finished!', $player->login);
|
||||||
|
}
|
||||||
|
$this->maniaControl->log("Update finished!");
|
||||||
|
|
||||||
|
$this->maniaControl->restart();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
});
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -403,7 +423,6 @@ class UpdateManager implements CallbackListener, CommandListener, TimerListener
|
|||||||
|
|
||||||
foreach($files as $file) {
|
foreach($files as $file) {
|
||||||
if (substr($file, -1) != '.' && substr($file, -2) != '..') {
|
if (substr($file, -1) != '.' && substr($file, -2) != '..') {
|
||||||
echo $file . "\n\r";
|
|
||||||
if (!is_writable($file)) {
|
if (!is_writable($file)) {
|
||||||
$this->maniaControl->log('Cannot update: the file/directory "' . $file . '" is not writable!');
|
$this->maniaControl->log('Cannot update: the file/directory "' . $file . '" is not writable!');
|
||||||
return false;
|
return false;
|
||||||
|
Loading…
Reference in New Issue
Block a user