[BUGFIX] Repository replace() does not replace unpersisted objects
authorClaus Due <claus@wildside.dk>
Wed, 7 Dec 2011 17:50:23 +0000 (18:50 +0100)
committerJochen Rau <jochen.rau@typoplanet.de>
Fri, 3 Feb 2012 17:12:50 +0000 (12:12 -0500)
This adds an additional case to check $this->addedObjects even if
$existingObject has an UID. Without this, adding, persisting and
replacing an object in the same controller action would cause the
replace() command to have no effect.

Thanks to Balisky Christophe for reporting.

Change-Id: Id297b1d5ae261a88aad485b718ea1a3e8be76f3e
Fixes: #7571

typo3/sysext/extbase/Classes/Persistence/Repository.php

index dfd0c76..30523bc 100644 (file)
@@ -197,6 +197,9 @@ class Tx_Extbase_Persistence_Repository implements Tx_Extbase_Persistence_Reposi
                        if ($this->removedObjects->contains($existingObject)) {
                                $this->removedObjects->detach($existingObject);
                                $this->removedObjects->attach($newObject);
+                       } elseif ($this->addedObjects->contains($existingObject)) {
+                               $this->addedObjects->detach($existingObject);
+                               $this->addedObjects->attach($newObject);
                        }
                } elseif ($this->addedObjects->contains($existingObject)) {
                        $this->addedObjects->detach($existingObject);