Merge pull request #9018 from owncloud/dbms-socket-support

Refactor OC_DB::connect() to properly support sockets.
This commit is contained in:
Frank Karlitschek 2014-06-13 18:09:51 +02:00
commit 87101e6638
2 changed files with 20 additions and 26 deletions

View File

@ -26,7 +26,7 @@ $CONFIG = array(
/* Password to access the ownCloud database */ /* Password to access the ownCloud database */
"dbpassword" => "", "dbpassword" => "",
/* Host running the ownCloud database */ /* Host running the ownCloud database. To specify a port use "HOSTNAME:####"; to specify a unix sockets use "localhost:/path/to/socket". */
"dbhost" => "", "dbhost" => "",
/* Prefix for the ownCloud tables in the database */ /* Prefix for the ownCloud tables in the database */

View File

@ -57,41 +57,35 @@ class OC_DB {
return true; return true;
} }
// The global data we need $type = OC_Config::getValue('dbtype', 'sqlite');
$name = OC_Config::getValue( "dbname", "owncloud" );
$host = OC_Config::getValue( "dbhost", "" );
$user = OC_Config::getValue( "dbuser", "" );
$pass = OC_Config::getValue( "dbpassword", "" );
$type = OC_Config::getValue( "dbtype", "sqlite" );
if(strpos($host, ':')) {
list($host, $port)=explode(':', $host, 2);
} else {
$port=false;
}
$factory = new \OC\DB\ConnectionFactory(); $factory = new \OC\DB\ConnectionFactory();
if (!$factory->isValidType($type)) { if (!$factory->isValidType($type)) {
return false; return false;
} }
$connectionParams = array(
'user' => OC_Config::getValue('dbuser', ''),
'password' => OC_Config::getValue('dbpassword', ''),
);
$name = OC_Config::getValue('dbname', 'owncloud');
if ($factory->normalizeType($type) === 'sqlite3') { if ($factory->normalizeType($type) === 'sqlite3') {
$datadir = OC_Config::getValue("datadirectory", OC::$SERVERROOT.'/data'); $datadir = OC_Config::getValue("datadirectory", OC::$SERVERROOT.'/data');
$connectionParams = array( $connectionParams['path'] = $datadir.'/'.$name.'.db';
'user' => $user,
'password' => $pass,
'path' => $datadir.'/'.$name.'.db',
);
} else { } else {
$connectionParams = array( $host = OC_Config::getValue('dbhost', '');
'user' => $user, if (strpos($host, ':')) {
'password' => $pass, // Host variable may carry a port or socket.
'host' => $host, list($host, $portOrSocket) = explode(':', $host, 2);
'dbname' => $name, if (ctype_digit($portOrSocket)) {
); $connectionParams['host'] = $host;
if (!empty($port)) { $connectionParams['port'] = $portOrSocket;
$connectionParams['port'] = $port; } else {
$connectionParams['unix_socket'] = $portOrSocket;
} }
} }
$connectionParams['dbname'] = $name;
}
$connectionParams['tablePrefix'] = OC_Config::getValue('dbtableprefix', 'oc_'); $connectionParams['tablePrefix'] = OC_Config::getValue('dbtableprefix', 'oc_');