From b5b48538910cf8686a38c81e7892b847558e8c80 Mon Sep 17 00:00:00 2001 From: celestora Date: Sat, 22 Feb 2025 20:24:31 +0200 Subject: [PATCH] feat(install): Add --oneshot option to upgrade MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit скрутка на зиму (на когда установщик будет чтобы можно было аяксом теребить обновление БД в браузере без 504) --- CLI/UpgradeCommand.php | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/CLI/UpgradeCommand.php b/CLI/UpgradeCommand.php index f1aa91d7..afe861ad 100644 --- a/CLI/UpgradeCommand.php +++ b/CLI/UpgradeCommand.php @@ -44,6 +44,8 @@ class UpgradeCommand extends Command { "Don't display warning before migrating database", false) ->addOption("repair", "R", InputOption::VALUE_NEGATABLE, "Attempt to repair database schema if tables are missing", false) + ->addOption("oneshot", "O", InputOption::VALUE_NONE, + "Only execute one operation") ->addArgument("chandler", InputArgument::OPTIONAL, "Location of Chandler installation"); } @@ -160,7 +162,7 @@ class UpgradeCommand extends Command { return $this->executeSqlScript(31, $installFile, $io); } - protected function runMigrations(SymfonyStyle $io): int + protected function runMigrations(SymfonyStyle $io, bool $oneshot): int { $nextLevel = $this->getNextLevel(); $migrations = array_filter($this->getMigrationFiles(), fn ($id) => $id >= $nextLevel, ARRAY_FILTER_USE_KEY); @@ -186,6 +188,9 @@ class UpgradeCommand extends Command { $t = time(); $this->db->query("INSERT INTO ovk_upgrade_history VALUES ($num, $t, \"$uname\");"); + + if ($oneshot) + return 5; } return 0; @@ -193,6 +198,7 @@ class UpgradeCommand extends Command { protected function execute(InputInterface $input, OutputInterface $output): int { + $oneShotMode = $input->getOption("oneshot"); $io = new SymfonyStyle($input, $output); if (!$input->getOption("quick")) { @@ -208,7 +214,7 @@ class UpgradeCommand extends Command { $this->checkDatabaseReadiness($chandlerOk, $ovkOk, $migrationsOk); - $res = 0; + $res = -1; if ($chandlerOk === null) { $io->writeln("Chandler schema not detected, attempting to install..."); @@ -228,12 +234,16 @@ class UpgradeCommand extends Command { if ($res > 0) return $res; + else if ($res == 0 && $oneShotMode) + return 5; if (!$ovkOk) { $io->writeln("Initializing OpenVK schema..."); $res = $this->initSchema($io); if ($res > 0) return $res; + else if ($oneShotMode) + return 5; } if (!$migrationsOk) { @@ -241,10 +251,12 @@ class UpgradeCommand extends Command { $res = $this->initUpgradeLog($io); if ($res > 0) return $res; + else if ($oneShotMode) + return 5; } $io->writeln("Upgrading database..."); - $res = $this->runMigrations($io); + $res = $this->runMigrations($io, $oneShotMode); if (!$res) { $io->success("Database has been upgraded!");