From b6e385d2439220a76e5fb8c5b4958ea9992ad632 Mon Sep 17 00:00:00 2001 From: romanb Date: Thu, 8 Jan 2009 11:23:24 +0000 Subject: [PATCH] fixed regression --- .../DBAL/Platforms/SqlitePlatform.php | 4 +- lib/Doctrine/DBAL/Types/Type.php | 7 +++- lib/Doctrine/ORM/Export/ClassExporter.php | 1 + .../Internal/Hydration/StandardHydrator.php | 37 +++++-------------- lib/Doctrine/ORM/Mapping/ClassMetadata.php | 4 +- lib/Doctrine/ORM/UnitOfWork.php | 22 ++++++----- tests/Orm/Functional/BasicCRUDTest.php | 12 +++++- .../Orm/Mapping/ClassMetadataFactoryTest.php | 4 +- tests/models/cms/CmsUser.php | 2 +- 9 files changed, 47 insertions(+), 46 deletions(-) diff --git a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php index afb26aae8..5a84449c4 100644 --- a/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php +++ b/lib/Doctrine/DBAL/Platforms/SqlitePlatform.php @@ -501,9 +501,9 @@ class Doctrine_DBAL_Platforms_SqlitePlatform extends Doctrine_DBAL_Platforms_Abs } } - if ( ! $autoinc && isset($options['primary']) && ! empty($options['primary'])) { + if (isset($options['primary']) && ! empty($options['primary'])) { $keyColumns = array_values($options['primary']); - $keyColumns = array_map(array($this->_conn, 'quoteIdentifier'), $keyColumns); + $keyColumns = array_map(array($this, 'quoteIdentifier'), $keyColumns); $queryFields.= ', PRIMARY KEY('.implode(', ', $keyColumns).')'; } diff --git a/lib/Doctrine/DBAL/Types/Type.php b/lib/Doctrine/DBAL/Types/Type.php index feca7721f..3ea00712e 100644 --- a/lib/Doctrine/DBAL/Types/Type.php +++ b/lib/Doctrine/DBAL/Types/Type.php @@ -48,9 +48,14 @@ abstract class Doctrine_DBAL_Types_Type */ public static function getType($name) { + if (is_object($name)) { + try { throw new Exception(); } + catch (Exception $e) { echo $e->getTraceAsString(); } + die(); + } if ( ! isset(self::$_typeObjects[$name])) { if ( ! isset(self::$_typesMap[$name])) { - throw Doctrine_Exception::unknownType($name); + throw new Doctrine_Exception("Unknown type: $name"); } self::$_typeObjects[$name] = new self::$_typesMap[$name](); } diff --git a/lib/Doctrine/ORM/Export/ClassExporter.php b/lib/Doctrine/ORM/Export/ClassExporter.php index e36d55c56..32d87286f 100644 --- a/lib/Doctrine/ORM/Export/ClassExporter.php +++ b/lib/Doctrine/ORM/Export/ClassExporter.php @@ -71,6 +71,7 @@ class Doctrine_ORM_Export_ClassExporter $column['length'] = $mapping['length']; if ($class->isIdentifier($fieldName)) { + $column['primary'] = true; if ($class->isIdGeneratorIdentity()) { $column['autoincrement'] = true; } diff --git a/lib/Doctrine/ORM/Internal/Hydration/StandardHydrator.php b/lib/Doctrine/ORM/Internal/Hydration/StandardHydrator.php index e6de9a9d3..67cdb6146 100644 --- a/lib/Doctrine/ORM/Internal/Hydration/StandardHydrator.php +++ b/lib/Doctrine/ORM/Internal/Hydration/StandardHydrator.php @@ -327,6 +327,8 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte } else { $fieldName = $this->_lookupFieldName($classMetadata, $columnName); $cache[$key]['isScalar'] = false; + // cache type information + $cache[$key]['type'] = $classMetadata->getTypeOfColumn($columnName); } $cache[$key]['fieldName'] = $fieldName; @@ -337,15 +339,6 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte } else { $cache[$key]['isIdentifier'] = false; } - - // cache type information - $type = $classMetadata->getTypeOfColumn($columnName); - if ($type == 'integer' || $type == 'string') { - $cache[$key]['isSimpleType'] = true; - } else { - $cache[$key]['type'] = $type; - $cache[$key]['isSimpleType'] = false; - } } $class = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; @@ -361,13 +354,11 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte $id[$dqlAlias] .= '|' . $value; } - if ($cache[$key]['isSimpleType']) { + if ($cache[$key]['isScalar']) { $rowData[$dqlAlias][$fieldName] = $value; } else { - $rowData[$dqlAlias][$fieldName] = $this->prepareValue( - $class, $fieldName, $value, $cache[$key]['type']); + $rowData[$dqlAlias][$fieldName] = $cache[$key]['type']->convertToPHPValue($value); } - //$rowData[$dqlAlias][$fieldName] = $cache[$key]['type']->convertToObjectValue($value); if ( ! isset($nonemptyComponents[$dqlAlias]) && $value !== null) { $nonemptyComponents[$dqlAlias] = true; @@ -412,31 +403,21 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte } else { $fieldName = $this->_lookupFieldName($classMetadata, $columnName); $cache[$key]['isScalar'] = false; + // cache type information + $cache[$key]['type'] = $classMetadata->getTypeOfColumn($columnName); } - $cache[$key]['fieldName'] = $fieldName; - - // cache type information - $type = $classMetadata->getTypeOfColumn($columnName); - if ($type == 'integer' || $type == 'string') { - $cache[$key]['isSimpleType'] = true; - } else { - $cache[$key]['type'] = $type; - $cache[$key]['isSimpleType'] = false; - } } $class = $this->_queryComponents[$cache[$key]['dqlAlias']]['metadata']; $dqlAlias = $cache[$key]['dqlAlias']; $fieldName = $cache[$key]['fieldName']; - if ($cache[$key]['isSimpleType'] || $cache[$key]['isScalar']) { + if ($cache[$key]['isScalar']) { $rowData[$dqlAlias . '_' . $fieldName] = $value; } else { - $rowData[$dqlAlias . '_' . $fieldName] = $this->prepareValue( - $class, $fieldName, $value, $cache[$key]['type']); + $rowData[$dqlAlias . '_' . $fieldName] = $cache[$key]['type']->convertToPHPValue($value); } - //$rowData[$dqlAlias . '_' . $fieldName] = $cache[$key]['type']->convertToObjectValue($value); } return $rowData; @@ -526,7 +507,7 @@ class Doctrine_ORM_Internal_Hydration_StandardHydrator extends Doctrine_ORM_Inte * @return mixed prepared value * @todo Remove. Should be handled by the Type classes. No need for this switch stuff. */ - public function prepareValue(Doctrine_ClassMetadata $class, $fieldName, $value, $typeHint = null) + public function prepareValue(Doctrine_ORM_Mapping_ClassMetadata $class, $fieldName, $value, $typeHint = null) { if ($value === $this->_nullObject) { return $this->_nullObject; diff --git a/lib/Doctrine/ORM/Mapping/ClassMetadata.php b/lib/Doctrine/ORM/Mapping/ClassMetadata.php index 719324910..a42efdd69 100644 --- a/lib/Doctrine/ORM/Mapping/ClassMetadata.php +++ b/lib/Doctrine/ORM/Mapping/ClassMetadata.php @@ -617,7 +617,9 @@ class Doctrine_ORM_Mapping_ClassMetadata throw Doctrine_ORM_Exceptions_MappingException::missingType(); } - $mapping['type'] = Doctrine_DBAL_Types_Type::getType($mapping['type']); + if ( ! is_object($mapping['type'])) { + $mapping['type'] = Doctrine_DBAL_Types_Type::getType($mapping['type']); + } // Complete fieldName and columnName mapping if ( ! isset($mapping['columnName'])) { diff --git a/lib/Doctrine/ORM/UnitOfWork.php b/lib/Doctrine/ORM/UnitOfWork.php index 6b6be76bd..7e81d2d10 100644 --- a/lib/Doctrine/ORM/UnitOfWork.php +++ b/lib/Doctrine/ORM/UnitOfWork.php @@ -257,13 +257,12 @@ class Doctrine_ORM_UnitOfWork /** * Computes all the changes that have been done to entities in the identity map - * and stores these changes in _dataChangeSet temporarily for access by the - * peristers, until the UoW commit is finished. + * since the last commit and stores these changes in _dataChangeSet temporarily + * for access by the persisters, until the UoW commit is finished. * * @param array $entities The entities for which to compute the changesets. If this * parameter is not specified, the changesets of all entities in the identity * map are computed. - * @return void */ public function computeDataChangeSet(array $entities = null) { @@ -297,6 +296,7 @@ class Doctrine_ORM_UnitOfWork if ($state == self::STATE_NEW) { $this->_dataChangeSets[$oid] = $actualData; + $this->_originalEntityData[$oid] = $actualData; } else { $originalData = $this->_originalEntityData[$oid]; $changeSet = array(); @@ -308,13 +308,13 @@ class Doctrine_ORM_UnitOfWork $changeSet[$propName] = array($orgValue => $actualValue); } } - $this->_dirtyEntities[$oid] = $entity; - $this->_dataChangeSets[$oid] = $changeSet; + if ($changeSet) { + $this->_dirtyEntities[$oid] = $entity; + $this->_dataChangeSets[$oid] = $changeSet; + $this->_originalEntityData[$oid] = $actualData; + } } } - if (isset($this->_dirtyEntities[$oid])) { - $this->_originalEntityData[$oid] = $actualData; - } } } } @@ -337,10 +337,11 @@ class Doctrine_ORM_UnitOfWork $returnVal = $persister->insert($entity); if ( ! is_null($returnVal)) { $oid = spl_object_hash($entity); - $class->getReflectionProperty($class->getSingleIdentifierFieldName()) - ->setValue($entity, $returnVal); + $idField = $class->getSingleIdentifierFieldName(); + $class->getReflectionProperty($idField)->setValue($entity, $returnVal); $this->_entityIdentifiers[$oid] = array($returnVal); $this->_entityStates[$oid] = self::STATE_MANAGED; + $this->_originalEntityData[$oid][$idField] = $returnVal; $this->addToIdentityMap($entity); } } @@ -354,6 +355,7 @@ class Doctrine_ORM_UnitOfWork */ private function _executeUpdates($class) { + try { throw new Exception(); } catch (Exception $e) { echo $e->getTraceAsString(); } $className = $class->getClassName(); $persister = $this->_em->getEntityPersister($className); foreach ($this->_dirtyEntities as $entity) { diff --git a/tests/Orm/Functional/BasicCRUDTest.php b/tests/Orm/Functional/BasicCRUDTest.php index cad1cf0bf..8267c4e15 100644 --- a/tests/Orm/Functional/BasicCRUDTest.php +++ b/tests/Orm/Functional/BasicCRUDTest.php @@ -12,7 +12,10 @@ class Orm_Functional_BasicCRUDTest extends Doctrine_OrmFunctionalTestCase { $em = $this->_getEntityManager(); $exporter = new Doctrine_ORM_Export_ClassExporter($em); - $exporter->exportClasses(array($em->getClassMetadata('CmsUser'))); + $exporter->exportClasses(array( + $em->getClassMetadata('CmsUser'), + $em->getClassMetadata('CmsPhonenumber') + )); // Create $user = new CmsUser; @@ -33,6 +36,13 @@ class Orm_Functional_BasicCRUDTest extends Doctrine_OrmFunctionalTestCase { $user4 = $em->find('CmsUser', $user2->id); $this->assertTrue($user2 === $user4); + + $ph = new CmsPhonenumber; + $ph->phonenumber = "12345"; + + $user->phonenumbers[] = $ph; + + //var_dump($em->getUnitOfWork()) } } diff --git a/tests/Orm/Mapping/ClassMetadataFactoryTest.php b/tests/Orm/Mapping/ClassMetadataFactoryTest.php index b969cfad9..6e7f24578 100644 --- a/tests/Orm/Mapping/ClassMetadataFactoryTest.php +++ b/tests/Orm/Mapping/ClassMetadataFactoryTest.php @@ -21,7 +21,7 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase { // Self-made metadata $cm1 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity1'); // Add a mapped field - $cm1->mapField(array('fieldName' => 'name', 'type' => 'string')); + $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar')); // and a mapped association $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this')); // and an id generator type @@ -56,7 +56,7 @@ class Orm_Mapping_ClassMetadataFactoryTest extends Doctrine_OrmTestCase { $cm1 = new Doctrine_ORM_Mapping_ClassMetadata('CMFTest_Entity1'); $cm1->setInheritanceType('singleTable'); // Add a mapped field - $cm1->mapField(array('fieldName' => 'name', 'type' => 'string')); + $cm1->mapField(array('fieldName' => 'name', 'type' => 'varchar')); // and a mapped association $cm1->mapOneToOne(array('fieldName' => 'other', 'targetEntity' => 'Other', 'mappedBy' => 'this')); // and an id generator type diff --git a/tests/models/cms/CmsUser.php b/tests/models/cms/CmsUser.php index 65665a400..052653f8a 100644 --- a/tests/models/cms/CmsUser.php +++ b/tests/models/cms/CmsUser.php @@ -26,7 +26,7 @@ class CmsUser */ public $name; /** - * @DoctrineOneToMany(targetEntity="CmsPhonenumber", mappedBy="user") + * @DoctrineOneToMany(targetEntity="CmsPhonenumber", mappedBy="user", cascade={"save"}) */ public $phonenumbers; /**