diff --git a/lib/classes/Setup/Upgrade.class.php b/lib/classes/Setup/Upgrade.class.php
index 5bdd116fa2..6b6496fa49 100644
--- a/lib/classes/Setup/Upgrade.class.php
+++ b/lib/classes/Setup/Upgrade.class.php
@@ -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');
}
@@ -176,7 +181,7 @@ class Setup_Upgrade
), 1
);
- if ( ! file_put_contents(self::get_lock_file(), $datas))
+ if (!file_put_contents(self::get_lock_file(), $datas))
throw new Exception_Setup_CannotWriteLockFile(
sprintf('Cannot write lock file to %s', self::get_lock_file())
);
@@ -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;
}
diff --git a/lib/classes/module/console/systemUpgrade.class.php b/lib/classes/module/console/systemUpgrade.class.php
index 4f35cf96b1..1046b4db76 100644
--- a/lib/classes/module/console/systemUpgrade.class.php
+++ b/lib/classes/module/console/systemUpgrade.class.php
@@ -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,23 @@ 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 (!$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, '' . _('Create automatically') . ' (Y/n)', 'y'));
- } while ( ! in_array($continue, array('y', 'n')));
+ $dialog = $this->getHelperSet()->get('dialog');
+ do {
+ $continue = mb_strtolower($dialog->ask($output, '' . _('Create automatically') . ' (Y/n)', 'y'));
+ } while (!in_array($continue, array('y', 'n')));
+ } else {
+ $continue = 'y';
+ }
if ($continue == 'y') {
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)');
}
$output->write('Phraseanet is going to be upgraded', true);
- $dialog = $this->getHelperSet()->get('dialog');
- do {
- $continue = mb_strtolower($dialog->ask($output, '' . _('Continuer ?') . ' (Y/n)', 'Y'));
- } while ( ! in_array($continue, array('y', 'n')));
+ if ($interactive) {
+ $dialog = $this->getHelperSet()->get('dialog');
+
+ do {
+ $continue = mb_strtolower($dialog->ask($output, '' . _('Continuer ?') . ' (Y/n)', '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('You have to fix your database before upgrade with the system:mailCheck command '));
}
- $upgrader = new Setup_Upgrade($appbox);
+ $upgrader = new Setup_Upgrade($appbox, $input->getOption('force'));
+
$appbox->forceUpgrade($upgrader);
foreach ($upgrader->getRecommendations() as $recommendation) {