diff options
author | Robin Appelman <icewind@owncloud.com> | 2016-07-12 13:11:44 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2016-07-12 14:38:24 +0200 |
commit | 8a79d314cf544cf2ca261cbac7ea07570e9ed8e5 (patch) | |
tree | 5242aa67b16c0e7ea0e2e1bf198f8434b0a8f358 /lib/private/Setup/AbstractDatabase.php | |
parent | 2bf7d3a5bd31ecdabeade82b0ac45b061d41d186 (diff) | |
download | nextcloud-server-8a79d314cf544cf2ca261cbac7ea07570e9ed8e5.tar.gz nextcloud-server-8a79d314cf544cf2ca261cbac7ea07570e9ed8e5.zip |
Remove duplicate database connect logic in mysql setup
Diffstat (limited to 'lib/private/Setup/AbstractDatabase.php')
-rw-r--r-- | lib/private/Setup/AbstractDatabase.php | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/lib/private/Setup/AbstractDatabase.php b/lib/private/Setup/AbstractDatabase.php index 08ed741f51c..62e9b2e823f 100644 --- a/lib/private/Setup/AbstractDatabase.php +++ b/lib/private/Setup/AbstractDatabase.php @@ -23,6 +23,8 @@ */ namespace OC\Setup; +use OC\AllConfig; +use OC\DB\ConnectionFactory; use OCP\IConfig; use OCP\ILogger; use OCP\Security\ISecureRandom; @@ -45,7 +47,7 @@ abstract class AbstractDatabase { protected $dbPort; /** @var string */ protected $tablePrefix; - /** @var IConfig */ + /** @var AllConfig */ protected $config; /** @var ILogger */ protected $logger; @@ -99,6 +101,24 @@ abstract class AbstractDatabase { } /** + * @return \OC\DB\Connection + * @throws \OC\DatabaseSetupException + */ + protected function connect() { + $systemConfig = $this->config->getSystemConfig(); + $cf = new ConnectionFactory(); + $connectionParams = $cf->createConnectionParams($systemConfig); + // we don't save username/password to the config immediately so this might not be set + if (!$connectionParams['user']) { + $connectionParams['user'] = $this->dbUser; + } + if (!$connectionParams['password']) { + $connectionParams['password'] = $this->dbPassword; + } + return $cf->getConnection($systemConfig->getValue('dbtype', 'sqlite'), $connectionParams); + } + + /** * @param string $userName */ abstract public function setupDatabase($userName); |