[Pkg-owncloud-commits] [owncloud] 53/153: Do not ask for password before input parameter validation.

David Prévot taffit at moszumanska.debian.org
Tue May 27 03:05:34 UTC 2014


This is an automated email from the git hooks/post-receive script.

taffit pushed a commit to branch master
in repository owncloud.

commit d2c7a8ee59d57be1441f771ff00350d5f677999f
Author: Andreas Fischer <bantu at owncloud.com>
Date:   Tue Apr 15 17:30:43 2014 +0200

    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 3382ebb..8f3047b 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,
-				'<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);
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-owncloud/owncloud.git



More information about the Pkg-owncloud-commits mailing list