Add option -y (answer yes to all questions) and -f (force upgrade even if a concurrent one is running) to system:upgrade command

This commit is contained in:
Romain Neutron
2012-09-10 13:39:48 +02:00
parent 16c49b3382
commit 1c592224d9
2 changed files with 38 additions and 17 deletions

View File

@@ -18,6 +18,7 @@
*/
use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class module_console_systemUpgrade extends Command
@@ -27,7 +28,10 @@ class module_console_systemUpgrade extends Command
{
parent::__construct($name);
$this->setDescription('Upgrade Phraseanet to the latest version');
$this
->setDescription('Upgrade Phraseanet to the latest version')
->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answer yes to all questions and do not ask the user')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Force the upgrade even if there is a concurrent upgrade');
return $this;
}
@@ -44,17 +48,22 @@ class module_console_systemUpgrade extends Command
$old_connexion_file = __DIR__ . '/../../../../config/connexion.inc';
$old_config_file = __DIR__ . '/../../../../config/config.inc';
$interactive = !$input->getOption('yes');
$Core = $this->getService('phraseanet.core');
if ( ! $Core->getConfiguration()->isInstalled() && file_exists($old_config_file) && file_exists($old_connexion_file)) {
if (!$Core->getConfiguration()->isInstalled() && file_exists($old_config_file) && file_exists($old_connexion_file)) {
$output->writeln('This version of Phraseanet requires a config/config.yml, config/connexion.yml, config/service.yml');
$output->writeln('Would you like it to be created based on your settings ?');
if ($interactive) {
$output->writeln('This version of Phraseanet requires a config/config.yml, config/connexion.yml, config/service.yml');
$output->writeln('Would you like it to be created based on your settings ?');
$dialog = $this->getHelperSet()->get('dialog');
do {
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Create automatically') . ' (Y/n)</question>', 'y'));
} while ( ! in_array($continue, array('y', 'n')));
$dialog = $this->getHelperSet()->get('dialog');
do {
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Create automatically') . ' (Y/n)</question>', 'y'));
} while (!in_array($continue, array('y', 'n')));
} else {
$continue = 'y';
}
if ($continue == 'y') {
try {
@@ -70,16 +79,21 @@ class module_console_systemUpgrade extends Command
}
}
if ( ! $Core->getConfiguration()->isInstalled()) {
if (!$Core->getConfiguration()->isInstalled()) {
throw new \RuntimeException('Phraseanet must be set-up (no connexion.inc / no config.inc)');
}
$output->write('Phraseanet is going to be upgraded', true);
$dialog = $this->getHelperSet()->get('dialog');
do {
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Continuer ?') . ' (Y/n)</question>', 'Y'));
} while ( ! in_array($continue, array('y', 'n')));
if ($interactive) {
$dialog = $this->getHelperSet()->get('dialog');
do {
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Continuer ?') . ' (Y/n)</question>', 'Y'));
} while (!in_array($continue, array('y', 'n')));
} else {
$continue = 'y';
}
if ($continue == 'y') {
try {
@@ -90,7 +104,8 @@ class module_console_systemUpgrade extends Command
return $output->writeln(sprintf('<error>You have to fix your database before upgrade with the system:mailCheck command </error>'));
}
$upgrader = new Setup_Upgrade($appbox);
$upgrader = new Setup_Upgrade($appbox, $input->getOption('force'));
$appbox->forceUpgrade($upgrader);
foreach ($upgrader->getRecommendations() as $recommendation) {