From a593d746c372d1c1c397c243858eb4c7a9e049b7 Mon Sep 17 00:00:00 2001 From: zYne Date: Mon, 25 Jun 2007 17:51:19 +0000 Subject: [PATCH] --- lib/Doctrine/EventListener.php | 16 +++++++++ lib/Doctrine/Transaction.php | 63 ++++++++++++++++++++++++---------- 2 files changed, 60 insertions(+), 19 deletions(-) diff --git a/lib/Doctrine/EventListener.php b/lib/Doctrine/EventListener.php index d6b3507ba..1d6b9d95c 100644 --- a/lib/Doctrine/EventListener.php +++ b/lib/Doctrine/EventListener.php @@ -78,6 +78,22 @@ class Doctrine_EventListener implements Doctrine_EventListener_Interface public function postTransactionBegin(Doctrine_Event $event) { } + + public function preSavepointCommit(Doctrine_Event $event) + { } + public function postSavepointCommit(Doctrine_Event $event) + { } + + public function preSavepointRollback(Doctrine_Event $event) + { } + public function postSavepointRollback(Doctrine_Event $event) + { } + + public function preSavepointCreate(Doctrine_Event $event) + { } + public function postSavepointCreate(Doctrine_Event $event) + { } + public function postConnect(Doctrine_Event $event) { } public function preConnect(Doctrine_Event $event) diff --git a/lib/Doctrine/Transaction.php b/lib/Doctrine/Transaction.php index a6f32ac57..568f54600 100644 --- a/lib/Doctrine/Transaction.php +++ b/lib/Doctrine/Transaction.php @@ -213,26 +213,37 @@ class Doctrine_Transaction extends Doctrine_Connection_Module public function beginTransaction($savepoint = null) { $this->conn->connect(); - + + $listener = $this->conn->getAttribute(Doctrine::ATTR_LISTENER); + if ( ! is_null($savepoint)) { $this->beginTransaction(); $this->savePoints[] = $savepoint; - $this->createSavePoint($savepoint); + $event = new Doctrine_Event($this, Doctrine_Event::SAVEPOINT_CREATE); + + $listener->preSavepointCreate($event); + + if ( ! $event->skipOperation) { + $this->createSavePoint($savepoint); + } + + $listener->postSavepointCreate($event); } else { if ($this->transactionLevel == 0) { $event = new Doctrine_Event($this, Doctrine_Event::TX_BEGIN); - $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->preTransactionBegin($event); + $listener->preTransactionBegin($event); - try { - $this->conn->getDbh()->beginTransaction(); - } catch(Exception $e) { - throw new Doctrine_Transaction_Exception($e->getMessage()); + if ( ! $event->skipOperation) { + try { + $this->conn->getDbh()->beginTransaction(); + } catch(Exception $e) { + throw new Doctrine_Transaction_Exception($e->getMessage()); + } } - - $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->postTransactionBegin($event); + $listener->postTransactionBegin($event); } } @@ -261,15 +272,25 @@ class Doctrine_Transaction extends Doctrine_Connection_Module return false; } + $listener = $this->conn->getAttribute(Doctrine::ATTR_LISTENER); + if ( ! is_null($savepoint)) { $this->transactionLevel = $this->removeSavePoints($savepoint); - $this->releaseSavePoint($savepoint); + $event = new Doctrine_Event($this, Doctrine_Event::SAVEPOINT_COMMIT); + + $listener->preSavepointCommit($event); + + if ( ! $event->skipOperation) { + $this->releaseSavePoint($savepoint); + } + + $listener->postSavepointCommit($event); } else { if ($this->transactionLevel == 1) { $event = new Doctrine_Event($this, Doctrine_Event::TX_COMMIT); - $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->preTransactionCommit($event); + $listener->preTransactionCommit($event); if ( ! $event->skipOperation) { try { @@ -300,7 +321,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module //$this->conn->unitOfWork->reset(); } - $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->postTransactionCommit($event); + $listener->postTransactionCommit($event); } } @@ -330,20 +351,24 @@ class Doctrine_Transaction extends Doctrine_Connection_Module return false; } + $listener = $this->conn->getAttribute(Doctrine::ATTR_LISTENER); + if ( ! is_null($savepoint)) { $this->transactionLevel = $this->removeSavePoints($savepoint); - $event = new Doctrine_Event($this, Doctrine_Event::ROLLBACK_SAVEPOINT); + $event = new Doctrine_Event($this, Doctrine_Event::SAVEPOINT_ROLLBACK); - $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->preSavepointRollback($event); - - $this->rollbackSavePoint($savepoint); + $listener->preSavepointRollback($event); - $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->postSavepointRollback($event); + if ( ! $event->skipOperation) { + $this->rollbackSavePoint($savepoint); + } + + $listener->postSavepointRollback($event); } else { $event = new Doctrine_Event($this, Doctrine_Event::TX_ROLLBACK); - $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->preTransactionRollback($event); + $listener->preTransactionRollback($event); if ( ! $event->skipOperation) { $this->deteles = array(); @@ -356,7 +381,7 @@ class Doctrine_Transaction extends Doctrine_Connection_Module } } - $this->conn->getAttribute(Doctrine::ATTR_LISTENER)->postTransactionRollback($event); + $listener->postTransactionRollback($event); } return true;