[+BUGFIX] Extbase (Persistence): Fixed a problem where the cache was cleared at every...
authorJochen Rau <j.rau@web.de>
Mon, 9 Nov 2009 11:46:20 +0000 (11:46 +0000)
committerJochen Rau <j.rau@web.de>
Mon, 9 Nov 2009 11:46:20 +0000 (11:46 +0000)
[+TASK] Extbase (Persistence): The uid of a ValueObject is cleared now if it gets cloned.
[!!!][-TASK] Extbase (Persistence): Removed buggy implementation of comma separated lists. Will be reimplemented later again.

typo3/sysext/extbase/Classes/DomainObject/AbstractDomainObject.php
typo3/sysext/extbase/Classes/DomainObject/AbstractEntity.php
typo3/sysext/extbase/Classes/DomainObject/AbstractValueObject.php
typo3/sysext/extbase/Classes/Persistence/Backend.php
typo3/sysext/extbase/Classes/Persistence/Manager.php
typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php
typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php

index 3f04032..deee8d3 100644 (file)
@@ -151,7 +151,7 @@ abstract class Tx_Extbase_DomainObject_AbstractDomainObject implements Tx_Extbas
         *
         * @return boolean
         */
-       public function _isDirty() {
+       public function _isDirty($propertyName = NULL) {
                return FALSE;
        }
 
index 66748b9..621cde6 100644 (file)
@@ -112,6 +112,7 @@ abstract class Tx_Extbase_DomainObject_AbstractEntity extends Tx_Extbase_DomainO
        /**
         * Returns TRUE if the properties were modified after reconstitution
         *
+        * @param string $propertyName An optional name of a property to be checked if its value is dirty
         * @return boolean
         */
        public function _isDirty($propertyName = NULL) {
index 983dcc7..361cf9d 100644 (file)
@@ -40,6 +40,16 @@ abstract class Tx_Extbase_DomainObject_AbstractValueObject extends Tx_Extbase_Do
        public function getValue() {
                return $this->__toString();
        }
+       
+       /**
+        * Clone method. Sets the _isClone property.
+        *
+        * @return void
+        */
+       public function __clone() {
+               $this->isClone = TRUE;
+               $this->uid = NULL;
+       }
 
 }
 ?>
\ No newline at end of file
index d8b9de9..dec11f9 100644 (file)
@@ -351,15 +351,15 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
                        if (($propertyValue instanceof Tx_Extbase_Persistence_LazyLoadingProxy) || ((get_class($propertyValue) === 'Tx_Extbase_Persistence_LazyObjectStorage') && ($propertyValue->isInitialized() === FALSE))) {
                                continue;
                        }
-
+                       
                        $columnMap = $dataMap->getColumnMap($propertyName);
                        $propertyMetaData = $classSchema->getProperty($propertyName);
                        $propertyType = $propertyMetaData['type'];
                        // FIXME enable property-type check
                        // $this->checkPropertyType($propertyType, $propertyValue);
-                       if (($propertyValue !== NULL) && ($propertyType === 'Tx_Extbase_Persistence_ObjectStorage')) {
-                               if ($object->_isDirty($propertyName)) {
-                                       $row[$columnMap->getColumnName()] = $this->persistObjectStorage($propertyValue, $object, $propertyName, $queue);
+                       if (($propertyValue !== NULL) && $propertyType === 'Tx_Extbase_Persistence_ObjectStorage') {
+                               if ($object->_isNew() || $object->_isDirty($propertyName)) {
+                                       $this->persistObjectStorage($propertyValue, $object, $propertyName, $queue, $row);
                                } else {
                                        foreach ($propertyValue as $containedObject) {
                                                $queue[] = $containedObject;
@@ -377,7 +377,7 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
                                        }
                                        $row[$columnMap->getColumnName()] = $dataMap->convertPropertyValueToFieldValue($propertyValue);
                                }
-                       } elseif ($object instanceof Tx_Extbase_DomainObject_AbstractValueObject || $object->_isNew() || $object->_isDirty($propertyName)) {
+                       } elseif ($object instanceof Tx_Extbase_DomainObject_AbstractValueObject || ($object->_isNew() || $object->_isDirty($propertyName))) {
                                $row[$columnMap->getColumnName()] = $dataMap->convertPropertyValueToFieldValue($propertyValue);
                        }
                }
@@ -431,7 +431,7 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
                        if($this->dataMapper->getDataMap(get_class($parentObject))->getColumnMap($parentPropertyName)->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_AND_BELONGS_TO_MANY) {
                                $this->insertRelationInRelationtable($object, $parentObject, $parentPropertyName, $sortingPosition);
                        }
-               } else {
+               } elseif ($object->_isNew()) {
                        $row = array();
                        $className = get_class($object);
                        $dataMap = $this->dataMapper->getDataMap($className);
@@ -474,21 +474,22 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
         * @param mixed $propertyValue The property value 
         * @return void
         */
-       protected function persistObjectStorage(Tx_Extbase_Persistence_ObjectStorage $objectStorage, Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, &$queue) {
+       protected function persistObjectStorage(Tx_Extbase_Persistence_ObjectStorage $objectStorage, Tx_Extbase_DomainObject_DomainObjectInterface $parentObject, $propertyName, array &$queue, array &$row) {
                $className = get_class($parentObject);
                $columnMap = $this->dataMapper->getDataMap($className)->getColumnMap($propertyName);
                $columnName = $columnMap->getColumnName();              
                $propertyMetaData = $this->reflectionService->getClassSchema($className)->getProperty($propertyName);
-               
+
+               $updateParent = FALSE;          
                foreach ($this->getRemovedChildObjects($parentObject, $propertyName) as $removedObject) {
                        if ($columnMap->getTypeOfRelation() === Tx_Extbase_Persistence_Mapper_ColumnMap::RELATION_HAS_MANY && $propertyMetaData['cascade'] === 'remove') {
                                $this->removeObject($removedObject);
                        } else {
                                $this->detachObjectFromParentObject($removedObject, $parentObject, $propertyName);
                        }
+                       $updateParent = TRUE;
                }
-
-               $childPidArray = array();
+               
                $sortingPosition = 1;
                foreach ($objectStorage as $object) {
                        if ($object->_isNew()) {
@@ -498,18 +499,14 @@ class Tx_Extbase_Persistence_Backend implements Tx_Extbase_Persistence_BackendIn
                                } else {
                                        $this->persistValueObject($object, $parentObject, $propertyName, $sortingPosition);
                                }
+                               $updateParent = TRUE;
                        }
-                       $childPidArray[] = $object->getUid(); // FIXME This won't work for partly loaded storages
                        $sortingPosition++;
                }
                
-               if ($columnMap->getParentKeyFieldName() === NULL) {
-                       $newParentPropertyValue = implode(',', $childPidArray);
-               } else {
-                       $newParentPropertyValue = count($objectStorage); // TODO check for limited queries
+               if ($updateParent === TRUE && $columnMap->getParentKeyFieldName() !== NULL) {
+                       $row[$columnMap->getColumnName()] = $this->dataMapper->countRelated($parentObject, $propertyName);                      
                }
-               
-               return $newParentPropertyValue;
        }
        
        /**
index fbf4b51..4ac8fd4 100644 (file)
@@ -62,7 +62,6 @@ class Tx_Extbase_Persistence_Manager implements Tx_Extbase_Persistence_ManagerIn
         *
         * @param Tx_Extbase_Persistence_BackendInterface $backend The persistence backend
         * @return void
-
         */
        public function injectBackend(Tx_Extbase_Persistence_BackendInterface $backend) {
                $this->backend = $backend;
@@ -74,7 +73,6 @@ class Tx_Extbase_Persistence_Manager implements Tx_Extbase_Persistence_ManagerIn
         *
         * @param Tx_Extbase_Persistence_Session $session The persistence session
         * @return void
-
         */
        public function injectSession(Tx_Extbase_Persistence_Session $session) {
                $this->session = $session;
@@ -94,7 +92,6 @@ class Tx_Extbase_Persistence_Manager implements Tx_Extbase_Persistence_ManagerIn
         * Returns the current persistence session
         *
         * @return Tx_Extbase_Persistence_Session
-
         */
        public function getSession() {
                return $this->session;
@@ -147,7 +144,11 @@ class Tx_Extbase_Persistence_Manager implements Tx_Extbase_Persistence_ManagerIn
                        $removedObjects->addAll($repository->getRemovedObjects());
                }
 
-               $aggregateRootObjects->addAll($this->session->getReconstitutedObjects());
+               foreach ($this->session->getReconstitutedObjects() as $reconstitutedObject) {
+                       if (class_exists(str_replace('_Model_', '_Repository_', get_class($reconstitutedObject)) . 'Repository')) {
+                               $aggregateRootObjects->attach($reconstitutedObject);
+                       }
+               }
 
                        // hand in only aggregate roots, leaving handling of subobjects to
                        // the underlying storage layer
index e1e2d6d..bb6cb30 100644 (file)
@@ -219,7 +219,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
         * @param Tx_Extbase_Persistence_Mapper_DataMap $dataMap The corresponding Data Map of the property
         * @return mixed The result
         */
-       public function fetchRelated(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue, $enableLazyLoading = TRUE) {
+       public function fetchRelated(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '', $enableLazyLoading = TRUE) {
                $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName);
                $propertyMetaData = $this->reflectionService->getClassSchema(get_class($parentObject))->getProperty($propertyName);
                if ($enableLazyLoading === TRUE && ($propertyMetaData['lazy'] || ($columnMap->getLoadingStrategy() !== Tx_Extbase_Persistence_Mapper_ColumnMap::STRATEGY_EAGER))) {
@@ -242,7 +242,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
         * @param mixed $fieldValue The raw field value.
         * @return void
         */
-       protected function fetchRelatedEager(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue) {
+       protected function fetchRelatedEager(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '') {
                $query = $this->getPreparedQuery($parentObject, $propertyName, $fieldValue);
                return $query->execute();
        }
@@ -255,7 +255,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
         * @param string $fieldValue 
         * @return void
         */
-       protected function getPreparedQuery(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue) {
+       protected function getPreparedQuery(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '') {
                $columnMap = $this->getDataMap(get_class($parentObject))->getColumnMap($propertyName);
                $queryFactory = t3lib_div::makeInstance('Tx_Extbase_Persistence_QueryFactory');
                $query = $queryFactory->create($columnMap->getChildClassName());
@@ -341,7 +341,7 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
         * @param string $propertyName The name of the proxied property in it's parent
         * @param mixed $fieldValue The raw field value.
         */
-       public function countRelated(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue) {
+       public function countRelated(Tx_Extbase_DomainObject_AbstractEntity $parentObject, $propertyName, $fieldValue = '') {
                $query = $this->getPreparedQuery($parentObject, $propertyName, $fieldValue);
                return $query->count();
        }
@@ -434,4 +434,4 @@ class Tx_Extbase_Persistence_Mapper_DataMapper implements t3lib_Singleton {
        }
 
 }
-?>
+?>
\ No newline at end of file
index 8a682e8..4a0178f 100644 (file)
@@ -114,7 +114,7 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
 
                $sqlString = 'INSERT INTO ' . $tableName . ' (' . implode(', ', $fields) . ') VALUES (' . implode(', ', $values) . ')';
                $this->replacePlaceholders($sqlString, $parameters);
-               // debug($sqlString,2);
+               // debug($sqlString,-2);
                $this->databaseHandle->sql_query($sqlString);
                $this->checkSqlErrors();
                $uid = $this->databaseHandle->sql_insert_id();
@@ -146,7 +146,7 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
 
                $sqlString = 'UPDATE ' . $tableName . ' SET ' . implode(', ', $fields) . ' WHERE uid=?';
                $this->replacePlaceholders($sqlString, $parameters);
-               // debug($sqlString,2);
+               // debug($sqlString,-2);
                $returnValue = $this->databaseHandle->sql_query($sqlString);
                $this->checkSqlErrors();
                if (!$isRelation) {
@@ -334,7 +334,7 @@ class Tx_Extbase_Persistence_Storage_Typo3DbBackend implements Tx_Extbase_Persis
 
                $tableName = $dataMap->getTableName();
                $this->addEnableFieldsStatement($tableName, $sql);
-
+               
                $statement = 'SELECT * FROM ' . $tableName;
                $statement .= ' WHERE ' . implode(' AND ', $fields);
                if (!empty($sql['additionalWhereClause'])) {