2019-11-15 21:20:35 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
/**
|
2024-05-23 07:26:56 +00:00
|
|
|
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-11-15 21:20:35 +00:00
|
|
|
*/
|
|
|
|
namespace OC\DB;
|
|
|
|
|
|
|
|
use Doctrine\Common\EventSubscriber;
|
2023-12-03 08:14:55 +00:00
|
|
|
use Doctrine\DBAL\Connections\PrimaryReadReplicaConnection;
|
2019-11-15 21:20:35 +00:00
|
|
|
use Doctrine\DBAL\Event\ConnectionEventArgs;
|
|
|
|
use Doctrine\DBAL\Events;
|
2023-12-03 08:14:55 +00:00
|
|
|
use Doctrine\DBAL\Platforms\MySQLPlatform;
|
2019-11-15 21:20:35 +00:00
|
|
|
use Doctrine\DBAL\TransactionIsolationLevel;
|
|
|
|
|
|
|
|
class SetTransactionIsolationLevel implements EventSubscriber {
|
|
|
|
/**
|
|
|
|
* @param ConnectionEventArgs $args
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function postConnect(ConnectionEventArgs $args) {
|
2023-12-03 08:14:55 +00:00
|
|
|
$connection = $args->getConnection();
|
|
|
|
if ($connection instanceof PrimaryReadReplicaConnection && $connection->isConnectedToPrimary()) {
|
|
|
|
$connection->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);
|
|
|
|
if ($connection->getDatabasePlatform() instanceof MySQLPlatform) {
|
|
|
|
$connection->executeStatement('SET SESSION AUTOCOMMIT=1');
|
|
|
|
}
|
|
|
|
}
|
2019-11-15 21:20:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
public function getSubscribedEvents() {
|
|
|
|
return [Events::postConnect];
|
|
|
|
}
|
|
|
|
}
|