Merge pull request #206 from romainneutron/Console

Add option -y and -f to system:upgrade command
This commit is contained in:
Romain Neutron
2012-09-10 05:51:39 -07:00
2 changed files with 39 additions and 17 deletions

View File

@@ -31,6 +31,7 @@ class Setup_Upgrade
* @var string
*/
protected $message;
/**
*
* @var array
@@ -54,8 +55,12 @@ class Setup_Upgrade
* @param appbox $appbox
* @return Setup_Upgrade
*/
public function __construct(appbox &$appbox)
public function __construct(appbox &$appbox, $force = false)
{
if ($force) {
self::remove_lock_file();
}
if (self::lock_exists()) {
throw new Exception_Setup_UpgradeAlreadyStarted('The upgrade is already started');
}
@@ -212,8 +217,9 @@ class Setup_Upgrade
*/
protected static function remove_lock_file()
{
if (self::lock_exists())
if (self::lock_exists()) {
unlink(self::get_lock_file());
}
return;
}

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,10 +48,13 @@ 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 = \bootstrap::getCore();
if (!$Core->getConfiguration()->isInstalled() && file_exists($old_config_file) && file_exists($old_connexion_file)) {
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 ?');
@@ -55,6 +62,9 @@ class module_console_systemUpgrade extends Command
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 {
@@ -75,11 +85,16 @@ class module_console_systemUpgrade extends Command
}
$output->write('Phraseanet is going to be upgraded', true);
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 {
@@ -91,7 +106,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) {