From 2ae6a0d96d45e2270a9c06bbfc91d1733fa9fce3 Mon Sep 17 00:00:00 2001 From: Robin Appelman Date: Wed, 10 Sep 2014 13:24:49 +0200 Subject: Move creating the database connection to the server container --- lib/private/db/connectionfactory.php | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) (limited to 'lib/private/db') diff --git a/lib/private/db/connectionfactory.php b/lib/private/db/connectionfactory.php index a5260c1a4c5..1f676f1fca2 100644 --- a/lib/private/db/connectionfactory.php +++ b/lib/private/db/connectionfactory.php @@ -118,4 +118,41 @@ class ConnectionFactory { $normalizedType = $this->normalizeType($type); return isset($this->defaultConnectionParams[$normalizedType]); } + + /** + * Create the connection parameters for the config + * + * @param \OCP\IConfig $config + * @return array + */ + public function createConnectionParams($config) { + $type = $config->getSystemValue('dbtype', 'sqlite'); + + $connectionParams = array( + 'user' => $config->getSystemValue('dbuser', ''), + 'password' => $config->getSystemValue('dbpassword', ''), + ); + $name = $config->getSystemValue('dbname', 'owncloud'); + + if ($this->normalizeType($type) === 'sqlite3') { + $datadir = $config->getSystemValue("datadirectory", \OC::$SERVERROOT . '/data'); + $connectionParams['path'] = $datadir . '/' . $name . '.db'; + } else { + $host = $config->getSystemValue('dbhost', ''); + if (strpos($host, ':')) { + // Host variable may carry a port or socket. + list($host, $portOrSocket) = explode(':', $host, 2); + if (ctype_digit($portOrSocket)) { + $connectionParams['port'] = $portOrSocket; + } else { + $connectionParams['unix_socket'] = $portOrSocket; + } + } + $connectionParams['host'] = $host; + $connectionParams['dbname'] = $name; + } + + $connectionParams['tablePrefix'] = $config->getSystemValue('dbtableprefix', 'oc_'); + return $connectionParams; + } } -- cgit v1.2.3