Skip to content

Commit ac6171e

Browse files
committed
Add event subscriber for transaction isolation level
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
1 parent 1437c21 commit ac6171e

File tree

5 files changed

+49
-2
lines changed

5 files changed

+49
-2
lines changed

lib/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -884,6 +884,7 @@
884884
'OC\\DB\\SQLiteMigrator' => $baseDir . '/lib/private/DB/SQLiteMigrator.php',
885885
'OC\\DB\\SQLiteSessionInit' => $baseDir . '/lib/private/DB/SQLiteSessionInit.php',
886886
'OC\\DB\\SchemaWrapper' => $baseDir . '/lib/private/DB/SchemaWrapper.php',
887+
'OC\\DB\\SetTransactionIsolationLevel' => $baseDir . '/lib/private/DB/SetTransactionIsolationLevel.php',
887888
'OC\\Dashboard\\DashboardManager' => $baseDir . '/lib/private/Dashboard/DashboardManager.php',
888889
'OC\\DatabaseException' => $baseDir . '/lib/private/DatabaseException.php',
889890
'OC\\DatabaseSetupException' => $baseDir . '/lib/private/DatabaseSetupException.php',

lib/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -913,6 +913,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
913913
'OC\\DB\\SQLiteMigrator' => __DIR__ . '/../../..' . '/lib/private/DB/SQLiteMigrator.php',
914914
'OC\\DB\\SQLiteSessionInit' => __DIR__ . '/../../..' . '/lib/private/DB/SQLiteSessionInit.php',
915915
'OC\\DB\\SchemaWrapper' => __DIR__ . '/../../..' . '/lib/private/DB/SchemaWrapper.php',
916+
'OC\\DB\\SetTransactionIsolationLevel' => __DIR__ . '/../../..' . '/lib/private/DB/SetTransactionIsolationLevel.php',
916917
'OC\\Dashboard\\DashboardManager' => __DIR__ . '/../../..' . '/lib/private/Dashboard/DashboardManager.php',
917918
'OC\\DatabaseException' => __DIR__ . '/../../..' . '/lib/private/DatabaseException.php',
918919
'OC\\DatabaseSetupException' => __DIR__ . '/../../..' . '/lib/private/DatabaseSetupException.php',

lib/private/DB/Connection.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,6 @@ public function __construct(array $params, Driver $driver, Configuration $config
151151
parent::__construct($params, $driver, $config, $eventManager);
152152
$this->adapter = new $params['adapter']($this);
153153
$this->tablePrefix = $params['tablePrefix'];
154-
155-
$this->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);
156154
}
157155

158156
/**

lib/private/DB/ConnectionFactory.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ public function getDefaultConnectionParams($type) {
122122
public function getConnection($type, $additionalConnectionParams) {
123123
$normalizedType = $this->normalizeType($type);
124124
$eventManager = new EventManager();
125+
$eventManager->addEventSubscriber(new SetTransactionIsolationLevel());
125126
switch ($normalizedType) {
126127
case 'mysql':
127128
$eventManager->addEventSubscriber(
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright Copyright (c) 2019 Daniel Kesselberg <mail@danielkesselberg.de>
7+
*
8+
* @author Daniel Kesselberg <mail@danielkesselberg.de>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*
25+
*/
26+
27+
namespace OC\DB;
28+
29+
use Doctrine\Common\EventSubscriber;
30+
use Doctrine\DBAL\Event\ConnectionEventArgs;
31+
use Doctrine\DBAL\Events;
32+
use Doctrine\DBAL\TransactionIsolationLevel;
33+
34+
class SetTransactionIsolationLevel implements EventSubscriber {
35+
/**
36+
* @param ConnectionEventArgs $args
37+
* @return void
38+
*/
39+
public function postConnect(ConnectionEventArgs $args) {
40+
$args->getConnection()->setTransactionIsolation(TransactionIsolationLevel::READ_COMMITTED);
41+
}
42+
43+
public function getSubscribedEvents() {
44+
return [Events::postConnect];
45+
}
46+
}

0 commit comments

Comments
 (0)