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') ->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('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('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; return $this;
} }
@@ -67,13 +68,25 @@ class module_console_systemUpgrade extends Command
$queries = $this->getService('phraseanet.appbox')->forceUpgrade($upgrader, $this->container); $queries = $this->getService('phraseanet.appbox')->forceUpgrade($upgrader, $this->container);
if ($input->getOption('dump')) { if ($input->getOption('dump') || $input->getOption('stderr')) {
if (0 < count($queries)) { if (0 < count($queries)) {
$output->writeln("Some SQL queries can be executed to optimize\n"); $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) { foreach ($queries as $query) {
if ($stderr) {
fwrite($handle, $query['sql']."\n");
} else {
$output->writeln(" ".$query['sql']); $output->writeln(" ".$query['sql']);
} }
}
if ($stderr) {
fclose ($handle);
}
$output->writeln("\n"); $output->writeln("\n");
} else { } else {