summaryrefslogtreecommitdiff
path: root/app/php/db/DBTransaction.php
diff options
context:
space:
mode:
authoremkael <emkael@tlen.pl>2016-02-26 14:59:34 +0100
committeremkael <emkael@tlen.pl>2016-02-26 14:59:34 +0100
commitb6ad16cbd2092d76d4fed03d37a77d29b5b38f00 (patch)
tree437bb2efbce01724cde04320edfb61d3e6fade93 /app/php/db/DBTransaction.php
parent16b4dda0f1d2df3a280b6507e12fe381ba0e8e74 (diff)
* database connection setup in PHP app
Diffstat (limited to 'app/php/db/DBTransaction.php')
-rw-r--r--app/php/db/DBTransaction.php53
1 files changed, 53 insertions, 0 deletions
diff --git a/app/php/db/DBTransaction.php b/app/php/db/DBTransaction.php
new file mode 100644
index 0000000..b176453
--- /dev/null
+++ b/app/php/db/DBTransaction.php
@@ -0,0 +1,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;
+ }
+ }
+
+}
+
+?>