From 80de56781753f4b77167def0d40b7fd33627459e Mon Sep 17 00:00:00 2001 From: romanb Date: Sun, 3 May 2009 11:49:48 +0000 Subject: [PATCH] [2.0] Fixed issue in changeset calculation. --- lib/Doctrine/DBAL/DriverManager.php | 2 +- .../Persisters/AbstractEntityPersister.php | 27 +++++----- .../Persisters/JoinedSubclassPersister.php | 3 +- .../ORM/Persisters/SingleTablePersister.php | 49 ++++++++++++------- lib/Doctrine/ORM/UnitOfWork.php | 8 +-- .../Functional/SingleTableInheritanceTest.php | 13 ++--- 6 files changed, 58 insertions(+), 44 deletions(-) diff --git a/lib/Doctrine/DBAL/DriverManager.php b/lib/Doctrine/DBAL/DriverManager.php index 393feda49..a4326cdec 100644 --- a/lib/Doctrine/DBAL/DriverManager.php +++ b/lib/Doctrine/DBAL/DriverManager.php @@ -32,7 +32,7 @@ use Doctrine\Common\EventManager; final class DriverManager { /** - * List of supported drivers and their mappings to the driver class. + * List of supported drivers and their mappings to the driver classes. * * @var array */ diff --git a/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php b/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php index 88daea510..829ac46ef 100644 --- a/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php +++ b/lib/Doctrine/ORM/Persisters/AbstractEntityPersister.php @@ -87,7 +87,8 @@ abstract class AbstractEntityPersister * Inserts an entity. * * @param object $entity The entity to insert. - * @return mixed + * @return mixed If the entity uses a post-insert ID generator, the generated + * ID is returned, NULL otherwise. */ public function insert($entity) { @@ -118,7 +119,7 @@ abstract class AbstractEntityPersister */ public function executeInserts() { - $tableName = $this->_classMetadata->getTableName(); + //$tableName = $this->_classMetadata->getTableName(); $stmt = $this->_conn->prepare($this->_classMetadata->getInsertSql()); foreach ($this->_queuedInserts as $insertData) { $stmt->execute(array_values($insertData)); @@ -154,11 +155,21 @@ abstract class AbstractEntityPersister $this->_conn->delete($this->_classMetadata->getTableName(), $id); } + /** + * Adds an entity to delete. + * + * @param object $entity + */ public function addDelete($entity) { } + /** + * Executes all pending entity deletions. + * + * @see addDelete() + */ public function executeDeletions() { @@ -197,22 +208,12 @@ abstract class AbstractEntityPersister { return array(); } - - /** - * Gets all field mappings of the entire entity hierarchy. - * - * @return array - */ - public function getAllFieldMappingsInHierarchy() - { - return $this->_classMetadata->getFieldMappings(); - } /** * Prepares the data of an entity for an insert/update operation. * * @param object $entity - * @param array $array + * @param array $result The reference to the data array. * @param boolean $isInsert */ protected function _prepareData($entity, array &$result, $isInsert = false) diff --git a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php index b3d9345fc..382cbacf4 100644 --- a/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php +++ b/lib/Doctrine/ORM/Persisters/JoinedSubclassPersister.php @@ -16,7 +16,7 @@ * * This software consists of voluntary contributions made by many individuals * and is licensed under the LGPL. For more information, see - * . + * . */ namespace Doctrine\ORM\Persisters; @@ -30,6 +30,7 @@ namespace Doctrine\ORM\Persisters; * @version $Revision$ * @link www.doctrine-project.org * @since 2.0 + * @todo Reimplement. */ class JoinedSubclassPersister extends AbstractEntityPersister { diff --git a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php index 6376909ff..8d6e37deb 100644 --- a/lib/Doctrine/ORM/Persisters/SingleTablePersister.php +++ b/lib/Doctrine/ORM/Persisters/SingleTablePersister.php @@ -1,11 +1,38 @@ . + */ namespace Doctrine\ORM\Persisters; +/** + * Persister for entities that participate in a hierarchy mapped with the + * SINGLE_TABLE strategy. + * + * @author Roman Borschel + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version $Revision: 3406 $ + * @link www.doctrine-project.org + * @since 2.0 + */ class SingleTablePersister extends AbstractEntityPersister { - //private $_selectColumnList = array(); - public function insert($entity) { return parent::insert($entity); @@ -18,23 +45,7 @@ class SingleTablePersister extends AbstractEntityPersister // Populate the discriminator column if ($isInsert) { $discColumn = $this->_classMetadata->getDiscriminatorColumn(); - //$discMap = $this->_classMetadata->getDiscriminatorMap(); - $result[$discColumn['name']] = $this->_classMetadata->getDiscriminatorValue(); //array_search($this->_entityName, $discMap); + $result[$discColumn['name']] = $this->_classMetadata->getDiscriminatorValue(); } } - - /** - * {@inheritdoc} - */ - /*public function getAllFieldMappingsInHierarchy() - { - $fieldMappings = $this->_classMetadata->getFieldMappings(); - foreach ($this->_classMetadata->getSubclasses() as $subclassName) { - $fieldMappings = array_merge( - $fieldMappings, - $this->_em->getClassMetadata($subclassName)->getFieldMappings() - ); - } - return $fieldMappings; - }*/ } \ No newline at end of file diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 886b75497..1744dffc3 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -325,14 +325,14 @@ class UnitOfWork implements PropertyChangedListener $entitiesToProcess = $class->isChangeTrackingDeferredExplicit() ? $this->_scheduledForDirtyCheck[$className] : $entities; - if ( ! $class->isInheritanceTypeNone() && count($entitiesToProcess) > 0) { - $class = $this->_em->getClassMetadata(get_class($entitiesToProcess[key($entitiesToProcess)])); - } - foreach ($entitiesToProcess as $entity) { $oid = spl_object_hash($entity); $state = $this->getEntityState($entity); + if ( ! $class->isInheritanceTypeNone()) { + $class = $this->_em->getClassMetadata(get_class($entity)); + } + // Look for changes in the entity itself by comparing against the // original data we have. if ($state == self::STATE_MANAGED || $state == self::STATE_NEW) { diff --git a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php index 3f5ccf194..c51f7a347 100644 --- a/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php +++ b/tests/Doctrine/Tests/ORM/Functional/SingleTableInheritanceTest.php @@ -28,17 +28,18 @@ class SingleTableInheritanceTest extends \Doctrine\Tests\OrmFunctionalTestCase $this->_em->save($parent); - $relatedEntity = new RelatedEntity; - $relatedEntity->setName('theRelatedOne'); - - $this->_em->save($relatedEntity); - $child = new ChildEntity; $child->setData('thedata'); $child->setNumber(1234); - $child->setRelatedEntity($relatedEntity); + //$child->setRelatedEntity($relatedEntity); $this->_em->save($child); + + $relatedEntity = new RelatedEntity; + $relatedEntity->setName('theRelatedOne'); + $relatedEntity->setOwner($child); + + $this->_em->save($relatedEntity); $this->_em->flush(); $this->_em->clear();