update mechanism

This commit is contained in:
Roman 2021-04-07 01:00:52 +02:00
parent c339ae0584
commit 1a3c4e44f6

21
cli.php

@ -187,13 +187,13 @@ function onMaintenance(array $argv) {
printLine("$ git fetch " . str_replace("/", " ", $pullBranch)); printLine("$ git fetch " . str_replace("/", " ", $pullBranch));
exec("git fetch " . str_replace("/", " ", $pullBranch), $gitFetch, $ret); exec("git fetch " . str_replace("/", " ", $pullBranch), $gitFetch, $ret);
if ($ret !== 0) { if ($ret !== 0) {
_exit(implode(PHP_EOL, $gitFetch)); die();
} }
printLine("$ git log HEAD..$pullBranch --oneline"); printLine("$ git log HEAD..$pullBranch --oneline");
exec("git log HEAD..$pullBranch --oneline", $gitLog, $ret); exec("git log HEAD..$pullBranch --oneline", $gitLog, $ret);
if ($ret !== 0) { if ($ret !== 0) {
_exit(implode(PHP_EOL, $gitLog)); die();
} else if (count($gitLog) === 0) { } else if (count($gitLog) === 0) {
_exit("Already up to date."); _exit("Already up to date.");
} }
@ -214,24 +214,29 @@ function onMaintenance(array $argv) {
// enable maintenance mode if it wasn't turned on before // enable maintenance mode if it wasn't turned on before
if (!$isMaintenanceEnabled) { if (!$isMaintenanceEnabled) {
printLine("Turning on maintenance mode"); printLine("Turning on maintenance mode");
onMaintenance(["cli.php", "maintenance", "on"]); $file = fopen($maintenanceFile, 'w') or _exit("Unable to create maintenance file");
fclose($file);
} }
printLine("Ready to update, pulling and merging"); printLine("Ready to update, pulling and merging");
printLine("$ git pull $pullBranch"); printLine("$ git pull " . str_replace("/", " ", $pullBranch) . " --no-ff");
exec("git pull $pullBranch", $gitPull, $ret); exec("git pull " . str_replace("/", " ", $pullBranch) . " --no-ff", $gitPull, $ret);
if ($ret !== 0) { if ($ret !== 0) {
printLine();
printLine("Update could not be applied, check the following git message."); printLine("Update could not be applied, check the following git message.");
printLine("Follow the instructions and afterwards turn off the maintenance mode again using:"); printLine("Follow the instructions and afterwards turn off the maintenance mode again using:");
printLine("cli.php maintenance off"); printLine("cli.php maintenance off");
printLine(); die();
_exit(implode(PHP_EOL, $gitLog));
} }
// disable maintenance mode again // disable maintenance mode again
if (!$isMaintenanceEnabled) { if (!$isMaintenanceEnabled) {
printLine("Turning off maintenance mode"); printLine("Turning off maintenance mode");
onMaintenance(["cli.php", "maintenance", "off"]); if (file_exists($maintenanceFile)) {
if (!unlink($maintenanceFile)) {
_exit("Unable to delete maintenance file");
}
}
} }
} else { } else {
_exit("Usage: cli.php maintenance <status|on|off|update>"); _exit("Usage: cli.php maintenance <status|on|off|update>");