diff options
author | Robin Appelman <icewind@owncloud.com> | 2014-09-10 13:24:49 +0200 |
---|---|---|
committer | Robin Appelman <icewind@owncloud.com> | 2014-10-22 12:29:53 +0200 |
commit | 2ae6a0d96d45e2270a9c06bbfc91d1733fa9fce3 (patch) | |
tree | a02dab9af63252245b27d94b5ac625a3aa6e44e5 /lib/private/server.php | |
parent | d4e929c37a70291e33c9a686e6e5576bd2a3dd86 (diff) | |
download | nextcloud-server-2ae6a0d96d45e2270a9c06bbfc91d1733fa9fce3.tar.gz nextcloud-server-2ae6a0d96d45e2270a9c06bbfc91d1733fa9fce3.zip |
Move creating the database connection to the server container
Diffstat (limited to 'lib/private/server.php')
-rw-r--r-- | lib/private/server.php | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/lib/private/server.php b/lib/private/server.php index 26d540ab239..b0d63af1554 100644 --- a/lib/private/server.php +++ b/lib/private/server.php @@ -217,8 +217,25 @@ class Server extends SimpleContainer implements IServerContainer { $this->registerService('Crypto', function ($c) { return new Crypto(\OC::$server->getConfig(), \OC::$server->getSecureRandom()); }); + $this->registerService('DatabaseConnection', function ($c) { + /** + * @var Server $c + */ + $factory = new \OC\DB\ConnectionFactory(); + $type = $c->getConfig()->getSystemValue('dbtype', 'sqlite'); + if (!$factory->isValidType($type)) { + throw new \DatabaseException('Invalid database type'); + } + $connectionParams = $factory->createConnectionParams($c->getConfig()); + $connection = $factory->getConnection($type, $connectionParams); + $connection->getConfiguration()->setSQLLogger($c->getQueryLogger()); + return $connection; + }); $this->registerService('Db', function ($c) { - return new Db(); + /** + * @var Server $c + */ + return new Db($c->getDatabaseConnection()); }); $this->registerService('HTTPHelper', function (SimpleContainer $c) { $config = $c->query('AllConfig'); @@ -469,7 +486,7 @@ class Server extends SimpleContainer implements IServerContainer { * @return \OCP\IDBConnection */ function getDatabaseConnection() { - return \OC_DB::getConnection(); + return $this->query('DatabaseConnection'); } /** |