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;
}
public function requireSetup()
{
return false;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
require_once dirname(__FILE__) . '/../../../../lib/bootstrap.php';
$interactive = !$input->getOption('yes');
if (!$this->container['phraseanet.configuration']->isInstalled() && \setup::needUpgradeConfigurationFile()) {
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')));
} else {
$continue = 'y';
}
if ($continue == 'y') {
try {
if (\setup::requireGVUpgrade()) {
setup::upgradeGV($this->container['phraseanet.registry']);
}
$connexionInc = new \SplFileInfo(__DIR__ . '/../../../../config/connexion.inc');
$configInc = new \SplFileInfo(__DIR__ . '/../../../../config/config.inc');
$this->getService('phraseanet.configuration')->upgradeFromOldConf($configInc, $connexionInc);
} catch (\Exception $e) {
throw new RuntimeException('Error while upgrading : ' . $e->getMessage());
}
} else {
throw new RuntimeException('Phraseanet is not set up');
}
}
if ( ! $this->getService('phraseanet.configuration')->isInstalled()) {
throw new \RuntimeException('Phraseanet must be set-up (no connexion.inc / no config.inc)');
}
$output->write('Phraseanet is going to be upgraded', true);
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 {
$output->write('Upgrading...', true);
if (count(User_Adapter::get_wrong_email_users($this->container)) > 0) {
return $output->writeln(sprintf('You have to fix your database before upgrade with the system:mailCheck command '));
}
$upgrader = new Setup_Upgrade($this->getService('phraseanet.appbox'), $input->getOption('force'));
$this->getService('phraseanet.appbox')->forceUpgrade($upgrader);
foreach ($upgrader->getRecommendations() as $recommendation) {
list($message, $command) = $recommendation;
$output->writeln(sprintf('%s', $message));
$output->writeln("");
$output->writeln(sprintf("\t\t%s", $command));
$output->writeln("");
$output->writeln("");
}
} catch (\Exception $e) {
$output->writeln(sprintf('An error occured while upgrading : %s ', $e->getMessage()));
}
} else {
$output->write('Canceled', true);
}
$output->write('Finished !', true);
return 0;
}
}