setDescription('Upgrades Phraseanet to the latest version')
->addOption('yes', 'y', InputOption::VALUE_NONE, 'Answers yes to all questions and do not ask the user')
->addOption('force', 'f', InputOption::VALUE_NONE, 'Forces the upgrade even if there is a concurrent upgrade')
->addOption('dump', 'd', InputOption::VALUE_NONE, 'Dumps SQL queries that can be used to clean database.')
->addOption('stderr', 's', InputOption::VALUE_NONE, 'Dumps SQL queries to stderr');
return $this;
}
protected function doExecute(InputInterface $input, OutputInterface $output)
{
$interactive = !$input->getOption('yes');
while ($migrations = $this->container['phraseanet.configuration-tester']->getMigrations()) {
foreach ($migrations as $migration) {
$migration->migrate();
}
}
if (!$this->getService('phraseanet.configuration-tester')->isInstalled()) {
throw new \RuntimeException('Phraseanet must be set-up');
}
$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') {
$output->write(sprintf('Upgrading... from version %s to %s', $this->container['phraseanet.appbox']->get_version(), Version::getNumber()), 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->container, $input->getOption('force'));
$queries = $this->getService('phraseanet.appbox')->forceUpgrade($upgrader, $this->container);
if ($input->getOption('dump') || $input->getOption('stderr')) {
if (0 < count($queries)) {
$output->writeln("Some SQL queries can be executed to optimize\n");
$stderr = $input->getOption('stderr');
if ($stderr) {
$handle = fopen('php://stderr', 'a');
}
foreach ($queries as $query) {
if ($stderr) {
fwrite($handle, $query['sql']."\n");
} else {
$output->writeln(" ".$query['sql']);
}
}
if ($stderr) {
fclose ($handle);
}
$output->writeln("\n");
} else {
$output->writeln("No SQL queries to execute to optimize\n");
}
}
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("");
}
if (null !== $this->getApplication()) {
$command = $this->getApplication()->find('crossdomain:generate');
$command->run(new ArrayInput(array(
'command' => 'crossdomain:generate'
)), $output);
}
} else {
$output->write('Canceled', true);
}
$output->write('Finished !', true);
return 0;
}
}