diff options
author | Andreas Fischer <bantu@owncloud.com> | 2014-03-31 20:00:44 +0200 |
---|---|---|
committer | Andreas Fischer <bantu@owncloud.com> | 2014-03-31 20:09:07 +0200 |
commit | f9853b253c6ecb9a77a9d1c9006c5f548cdfd04e (patch) | |
tree | acd148a858ace6d0ebc71b5534bb0ee34b57d207 /core/command/db | |
parent | a585cec5303a7b3d361559f73bba154fcbe0c978 (diff) | |
download | nextcloud-server-f9853b253c6ecb9a77a9d1c9006c5f548cdfd04e.tar.gz nextcloud-server-f9853b253c6ecb9a77a9d1c9006c5f548cdfd04e.zip |
Deduplicate connection handling code into \OC\DB\ConnectionFactory
Diffstat (limited to 'core/command/db')
-rw-r--r-- | core/command/db/converttype.php | 45 |
1 files changed, 14 insertions, 31 deletions
diff --git a/core/command/db/converttype.php b/core/command/db/converttype.php index 387f873adb6..2a4e6747e65 100644 --- a/core/command/db/converttype.php +++ b/core/command/db/converttype.php @@ -22,10 +22,17 @@ class ConvertType extends Command { protected $config; /** + * @var \OC\DB\ConnectionFactory + */ + protected $connectionFactory; + + /** * @param \OC\Config $config + * @param \OC\DB\ConnectionFactory $connectionFactory */ - public function __construct($config) { + public function __construct($config, $connectionFactory) { $this->config = $config; + $this->connectionFactory = $connectionFactory; parent::__construct(); } @@ -87,12 +94,6 @@ class ConvertType extends Command { ; } - private static $type2driver = array( - 'mysql' => 'pdo_mysql', - 'pgsql' => 'pdo_pgsql', - 'oci' => 'oci8', - 'mssql' => 'pdo_sqlsrv', - ); protected function execute(InputInterface $input, OutputInterface $output) { $fromDB = \OC_DB::getConnection(); $toDB = $this->getToDBConnection($input, $output); @@ -140,35 +141,17 @@ class ConvertType extends Command { private function getToDBConnection($input, $output) { $type = $input->getArgument('type'); - $username = $input->getArgument('username'); - $hostname = $input->getArgument('hostname'); - $dbname = $input->getArgument('database'); - $password = $input->getOption('password'); - - if (!isset(self::$type2driver[$type])) { - throw new \InvalidArgumentException('Unknown type: '.$type); - } $connectionParams = array( - 'driver' => self::$type2driver[$type], - 'user' => $username, - 'password' => $password, - 'host' => $hostname, - 'dbname' => $dbname, + 'host' => $input->getArgument('hostname'), + 'user' => $input->getArgument('username'), + 'password' => $input->getOption('password'), + 'dbname' => $input->getArgument('database'), + 'tablePrefix' => $this->config->getValue('dbtableprefix', 'oc_'), ); if ($input->getOption('port')) { $connectionParams['port'] = $input->getOption('port'); } - switch ($type) { - case 'mysql': - case 'mssql': - $connectionParams['charset'] = 'UTF8'; - break; - case 'oci': - $connectionParams['charset'] = 'AL32UTF8'; - break; - } - - return \Doctrine\DBAL\DriverManager::getConnection($connectionParams); + return $this->connectionFactory->getConnection($type, $connectionParams); } private function getTables($db) { |