PHRAS-3820_fix-patch-3.8-to-4.1 (#4263)

* add --dry to bin/setup system:upgrade ; trace patches ; allow MailChecker to fail (when table 'usr' does not exist anymore...)

* MailChecker now works on 'usr' and 'Users' table

* typo

* typo again

* don't create appbox.Registrations if exists

* don't create tables if already exists

* Revert "don't create appbox.Registrations if exists"

This reverts commit 652131aff7.

* drop (empty ?) tables already created before patch

* reorder drop / delete to follow fk rules

* fix typo that makes ApiMigration to run event when table exists ; Move some drop tables at the end
This commit is contained in:
jygaulier
2023-03-09 13:45:39 +01:00
committed by GitHub
parent d5be724ec2
commit a6260ef149
32 changed files with 250 additions and 114 deletions

View File

@@ -11,6 +11,7 @@
use Alchemy\Phrasea\Command\Command;
use Alchemy\Phrasea\Core\Version;
use Alchemy\Phrasea\Setup\ConfigurationTester;
use Symfony\Component\Console\Input\ArrayInput;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
@@ -28,13 +29,16 @@ class module_console_systemUpgrade extends Command
->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answers yes to all questions and do not ask the user')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces the upgrade even if there is a concurrent upgrade')
->addOption('dump', 'd', InputOption::VALUE_NONE, 'Dumps SQL queries that can be used to clean database.')
->addOption('stderr', 's', InputOption::VALUE_NONE, 'Dumps SQL queries to stderr');
->addOption('stderr', 's', InputOption::VALUE_NONE, 'Dumps SQL queries to stderr')
->addOption('dry', null, InputOption::VALUE_NONE, 'List patchs, do no apply changes');
return $this;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$dry = !!$input->getOption('dry');
$pluginAutoloader = rtrim($this->container['root.path'], '\\/') . '/plugins/autoload.php';
if (file_exists($pluginAutoloader)) {
@@ -49,9 +53,17 @@ class module_console_systemUpgrade extends Command
$interactive = !$input->getOption('yes');
while ($migrations = $this->container['phraseanet.configuration-tester']->getMigrations()) {
/** @var ConfigurationTester $configurationTester */
$configurationTester = $this->container['phraseanet.configuration-tester'];
while ($migrations = $configurationTester->getMigrations($input, $output)) {
foreach ($migrations as $migration) {
$migration->migrate();
if($dry) {
$output->writeln(sprintf("dry : NOT applying migration \"%s\"", get_class($migration)));
}
else {
$output->writeln(sprintf("applying migration \"%s\"", get_class($migration)));
$migration->migrate();
}
}
}
@@ -76,14 +88,15 @@ class module_console_systemUpgrade extends Command
$output->write(sprintf('Upgrading... from version <info>%s</info> to <info>%s</info>', $this->container->getApplicationBox()->get_version(), $version->getNumber()), true);
try {
$upgrader = new Setup_Upgrade($this->container, $input->getOption('force'));
// Setup_Upgrade will call MailChecker
$upgrader = new Setup_Upgrade($this->container, $input, $output, $input->getOption('force'));
} catch (\Exception_Setup_FixBadEmailAddresses $e) {
return $output->writeln(sprintf('<error>You have to fix your database before upgrade with the system:mailCheck command </error>'));
}
/** @var appbox $appBox */
$appBox = $this->getService('phraseanet.appbox');
$queries = $appBox->forceUpgrade($upgrader, $this->container);
$queries = $appBox->forceUpgrade($upgrader, $this->container, $input, $output);
/**
* todo (?) combine schema changes on a table as a simngle sql
* because on big tables like logs, adding 2 columns is 2 very long sql
@@ -126,9 +139,14 @@ class module_console_systemUpgrade extends Command
if (null !== $this->getApplication()) {
$command = $this->getApplication()->find('crossdomain:generate');
$command->run(new ArrayInput(array(
'command' => 'crossdomain:generate'
)), $output);
if($dry) {
$output->writeln("dry : NOT running 'crossdomain:generate'");
}
else {
$command->run(new ArrayInput([
'command' => 'crossdomain:generate'
]), $output);
}
}
} else {
$output->write('<info>Canceled</info>', true);
@@ -136,19 +154,25 @@ class module_console_systemUpgrade extends Command
$output->write('System upgrade Finished !', true);
// need to fix autoincrements after system:upgrade
$output->write('Start fixing autoincrements !', true);
if($dry) {
$output->writeln("dry : NOT fixing autoincrements");
$returnCode = 0;
}
else {
$output->write('Start fixing autoincrements !', true);
$fixAutoincrementCommand = $this->getApplication()->find('system:fix-autoincrements');
$fixAutoincrementCommand = $this->getApplication()->find('system:fix-autoincrements');
$arguments = array(
'command' => 'system:fix-autoincrements',
);
$arguments = [
'command' => 'system:fix-autoincrements',
];
$fixAutoincrementInput = new ArrayInput($arguments);
$fixAutoincrementInput = new ArrayInput($arguments);
$returnCode = $fixAutoincrementCommand->run($fixAutoincrementInput, $output);
$returnCode = $fixAutoincrementCommand->run($fixAutoincrementInput, $output);
$output->write('Fixing autoincrements finished after system:upgrade', true);
$output->write('Fixing autoincrements finished after system:upgrade', true);
}
return $returnCode;
}