Merge pull request #54104 from nextcloud/backport/54027/stable30

[stable30] fix(ConnectionFactory): Apply Oracle connection fix to primary and replica params as well
This commit is contained in:
Joas Schilling 2025-07-29 09:51:41 +02:00 committed by GitHub
commit 286c10c8b9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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;
}
}