[BUGFIX] Persist an empty unmodified objectstorage
authorMarc Bastian Heinrichs <typo3@mbh-software.de>
Sun, 14 Apr 2013 10:14:08 +0000 (12:14 +0200)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Sat, 27 Apr 2013 11:41:12 +0000 (13:41 +0200)
If the propertymapper builds an empty objectstorage for a property or
a property is set to a new objectstorage and the objectstorage property
has childobjects before, this objectstore needs to be persisted.

Change-Id: Ibcbd7cd6e1677e5321f0891e58f60bb5a49d529d
Releases: 6.1, 6.0, 4.7
Fixes: #13621
Fixes: #44110
Fixes: #42732
Reviewed-on: https://review.typo3.org/20215
Reviewed-by: Anja Leichsenring
Tested-by: Anja Leichsenring
typo3/sysext/extbase/Classes/Persistence/Generic/Backend.php

index fd55c12..7013f66 100644 (file)
@@ -393,7 +393,11 @@ class Backend implements \TYPO3\CMS\Extbase\Persistence\Generic\BackendInterface
                        }
                        $columnMap = $dataMap->getColumnMap($propertyName);
                        if ($propertyValue instanceof \TYPO3\CMS\Extbase\Persistence\ObjectStorage) {
-                               if ($object->_isNew() || $propertyValue->_isDirty()) {
+                               $cleanProperty = $object->_getCleanProperty($propertyName);
+                               // objectstorage needs to be persisted if the object is new, the objectstorge is dirty, meaning it has
+                               // been changed after initial build, or a empty objectstorge is present and the cleanstate objectstorage
+                               // has childelements, meaning all elements should been removed from the objectstorage
+                               if ($object->_isNew() || $propertyValue->_isDirty() || ($propertyValue->count() == 0 && $cleanProperty && $cleanProperty->count() > 0)) {
                                        $this->persistObjectStorage($propertyValue, $object, $propertyName, $row);
                                        $propertyValue->_memorizeCleanState();
                                }