Use exceptions for in input validation.

This commit is contained in:
Andreas Fischer 2014-04-15 18:14:26 +02:00
parent 854dd8fa7c
commit f1d05d204e

View file

@ -97,23 +97,24 @@ class ConvertType extends Command {
protected function validateInput(InputInterface $input, OutputInterface $output) { protected function validateInput(InputInterface $input, OutputInterface $output) {
$type = $input->getArgument('type'); $type = $input->getArgument('type');
if ($this->connectionFactory->normalizeType($type) === 'sqlite3') { if ($this->connectionFactory->normalizeType($type) === 'sqlite3') {
$output->writeln('<error>Converting to SQLite (sqlite3) is currently not supported.</error>'); throw new \InvalidArgumentException(
return 1; 'Converting to SQLite (sqlite3) is currently not supported.'
);
} }
if ($type === $this->config->getValue('dbtype', '')) { if ($type === $this->config->getValue('dbtype', '')) {
$output->writeln(sprintf( throw new \InvalidArgumentException(sprintf(
'<error>Can not convert from %1$s to %1$s.</error>', 'Can not convert from %1$s to %1$s.',
$type $type
)); ));
return 1;
} }
if ($type === 'oci' && $input->getOption('clear-schema')) { if ($type === 'oci' && $input->getOption('clear-schema')) {
// Doctrine unconditionally tries (at least in version 2.3) // Doctrine unconditionally tries (at least in version 2.3)
// to drop sequence triggers when dropping a table, even though // to drop sequence triggers when dropping a table, even though
// such triggers may not exist. This results in errors like // such triggers may not exist. This results in errors like
// "ORA-04080: trigger 'OC_STORAGES_AI_PK' does not exist". // "ORA-04080: trigger 'OC_STORAGES_AI_PK' does not exist".
$output->writeln('<error>The --clear-schema option is not supported when converting to Oracle (oci).</error>'); throw new \InvalidArgumentException(
return 1; 'The --clear-schema option is not supported when converting to Oracle (oci).'
);
} }
} }
@ -148,11 +149,7 @@ class ConvertType extends Command {
} }
protected function execute(InputInterface $input, OutputInterface $output) { protected function execute(InputInterface $input, OutputInterface $output) {
$inputError = $this->validateInput($input, $output); $this->validateInput($input, $output);
if ($inputError) {
return $inputError;
}
$this->readPassword($input, $output); $this->readPassword($input, $output);
$fromDB = \OC_DB::getConnection(); $fromDB = \OC_DB::getConnection();