Merge pull request #54027 from nextcloud/fix/oracle-db-connection

fix(ConnectionFactory): Apply Oracle connection fix to primary and replica params as well
pull/54009/head
Joas Schilling 2025-07-28 08:13:33 +07:00 committed by GitHub
commit 93d07e814b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 23 additions and 15 deletions

@ -121,21 +121,9 @@ class ConnectionFactory {
case 'oci':
$eventManager->addEventSubscriber(new OracleSessionInit);
// the driverOptions are unused in dbal and need to be mapped to the parameters
if (isset($connectionParams['driverOptions'])) {
$connectionParams = array_merge($connectionParams, $connectionParams['driverOptions']);
}
$host = $connectionParams['host'];
$port = $connectionParams['port'] ?? null;
$dbName = $connectionParams['dbname'];
// we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string
if ($host === '') {
$connectionParams['dbname'] = $dbName; // use dbname as easy connect name
} else {
$connectionParams['dbname'] = '//' . $host . (!empty($port) ? ":{$port}" : '') . '/' . $dbName;
}
unset($connectionParams['host']);
$connectionParams = $this->forceConnectionStringOracle($connectionParams);
$connectionParams['primary'] = $this->forceConnectionStringOracle($connectionParams['primary']);
$connectionParams['replica'] = array_map([$this, 'forceConnectionStringOracle'], $connectionParams['replica']);
break;
case 'sqlite3':
@ -265,4 +253,24 @@ class ConnectionFactory {
return $params;
}
protected function forceConnectionStringOracle(array $connectionParams): array {
// the driverOptions are unused in dbal and need to be mapped to the parameters
if (isset($connectionParams['driverOptions'])) {
$connectionParams = array_merge($connectionParams, $connectionParams['driverOptions']);
}
$host = $connectionParams['host'];
$port = $connectionParams['port'] ?? null;
$dbName = $connectionParams['dbname'];
// we set the connect string as dbname and unset the host to coerce doctrine into using it as connect string
if ($host === '') {
$connectionParams['dbname'] = $dbName; // use dbname as easy connect name
} else {
$connectionParams['dbname'] = '//' . $host . (!empty($port) ? ":{$port}" : '') . '/' . $dbName;
}
unset($connectionParams['host']);
return $connectionParams;
}
}