From d7a88b382dee5065dbefeca5d033133a0566ee7e Mon Sep 17 00:00:00 2001 From: Yuri Kuznetsov Date: Sat, 6 Apr 2024 12:45:55 +0300 Subject: [PATCH] migrations fix and dev --- .../Console/Commands/MigrationVersionStep.php | 1 + .../Espo/Core/Upgrades/Migration/Runner.php | 12 +++++----- .../Core/Upgrades/Migration/StepRunner.php | 23 ++++++++++++++++--- 3 files changed, 27 insertions(+), 9 deletions(-) diff --git a/application/Espo/Core/Console/Commands/MigrationVersionStep.php b/application/Espo/Core/Console/Commands/MigrationVersionStep.php index cced09d562..7d7bc333ee 100644 --- a/application/Espo/Core/Console/Commands/MigrationVersionStep.php +++ b/application/Espo/Core/Console/Commands/MigrationVersionStep.php @@ -55,5 +55,6 @@ class MigrationVersionStep implements Command $this->afterUpgradeRunner->run($step); $io->writeLine("Done."); + $io->setExitStatus(0); } } diff --git a/application/Espo/Core/Upgrades/Migration/Runner.php b/application/Espo/Core/Upgrades/Migration/Runner.php index 0bb5229621..d53dfe2d21 100644 --- a/application/Espo/Core/Upgrades/Migration/Runner.php +++ b/application/Espo/Core/Upgrades/Migration/Runner.php @@ -59,7 +59,7 @@ class Runner $prepareSteps = $this->stepsProvider->getPrepare($version, $targetVersion); if ($prepareSteps !== []) { - $io->write(" Running prepare migrations..."); + $io->writeLine("Running prepare migrations..."); foreach ($prepareSteps as $step) { $this->runPrepareStep($io, $step); @@ -69,12 +69,12 @@ class Runner $afterSteps = $this->stepsProvider->getAfterUpgrade($version, $targetVersion); if ($afterSteps === []) { - $io->writeLine(" No migrations to run."); + $io->writeLine("No migrations to run."); return; } - $io->write(" Running after-upgrade migrations..."); + $io->writeLine("Running after-upgrade migrations..."); foreach ($afterSteps as $step) { $this->runAfterUpgradeStep($io, $step); @@ -84,12 +84,12 @@ class Runner $this->updateVersion($targetVersion); $this->dataManager->updateAppTimestamp(); - $io->writeLine(" Completed."); + $io->writeLine("Completed."); } private function runAfterUpgradeStep(IO $io, string $step): void { - $io->write(" $step..."); + $io->write(" $step..."); $isSuccessful = $this->stepRunner->runAfterUpgrade($step); @@ -101,7 +101,7 @@ class Runner $io->writeLine(" FAIL"); - throw new RuntimeException(); + throw new RuntimeException("Step process failed."); } private function runPrepareStep(IO $io, string $step): void diff --git a/application/Espo/Core/Upgrades/Migration/StepRunner.php b/application/Espo/Core/Upgrades/Migration/StepRunner.php index ca16df1824..ca6a3fe8df 100644 --- a/application/Espo/Core/Upgrades/Migration/StepRunner.php +++ b/application/Espo/Core/Upgrades/Migration/StepRunner.php @@ -31,6 +31,7 @@ namespace Espo\Core\Upgrades\Migration; use Espo\Core\InjectableFactory; use Espo\Core\Utils\Config; +use Espo\Core\Utils\Log; use RuntimeException; use Symfony\Component\Process\PhpExecutableFinder; use Symfony\Component\Process\Process; @@ -39,19 +40,22 @@ class StepRunner { public function __construct( private Config $config, - private InjectableFactory $injectableFactory + private InjectableFactory $injectableFactory, + private Log $log ) {} public function runAfterUpgrade(string $step): bool { $phpExecutablePath = $this->getPhpExecutablePath(); - $command = "command.php migration-version-step --step=$step"; + $command = "command.php"; - $process = new Process([$phpExecutablePath, $command]); + $process = new Process([$phpExecutablePath, $command, 'migration-version-step', "--step=$step"]); $process->setTimeout(null); $process->run(); + $this->processLogging($process); + return $process->isSuccessful(); } @@ -80,4 +84,17 @@ class StepRunner return $phpExecutablePath; } + + private function processLogging(Process $process): void + { + if ($process->isSuccessful()) { + return; + } + + $output = $process->getOutput(); + + if ($output) { + $this->log->error("Migration step command: " . $output); + } + } }