From d2c7a8ee59d57be1441f771ff00350d5f677999f Mon Sep 17 00:00:00 2001 From: Andreas Fischer Date: Tue, 15 Apr 2014 17:30:43 +0200 Subject: [PATCH] Do not ask for password before input parameter validation. --- core/command/db/converttype.php | 45 ++++++++++++++++++++++----------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/core/command/db/converttype.php b/core/command/db/converttype.php index 3382ebb017..8f3047b8a0 100644 --- a/core/command/db/converttype.php +++ b/core/command/db/converttype.php @@ -43,20 +43,6 @@ class ConvertType extends Command { parent::__construct(); } - protected function interact(InputInterface $input, OutputInterface $output) { - parent::interact($input, $output); - if (!$input->getOption('password')) { - /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ - $dialog = $this->getHelperSet()->get('dialog'); - $password = $dialog->askHiddenResponse( - $output, - 'What is the database password?', - false - ); - $input->setOption('password', $password); - } - } - protected function configure() { $this ->setName('db:convert-type') @@ -91,7 +77,7 @@ class ConvertType extends Command { 'password', null, InputOption::VALUE_REQUIRED, - 'the password of the database to convert to. Will be asked when not specified' + 'the password of the database to convert to. Will be asked when not specified. Can also be passed via stdin.' ) ->addOption( 'clear-schema', @@ -131,12 +117,41 @@ class ConvertType extends Command { } } + protected function readPassword(InputInterface $input, OutputInterface $output) { + // Explicitly specified password + if ($input->getOption('password')) { + return; + } + + // Read from stdin + $password = file_get_contents('php://stdin'); + if (trim($password) !== '') { + $input->setOption('password', $password); + return; + } + + // Read password by interacting + if ($input->isInteractive()) { + /** @var $dialog \Symfony\Component\Console\Helper\DialogHelper */ + $dialog = $this->getHelperSet()->get('dialog'); + $password = $dialog->askHiddenResponse( + $output, + 'What is the database password?', + false + ); + $input->setOption('password', $password); + return; + } + } + protected function execute(InputInterface $input, OutputInterface $output) { $inputError = $this->validateInput($input, $output); if ($inputError) { return $inputError; } + $this->readPassword($input, $output); + $fromDB = \OC_DB::getConnection(); $toDB = $this->getToDBConnection($input, $output);