Add option to dump SQL queries in stderr

This commit is contained in:
Romain Neutron
2014-01-29 16:45:42 +01:00
parent 8d695c6539
commit 3124d7634e

View File

@@ -25,7 +25,8 @@ class module_console_systemUpgrade extends Command
->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('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;
}
@@ -67,12 +68,24 @@ class module_console_systemUpgrade extends Command
$queries = $this->getService('phraseanet.appbox')->forceUpgrade($upgrader, $this->container);
if ($input->getOption('dump')) {
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) {
$output->writeln(" ".$query['sql']);
if ($stderr) {
fwrite($handle, $query['sql']."\n");
} else {
$output->writeln(" ".$query['sql']);
}
}
if ($stderr) {
fclose ($handle);
}
$output->writeln("\n");