Skip to content

Commit 4daf9f6

Browse files
authored
Turn off autocommit for transactions (#16)
1 parent b0cd906 commit 4daf9f6

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

src/Storage/DbalNestedSet.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ public function addNodeAfter(Node $target, NodeKey $nodeKey) {
6666
protected function insertNodeAtPostion($newLeftPosition, $depth, NodeKey $nodeKey) {
6767

6868
try {
69+
$this->connection->setAutoCommit(FALSE);
6970
$this->connection->beginTransaction();
7071

7172
// Make space for inserting node.
@@ -85,6 +86,9 @@ protected function insertNodeAtPostion($newLeftPosition, $depth, NodeKey $nodeKe
8586
$this->connection->rollBack();
8687
throw $e;
8788
}
89+
finally {
90+
$this->connection->setAutoCommit(TRUE);
91+
}
8892
return $newNode;
8993

9094
}
@@ -271,6 +275,7 @@ public function deleteSubTree(Node $node) {
271275
$width = $right - $left + 1;
272276

273277
try {
278+
$this->connection->setAutoCommit(FALSE);
274279
$this->connection->beginTransaction();
275280

276281
// Delete the node.
@@ -292,6 +297,9 @@ public function deleteSubTree(Node $node) {
292297
$this->connection->rollBack();
293298
throw $e;
294299
}
300+
finally {
301+
$this->connection->setAutoCommit(TRUE);
302+
}
295303

296304
}
297305

@@ -347,6 +355,7 @@ protected function moveSubTreeToPosition($newLeftPosition, Node $node, $newDepth
347355
$distance = $newLeftPosition - $node->getLeft();
348356
$tempPos = $node->getLeft();
349357

358+
$this->connection->setAutoCommit(FALSE);
350359
$this->connection->beginTransaction();
351360

352361
// Calculate depth difference.
@@ -386,6 +395,9 @@ protected function moveSubTreeToPosition($newLeftPosition, Node $node, $newDepth
386395
$this->connection->rollBack();
387396
throw $e;
388397
}
398+
finally {
399+
$this->connection->setAutoCommit(TRUE);
400+
}
389401

390402
}
391403

0 commit comments

Comments
 (0)