From 8e96916db115088b04fffff612e9d623dd315217 Mon Sep 17 00:00:00 2001 From: Jochen Rau Date: Mon, 9 Nov 2009 11:46:20 +0000 Subject: [PATCH] [+BUGFIX] Extbase (Persistence): Fixed a problem where the cache was cleared at every hit. [+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. --- .../DomainObject/AbstractDomainObject.php | 2 +- .../Classes/DomainObject/AbstractEntity.php | 1 + .../DomainObject/AbstractValueObject.php | 10 ++++++ .../extbase/Classes/Persistence/Backend.php | 31 +++++++++---------- .../extbase/Classes/Persistence/Manager.php | 9 +++--- .../Classes/Persistence/Mapper/DataMapper.php | 10 +++--- .../Persistence/Storage/Typo3DbBackend.php | 6 ++-- 7 files changed, 39 insertions(+), 30 deletions(-) diff --git a/typo3/sysext/extbase/Classes/DomainObject/AbstractDomainObject.php b/typo3/sysext/extbase/Classes/DomainObject/AbstractDomainObject.php index 3f04032b3232..deee8d365325 100644 --- a/typo3/sysext/extbase/Classes/DomainObject/AbstractDomainObject.php +++ b/typo3/sysext/extbase/Classes/DomainObject/AbstractDomainObject.php @@ -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; } diff --git a/typo3/sysext/extbase/Classes/DomainObject/AbstractEntity.php b/typo3/sysext/extbase/Classes/DomainObject/AbstractEntity.php index 66748b9da6d8..621cde675e68 100644 --- a/typo3/sysext/extbase/Classes/DomainObject/AbstractEntity.php +++ b/typo3/sysext/extbase/Classes/DomainObject/AbstractEntity.php @@ -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) { diff --git a/typo3/sysext/extbase/Classes/DomainObject/AbstractValueObject.php b/typo3/sysext/extbase/Classes/DomainObject/AbstractValueObject.php index 983dcc7e2f4f..361cf9da69e1 100644 --- a/typo3/sysext/extbase/Classes/DomainObject/AbstractValueObject.php +++ b/typo3/sysext/extbase/Classes/DomainObject/AbstractValueObject.php @@ -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 diff --git a/typo3/sysext/extbase/Classes/Persistence/Backend.php b/typo3/sysext/extbase/Classes/Persistence/Backend.php index d8b9de98b00e..dec11f963def 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Backend.php +++ b/typo3/sysext/extbase/Classes/Persistence/Backend.php @@ -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; } /** diff --git a/typo3/sysext/extbase/Classes/Persistence/Manager.php b/typo3/sysext/extbase/Classes/Persistence/Manager.php index fbf4b514128c..4ac8fd42009d 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Manager.php +++ b/typo3/sysext/extbase/Classes/Persistence/Manager.php @@ -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 diff --git a/typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php b/typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php index e1e2d6d598e5..bb6cb30ae476 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php +++ b/typo3/sysext/extbase/Classes/Persistence/Mapper/DataMapper.php @@ -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 diff --git a/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php b/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php index 8a682e8a8938..4a0178f23829 100644 --- a/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php +++ b/typo3/sysext/extbase/Classes/Persistence/Storage/Typo3DbBackend.php @@ -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'])) { -- 2.20.1