summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAleksander Machniak <machniak@kolabsys.com>2014-09-18 09:30:12 (GMT)
committerAleksander Machniak <machniak@kolabsys.com>2014-09-18 09:30:12 (GMT)
commitc4bc1954b0d17155ed2bce9591f4e4d256f10452 (patch)
treeae09495f707a676effed0f01f5df7cde783dff8f
parent18dc3e4ae07b77dba761e0712571aa5f6bed4187 (diff)
downloadkolab-syncroton-c4bc1954b0d17155ed2bce9591f4e4d256f10452.tar.gz
Handle database transactions with rcube_db class
-rw-r--r--lib/kolab_sync.php2
-rw-r--r--lib/kolab_sync_db.php64
-rw-r--r--lib/kolab_sync_transaction_manager.php31
3 files changed, 9 insertions, 88 deletions
diff --git a/lib/kolab_sync.php b/lib/kolab_sync.php
index ab9c27c..515076e 100644
--- a/lib/kolab_sync.php
+++ b/lib/kolab_sync.php
@@ -141,7 +141,7 @@ class kolab_sync extends rcube
// Register Syncroton backends
Syncroton_Registry::set('loggerBackend', $this->logger);
- Syncroton_Registry::set(Syncroton_Registry::DATABASE, new kolab_sync_db);
+ Syncroton_Registry::set(Syncroton_Registry::DATABASE, $this->get_dbh());
Syncroton_Registry::set(Syncroton_Registry::TRANSACTIONMANAGER, kolab_sync_transaction_manager::getInstance());
Syncroton_Registry::set(Syncroton_Registry::DEVICEBACKEND, new kolab_sync_backend_device);
Syncroton_Registry::set(Syncroton_Registry::FOLDERBACKEND, new kolab_sync_backend_folder);
diff --git a/lib/kolab_sync_db.php b/lib/kolab_sync_db.php
deleted file mode 100644
index b56ce52..0000000
--- a/lib/kolab_sync_db.php
+++ /dev/null
@@ -1,64 +0,0 @@
-<?php
-
-/**
- +--------------------------------------------------------------------------+
- | Kolab Sync (ActiveSync for Kolab) |
- | |
- | Copyright (C) 2011-2012, Kolab Systems AG <contact@kolabsys.com> |
- | |
- | This program is free software: you can redistribute it and/or modify |
- | it under the terms of the GNU Affero General Public License as published |
- | by the Free Software Foundation, either version 3 of the License, or |
- | (at your option) any later version. |
- | |
- | This program is distributed in the hope that it will be useful, |
- | but WITHOUT ANY WARRANTY; without even the implied warranty of |
- | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
- | GNU Affero General Public License for more details. |
- | |
- | You should have received a copy of the GNU Affero General Public License |
- | along with this program. If not, see <http://www.gnu.org/licenses/> |
- +--------------------------------------------------------------------------+
- | Author: Aleksander Machniak <machniak@kolabsys.com> |
- +--------------------------------------------------------------------------+
-*/
-
-/**
- * Database layer wrapper with transaction support
- */
-class kolab_sync_db
-{
- /**
- * the database adapter
- *
- * @var rcube_db
- */
- protected $db;
-
-
- public function __construct()
- {
- $this->db = rcube::get_instance()->get_dbh();
- }
-
- public function beginTransaction()
- {
- $query = 'BEGIN';
-
- $this->db->query($query);
- }
-
- public function commit()
- {
- $query = 'COMMIT';
-
- $this->db->query($query);
- }
-
- public function rollBack()
- {
- $query = 'ROLLBACK';
-
- $this->db->query($query);
- }
-}
diff --git a/lib/kolab_sync_transaction_manager.php b/lib/kolab_sync_transaction_manager.php
index e097378..2121d89 100644
--- a/lib/kolab_sync_transaction_manager.php
+++ b/lib/kolab_sync_transaction_manager.php
@@ -103,13 +103,8 @@ class kolab_sync_transaction_manager implements Syncroton_TransactionManagerInte
}
if (! in_array($_transactionable, $this->_openTransactionables)) {
- if ($this->_logger instanceof Zend_Log) {
- $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " new transactionable. Starting transaction on this resource");
- }
-
- if ($_transactionable instanceof kolab_sync_db) {
- //setAutocommit($_transactionable,false);
- $_transactionable->beginTransaction();
+ if ($_transactionable instanceof rcube_db) {
+ $_transactionable->startTransaction();
}
else {
$this->rollBack();
@@ -122,10 +117,6 @@ class kolab_sync_transaction_manager implements Syncroton_TransactionManagerInte
$transactionId = sha1(mt_rand(). microtime());
array_push($this->_openTransactions, $transactionId);
- if ($this->_logger instanceof Zend_Log) {
- $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " queued transaction with id $transactionId");
- }
-
return $transactionId;
}
@@ -149,19 +140,14 @@ class kolab_sync_transaction_manager implements Syncroton_TransactionManagerInte
$numOpenTransactions = count($this->_openTransactions);
if ($numOpenTransactions === 0) {
- if ($this->_logger instanceof Zend_Log) {
- $this->_logger->debug(__METHOD__ . '::' . __LINE__ . " no more open transactions in queue commiting all transactionables");
- }
-
foreach ($this->_openTransactionables as $transactionableIdx => $transactionable) {
- if ($transactionable instanceof kolab_sync_db) {
- $transactionable->commit();
- //setAutocommit($transactionable,true);
+ if ($transactionable instanceof rcube_db) {
+ $transactionable->endTransaction();
}
}
$this->_openTransactionables = array();
- $this->_openTransactions = array();
+ $this->_openTransactions = array();
}
else {
if ($this->_logger instanceof Zend_Log) {
@@ -182,13 +168,12 @@ class kolab_sync_transaction_manager implements Syncroton_TransactionManagerInte
}
foreach ($this->_openTransactionables as $transactionable) {
- if ($transactionable instanceof kolab_sync_db) {
- $transactionable->rollBack();
- //setAutocommit($transactionable,true);
+ if ($transactionable instanceof rcube_db) {
+ $transactionable->rollbackTransaction();
}
}
$this->_openTransactionables = array();
- $this->_openTransactions = array();
+ $this->_openTransactions = array();
}
}