|
|
|
@ -32,7 +32,6 @@ use Doctrine\Common\EventManager;
|
|
|
|
|
use Doctrine\DBAL\Configuration;
|
|
|
|
|
use Doctrine\DBAL\DriverManager;
|
|
|
|
|
use Doctrine\DBAL\Event\Listeners\OracleSessionInit;
|
|
|
|
|
use Doctrine\DBAL\Event\Listeners\SQLSessionInit;
|
|
|
|
|
use OC\SystemConfig;
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
@ -127,11 +126,8 @@ class ConnectionFactory {
|
|
|
|
|
$normalizedType = $this->normalizeType($type);
|
|
|
|
|
$eventManager = new EventManager();
|
|
|
|
|
$eventManager->addEventSubscriber(new SetTransactionIsolationLevel());
|
|
|
|
|
$additionalConnectionParams = array_merge($this->createConnectionParams(), $additionalConnectionParams);
|
|
|
|
|
switch ($normalizedType) {
|
|
|
|
|
case 'mysql':
|
|
|
|
|
$eventManager->addEventSubscriber(
|
|
|
|
|
new SQLSessionInit("SET SESSION AUTOCOMMIT=1"));
|
|
|
|
|
break;
|
|
|
|
|
case 'oci':
|
|
|
|
|
$eventManager->addEventSubscriber(new OracleSessionInit);
|
|
|
|
|
// the driverOptions are unused in dbal and need to be mapped to the parameters
|
|
|
|
@ -159,7 +155,7 @@ class ConnectionFactory {
|
|
|
|
|
}
|
|
|
|
|
/** @var Connection $connection */
|
|
|
|
|
$connection = DriverManager::getConnection(
|
|
|
|
|
array_merge($this->getDefaultConnectionParams($type), $additionalConnectionParams),
|
|
|
|
|
$additionalConnectionParams,
|
|
|
|
|
new Configuration(),
|
|
|
|
|
$eventManager
|
|
|
|
|
);
|
|
|
|
@ -195,10 +191,10 @@ class ConnectionFactory {
|
|
|
|
|
public function createConnectionParams(string $configPrefix = '') {
|
|
|
|
|
$type = $this->config->getValue('dbtype', 'sqlite');
|
|
|
|
|
|
|
|
|
|
$connectionParams = [
|
|
|
|
|
$connectionParams = array_merge($this->getDefaultConnectionParams($type), [
|
|
|
|
|
'user' => $this->config->getValue($configPrefix . 'dbuser', $this->config->getValue('dbuser', '')),
|
|
|
|
|
'password' => $this->config->getValue($configPrefix . 'dbpassword', $this->config->getValue('dbpassword', '')),
|
|
|
|
|
];
|
|
|
|
|
]);
|
|
|
|
|
$name = $this->config->getValue($configPrefix . 'dbname', $this->config->getValue('dbname', self::DEFAULT_DBNAME));
|
|
|
|
|
|
|
|
|
|
if ($this->normalizeType($type) === 'sqlite3') {
|
|
|
|
@ -237,7 +233,11 @@ class ConnectionFactory {
|
|
|
|
|
$connectionParams['persistent'] = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $connectionParams;
|
|
|
|
|
$replica = $this->config->getValue('dbreplica', []) ?: [$connectionParams];
|
|
|
|
|
return array_merge($connectionParams, [
|
|
|
|
|
'primary' => $connectionParams,
|
|
|
|
|
'replica' => $replica,
|
|
|
|
|
]);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|