summaryrefslogtreecommitdiff
path: root/app/frontend/db/DBTransaction.php
blob: b176453dbb352b428a23a428872a7737b4f9858a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php

Prado::using('Application.db.DBConnection');
Prado::using('System.Data.TDbTransaction');

class DBTransaction extends TDbTransaction {

   private $_nestedCount = 0;
   private $_rolledBack = FALSE;

   public function beginNestedTransaction() {
      if ($this->getActive()) {
         $this->_nestedCount++;
      }
   }

   public function commit() {
      if ($this->_rolledBack) {
         $childTransaction = (bool)($this->_nestedCount);
         $this->rollback();
         if (!$childTransaction) {
            throw new TDbException('Nested transaction was rolled back, unable to commit.');
         }
      }
      else {
         if ($this->_nestedCount) {
            $this->_nestedCount--;
         }
         else {
            parent::commit();
         }
      }
   }

   public function rollback() {
      if (!$this->getActive()) {
         $this->_nestedCount = 0;
         return;
      }
      if ($this->_nestedCount) {
         $this->_rolledBack = TRUE;
         $this->_nestedCount--;
      }
      else {
         parent::rollback();
         $this->_nestedCount = 0;
         $this->_rolledBack = FALSE;
      }
   }

}

?>