Do not ask for password before input parameter validation.

This commit is contained in:
Andreas Fischer 2014-04-15 17:30:43 +02:00
parent 8e758513c8
commit d2c7a8ee59
1 changed files with 30 additions and 15 deletions

View File

@ -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,
'<question>What is the database password?</question>',
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,
'<question>What is the database password?</question>',
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);