migrations fix and dev

This commit is contained in:
Yuri Kuznetsov
2024-04-06 12:45:55 +03:00
parent acc2eb1a55
commit d7a88b382d
3 changed files with 27 additions and 9 deletions
@@ -55,5 +55,6 @@ class MigrationVersionStep implements Command
$this->afterUpgradeRunner->run($step);
$io->writeLine("Done.");
$io->setExitStatus(0);
}
}
@@ -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
@@ -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);
}
}
}