Commit 782cbe37 authored by zYne's avatar zYne

new template methods

parent e057ab7d
...@@ -141,6 +141,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -141,6 +141,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
{ {
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreSave($record);
$record->preSave();
switch ($record->state()) { switch ($record->state()) {
case Doctrine_Record::STATE_TDIRTY: case Doctrine_Record::STATE_TDIRTY:
$this->insert($record); $this->insert($record);
...@@ -155,6 +157,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -155,6 +157,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
break; break;
} }
$record->postSave();
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onSave($record);
} }
/** /**
...@@ -174,10 +178,14 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -174,10 +178,14 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record->getTable()->getListener()->onPreDelete($record); $record->getTable()->getListener()->onPreDelete($record);
$record->preDelete();
$this->deleteComposites($record); $this->deleteComposites($record);
$this->conn->transaction->addDelete($record); $this->conn->transaction->addDelete($record);
$record->postDelete();
$record->getTable()->getListener()->onDelete($record); $record->getTable()->getListener()->onDelete($record);
$record->state(Doctrine_Record::STATE_TCLEAN); $record->state(Doctrine_Record::STATE_TCLEAN);
...@@ -321,6 +329,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -321,6 +329,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
{ {
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreUpdate($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreUpdate($record);
$record->preUpdate();
$array = $record->getPrepared(); $array = $record->getPrepared();
if (empty($array)) { if (empty($array)) {
...@@ -358,6 +368,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -358,6 +368,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record->assignIdentifier(true); $record->assignIdentifier(true);
$record->postUpdate();
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onUpdate($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onUpdate($record);
return true; return true;
...@@ -373,6 +385,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -373,6 +385,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
// listen the onPreInsert event // listen the onPreInsert event
$record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreInsert($record); $record->getTable()->getAttribute(Doctrine::ATTR_LISTENER)->onPreInsert($record);
$record->preInsert();
$array = $record->getPrepared(); $array = $record->getPrepared();
if (empty($array)) { if (empty($array)) {
...@@ -411,6 +425,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module ...@@ -411,6 +425,8 @@ class Doctrine_Connection_UnitOfWork extends Doctrine_Connection_Module
$record->assignIdentifier(true); $record->assignIdentifier(true);
} }
$record->postInsert();
// listen the onInsert event // listen the onInsert event
$table->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record); $table->getAttribute(Doctrine::ATTR_LISTENER)->onInsert($record);
......
...@@ -275,21 +275,73 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -275,21 +275,73 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* validations that are neccessary. * validations that are neccessary.
*/ */
protected function validate() protected function validate()
{} { }
/** /**
* Empty tempalte method to provide concrete Record classes with the possibility * Empty template method to provide concrete Record classes with the possibility
* to hook into the validation procedure only when the record is going to be * to hook into the validation procedure only when the record is going to be
* updated. * updated.
*/ */
protected function validateOnUpdate() protected function validateOnUpdate()
{} { }
/** /**
* Empty tempalte method to provide concrete Record classes with the possibility * Empty template method to provide concrete Record classes with the possibility
* to hook into the validation procedure only when the record is going to be * to hook into the validation procedure only when the record is going to be
* inserted into the data store the first time. * inserted into the data store the first time.
*/ */
protected function validateOnInsert() protected function validateOnInsert()
{} { }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure.
*/
public function preSave()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the saving procedure.
*/
public function postSave()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the deletion procedure.
*/
public function preDelete()
{ }
/**
* Empty template method to provide concrete Record classes with the possibility
* to hook into the deletion procedure.
*/
public function postDelete()
{ }
/**
* 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()
{ }
/**
* 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()
{ }
/**
* 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()
{ }
/**
* 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()
{ }
/** /**
* getErrorStack * getErrorStack
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment