[BUGFIX] Fix persisting of lazy object storages
authorThomas Maroschik <tmaroschik@dfau.de>
Mon, 29 Apr 2013 21:42:33 +0000 (23:42 +0200)
committerMarc Bastian Heinrichs <typo3@mbh-software.de>
Mon, 29 Apr 2013 22:07:43 +0000 (00:07 +0200)
Lazy object storages saved in the clean state of a
parent object get initialized during persisting and
set the clean state of the parent object to the current changed
state. After that the persistence backend cannot detect any
changes and skips persisting of the changed relations.

This fix checks if the lazy object storage is already part
of the parents clean state and skips the memorization in
this case.

Fixes: #47703
Releases: 6.2, 6.1
Change-Id: I6801ca8ff709253ac33c65bc619b5d794f5615ce
Reviewed-on: https://review.typo3.org/20335
Reviewed-by: Nico de Haen
Tested-by: Nico de Haen
Reviewed-by: Marc Bastian Heinrichs
Tested-by: Marc Bastian Heinrichs
typo3/sysext/extbase/Classes/Persistence/Generic/LazyObjectStorage.php

index 7aed39a..3661ddb 100644 (file)
@@ -120,10 +120,19 @@ class LazyObjectStorage extends \TYPO3\CMS\Extbase\Persistence\ObjectStorage imp
                                parent::attach($object);
                        }
                        $this->_memorizeCleanState();
-                       $this->parentObject->_memorizeCleanState($this->propertyName);
+                       if (!$this->isStorageAlreadyMemorizedInParentCleanState()) {
+                               $this->parentObject->_memorizeCleanState($this->propertyName);
+                       }
                }
        }
 
+       /**
+        * @return bool
+        */
+       protected function isStorageAlreadyMemorizedInParentCleanState() {
+               return $this->parentObject->_getCleanProperty($this->propertyName) === $this;
+       }
+
        // Delegation to the ObjectStorage methods below
        /**
         * @param \TYPO3\CMS\Extbase\Persistence\ObjectStorage $storage
@@ -298,6 +307,15 @@ class LazyObjectStorage extends \TYPO3\CMS\Extbase\Persistence\ObjectStorage imp
                $this->initialize();
                return parent::toArray();
        }
+
+       /**
+        * @param mixed $object
+        * @return integer|NULL
+        */
+       public function getPosition($object) {
+               $this->initialize();
+               return parent::getPosition($object);
+       }
 }
 
 ?>
\ No newline at end of file