diff --git a/lib/Doctrine/Connection/UnitOfWork.php b/lib/Doctrine/Connection/UnitOfWork.php index 29ad94c3e..f4ec7cc3d 100644 --- a/lib/Doctrine/Connection/UnitOfWork.php +++ b/lib/Doctrine/Connection/UnitOfWork.php @@ -140,8 +140,10 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module public function save(Doctrine_Record $record) { $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record); + + $event = new Doctrine_Event($this, Doctrine_Event::SAVE); - $record->preSave(); + $record->preSave($event); switch ($record->state()) { case Doctrine_Record::STATE_TDIRTY: @@ -157,7 +159,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module break; } - $record->postSave(); + $record->postSave($event); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record); } @@ -178,13 +180,15 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module $record->getTable()->getListener()->onPreDelete($record); - $record->preDelete(); + $event = new Doctrine_Event($this, Doctrine_Event::DELETE); + + $record->preDelete($event); $this->deleteComposites($record); $this->conn->transaction->addDelete($record); - $record->postDelete(); + $record->postDelete($event); $record->getTable()->getListener()->onDelete($record); @@ -329,7 +333,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module { $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreUpdate($record); - $record->preUpdate(); + $event = new Doctrine_Event($this, Doctrine_Event::UPDATE); + + $record->preUpdate($event); $array = $record->getPrepared(); @@ -368,7 +374,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module $record->assignIdentifier(true); - $record->postUpdate(); + $record->postUpdate($event); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onUpdate($record); @@ -385,7 +391,9 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module // listen the onPreInsert event $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreInsert($record); - $record->preInsert(); + $event = new Doctrine_Event($this, Doctrine_Event::INSERT); + + $record->preInsert($event); $array = $record->getPrepared(); @@ -425,7 +433,7 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module $record->assignIdentifier(true); } - $record->postInsert(); + $record->postInsert($event); // listen the onInsert event $table->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record); diff --git a/lib/Doctrine/Event.php b/lib/Doctrine/Event.php index 7443c0992..09c4f2f1f 100644 --- a/lib/Doctrine/Event.php +++ b/lib/Doctrine/Event.php @@ -44,8 +44,13 @@ class Doctrine_Event const CONNECT = 8; const FETCH = 9; const FETCHALL = 10; + + const DELETE = 11; + const SAVE = 12; + const UPDATE = 13; + const INSERT = 14; /** - * @var Doctrine_Db $invoker the handler which invoked this event + * @var mixed $invoker the handler which invoked this event */ protected $invoker; /** @@ -57,7 +62,7 @@ class Doctrine_Event */ protected $params; /** - * @see Doctrine_Db_Event constants + * @see Doctrine_Event constants * @var integer $code the event code */ protected $code; @@ -81,7 +86,7 @@ class Doctrine_Event $this->invoker = $invoker; $this->code = $code; $this->query = $query; - $this->params = $params; + $this->params = $params; } /** * getQuery diff --git a/lib/Doctrine/Record.php b/lib/Doctrine/Record.php index cfe265dba..acbf3180e 100644 --- a/lib/Doctrine/Record.php +++ b/lib/Doctrine/Record.php @@ -294,53 +294,53 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite * Empty template method to provide concrete Record classes with the possibility * to hook into the saving procedure. */ - public function preSave() + public function preSave($event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the saving procedure. */ - public function postSave() + public function postSave($event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the deletion procedure. */ - public function preDelete() + public function preDelete($event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the deletion procedure. */ - public function postDelete() + public function postDelete($event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the saving procedure only when the record is going to be * updated. */ - public function preUpdate() + public function preUpdate($event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the saving procedure only when the record is going to be * updated. */ - public function postUpdate() + public function postUpdate($event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the saving procedure only when the record is going to be * inserted into the data store the first time. */ - public function preInsert() + public function preInsert($event) { } /** * Empty template method to provide concrete Record classes with the possibility * to hook into the saving procedure only when the record is going to be * inserted into the data store the first time. */ - public function postInsert() + public function postInsert($event) { } /** * getErrorStack