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 * @var string
*/ */
protected $message; protected $message;
/** /**
* *
* @var array * @var array
@@ -54,8 +55,12 @@ class Setup_Upgrade
* @param appbox $appbox * @param appbox $appbox
* @return Setup_Upgrade * @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()) { if (self::lock_exists()) {
throw new Exception_Setup_UpgradeAlreadyStarted('The upgrade is already started'); throw new Exception_Setup_UpgradeAlreadyStarted('The upgrade is already started');
} }
@@ -176,7 +181,7 @@ class Setup_Upgrade
), 1 ), 1
); );
if ( ! file_put_contents(self::get_lock_file(), $datas)) if (!file_put_contents(self::get_lock_file(), $datas))
throw new Exception_Setup_CannotWriteLockFile( throw new Exception_Setup_CannotWriteLockFile(
sprintf('Cannot write lock file to %s', self::get_lock_file()) sprintf('Cannot write lock file to %s', self::get_lock_file())
); );
@@ -212,8 +217,9 @@ class Setup_Upgrade
*/ */
protected static function remove_lock_file() protected static function remove_lock_file()
{ {
if (self::lock_exists()) if (self::lock_exists()) {
unlink(self::get_lock_file()); unlink(self::get_lock_file());
}
return; return;
} }

View File

@@ -18,6 +18,7 @@
*/ */
use Alchemy\Phrasea\Command\Command; use Alchemy\Phrasea\Command\Command;
use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface; use Symfony\Component\Console\Output\OutputInterface;
class module_console_systemUpgrade extends Command class module_console_systemUpgrade extends Command
@@ -27,7 +28,10 @@ class module_console_systemUpgrade extends Command
{ {
parent::__construct($name); 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; return $this;
} }
@@ -44,17 +48,23 @@ class module_console_systemUpgrade extends Command
$old_connexion_file = __DIR__ . '/../../../../config/connexion.inc'; $old_connexion_file = __DIR__ . '/../../../../config/connexion.inc';
$old_config_file = __DIR__ . '/../../../../config/config.inc'; $old_config_file = __DIR__ . '/../../../../config/config.inc';
$interactive = !$input->getOption('yes');
$Core = \bootstrap::getCore(); $Core = \bootstrap::getCore();
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)) {
if ($interactive) {
$output->writeln('This version of Phraseanet requires a config/config.yml, config/connexion.yml, config/service.yml'); $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 ?'); $output->writeln('Would you like it to be created based on your settings ?');
$dialog = $this->getHelperSet()->get('dialog'); $dialog = $this->getHelperSet()->get('dialog');
do { do {
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Create automatically') . ' (Y/n)</question>', 'y')); $continue = mb_strtolower($dialog->ask($output, '<question>' . _('Create automatically') . ' (Y/n)</question>', 'y'));
} while ( ! in_array($continue, array('y', 'n'))); } while (!in_array($continue, array('y', 'n')));
} else {
$continue = 'y';
}
if ($continue == 'y') { if ($continue == 'y') {
try { try {
@@ -70,16 +80,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)'); throw new \RuntimeException('Phraseanet must be set-up (no connexion.inc / no config.inc)');
} }
$output->write('Phraseanet is going to be upgraded', true); $output->write('Phraseanet is going to be upgraded', true);
if ($interactive) {
$dialog = $this->getHelperSet()->get('dialog'); $dialog = $this->getHelperSet()->get('dialog');
do { do {
$continue = mb_strtolower($dialog->ask($output, '<question>' . _('Continuer ?') . ' (Y/n)</question>', 'Y')); $continue = mb_strtolower($dialog->ask($output, '<question>' . _('Continuer ?') . ' (Y/n)</question>', 'Y'));
} while ( ! in_array($continue, array('y', 'n'))); } while (!in_array($continue, array('y', 'n')));
} else {
$continue = 'y';
}
if ($continue == 'y') { if ($continue == 'y') {
try { 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>')); 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); $appbox->forceUpgrade($upgrader);
foreach ($upgrader->getRecommendations() as $recommendation) { foreach ($upgrader->getRecommendations() as $recommendation) {