From 419daa8114d755939ce3328ca1e05e5898ada4e1 Mon Sep 17 00:00:00 2001 From: zYne Date: Wed, 20 Sep 2006 11:29:35 +0000 Subject: [PATCH] Small refactorings --- Doctrine/Connection.php | 44 ++++++++++++++---------------- Doctrine/Connection/UnitOfWork.php | 2 +- 2 files changed, 21 insertions(+), 25 deletions(-) diff --git a/Doctrine/Connection.php b/Doctrine/Connection.php index 08f482b82..9d15ee2b5 100644 --- a/Doctrine/Connection.php +++ b/Doctrine/Connection.php @@ -204,6 +204,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun return count($this->tables); } /** + * addTable + * adds a Doctrine_Table object into connection registry + * * @param $objTable a Doctrine_Table object to be added into registry * @return boolean */ @@ -217,6 +220,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun return true; } /** + * create * creates a record * * create creates a record @@ -240,7 +244,7 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } /** * saveAll - * saves all the records from all tables + * persists all the records from all tables * * @return void */ @@ -274,6 +278,9 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun } } /** + * evictTables + * evicts all tables + * * @return void */ public function evictTables() { @@ -424,16 +431,10 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun $foreign = $fk->getForeign(); if($record->getTable()->hasPrimaryKey($fk->getLocal())) { - switch($record->getState()): - case Doctrine_Record::STATE_TDIRTY: - case Doctrine_Record::STATE_TCLEAN: - $saveLater[$k] = $fk; - break; - case Doctrine_Record::STATE_CLEAN: - case Doctrine_Record::STATE_DIRTY: - $v->save(); - break; - endswitch; + if( ! $record->exists()) + $saveLater[$k] = $fk; + else + $v->save(); } else { // ONE-TO-ONE relationship $obj = $record->get($fk->getTable()->getComponentName()); @@ -552,21 +553,16 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun * @return boolean true on success, false on failure */ final public function delete(Doctrine_Record $record) { - switch($record->getState()): - case Doctrine_Record::STATE_PROXY: - case Doctrine_Record::STATE_CLEAN: - case Doctrine_Record::STATE_DIRTY: - $this->beginTransaction(); + if( ! $record->exists()) + return false; + + $this->beginTransaction(); - $this->deleteComposites($record); - $this->transaction->addDelete($record); + $this->deleteComposites($record); + $this->transaction->addDelete($record); - $this->commit(); - return true; - break; - default: - return false; - endswitch; + $this->commit(); + return true; } /** * returns a string representation of this object diff --git a/Doctrine/Connection/UnitOfWork.php b/Doctrine/Connection/UnitOfWork.php index 27572c930..85ce43e7e 100644 --- a/Doctrine/Connection/UnitOfWork.php +++ b/Doctrine/Connection/UnitOfWork.php @@ -20,7 +20,7 @@ */ /** - * Doctrine_Transaction + * Doctrine_Connection_UnitOfWork * * @package Doctrine ORM * @url www.phpdoctrine.com