From 3124d7634e48751f091c8ed73effa4051721a6b0 Mon Sep 17 00:00:00 2001 From: Romain Neutron Date: Wed, 29 Jan 2014 16:45:42 +0100 Subject: [PATCH] Add option to dump SQL queries in stderr --- lib/classes/module/console/systemUpgrade.php | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/classes/module/console/systemUpgrade.php b/lib/classes/module/console/systemUpgrade.php index 0d0b82cc0c..810b8cfde7 100644 --- a/lib/classes/module/console/systemUpgrade.php +++ b/lib/classes/module/console/systemUpgrade.php @@ -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");