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/db | |
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/db')
-rw-r--r-- | lib/private/db/connectionfactory.php | 37 |
1 files changed, 37 insertions, 0 deletions
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; + } } |