Skip to content

Commit

Permalink
Merge pull request #31059 from nextcloud/backport/30973/stable23
Browse files Browse the repository at this point in the history
[stable23] Allow specify a config prefix for another database connection
  • Loading branch information
PVince81 authored Feb 16, 2022
2 parents 78ebe4b + 016c6e3 commit 79f5c76
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions lib/private/DB/ConnectionFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,22 +189,23 @@ public function isValidType($type) {
/**
* Create the connection parameters for the config
*
* @param string $configPrefix
* @return array
*/
public function createConnectionParams() {
public function createConnectionParams(string $configPrefix = '') {
$type = $this->config->getValue('dbtype', 'sqlite');

$connectionParams = [
'user' => $this->config->getValue('dbuser', ''),
'password' => $this->config->getValue('dbpassword', ''),
'user' => $this->config->getValue($configPrefix . 'dbuser', $this->config->getValue('dbuser', '')),
'password' => $this->config->getValue($configPrefix . 'dbpassword', $this->config->getValue('dbpassword', '')),
];
$name = $this->config->getValue('dbname', self::DEFAULT_DBNAME);
$name = $this->config->getValue($configPrefix . 'dbname', $this->config->getValue('dbname', self::DEFAULT_DBNAME));

if ($this->normalizeType($type) === 'sqlite3') {
$dataDir = $this->config->getValue("datadirectory", \OC::$SERVERROOT . '/data');
$connectionParams['path'] = $dataDir . '/' . $name . '.db';
} else {
$host = $this->config->getValue('dbhost', '');
$host = $this->config->getValue($configPrefix . 'dbhost', $this->config->getValue('dbhost', ''));
$connectionParams = array_merge($connectionParams, $this->splitHostFromPortAndSocket($host));
$connectionParams['dbname'] = $name;
}
Expand All @@ -213,7 +214,7 @@ public function createConnectionParams() {
$connectionParams['sqlite.journal_mode'] = $this->config->getValue('sqlite.journal_mode', 'WAL');

//additional driver options, eg. for mysql ssl
$driverOptions = $this->config->getValue('dbdriveroptions', null);
$driverOptions = $this->config->getValue($configPrefix . 'dbdriveroptions', $this->config->getValue('dbdriveroptions', null));
if ($driverOptions) {
$connectionParams['driverOptions'] = $driverOptions;
}
Expand Down

0 comments on commit 79f5c76

Please sign in to comment.