[REVERT] let PersistentObjectConverter clone objects
authorFelix Oertel <f@oer.tel>
Fri, 13 Jan 2012 10:07:14 +0000 (11:07 +0100)
committerFelix Oertel <f@oer.tel>
Fri, 13 Jan 2012 10:07:14 +0000 (11:07 +0100)
This reverts https://review.typo3.org/#change,7748

Before keeping the objectConverter from cloning objects we have to
take care of auto-persisting objects from the identityMap.

Change-Id: Ifb6a7ede58bc2338e4c1fa9d2aff31a3e5eaaf4f

typo3/sysext/extbase/Classes/Property/TypeConverter/PersistentObjectConverter.php
typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php

index 342b1fd..3f0f3e4 100644 (file)
@@ -195,6 +195,8 @@ class Tx_Extbase_Property_TypeConverter_PersistentObjectConverter extends Tx_Ext
                                if ($configuration === NULL || $configuration->getConfigurationValue('Tx_Extbase_Property_TypeConverter_PersistentObjectConverter', self::CONFIGURATION_MODIFICATION_ALLOWED) !== TRUE) {
                                        throw new Tx_Extbase_Property_Exception_InvalidPropertyMappingConfigurationException('Modification of persistent objects not allowed. To enable this, you need to set the PropertyMappingConfiguration Value "CONFIGURATION_MODIFICATION_ALLOWED" to TRUE.', 1297932028);
                                }
+
+                               $object = clone $object;
                        }
 
                        return $object;
index 64e259f..91452f0 100644 (file)
@@ -200,7 +200,7 @@ class Tx_Extbase_Tests_Unit_Property_TypeConverter_PersistentObjectConverterTest
         * @test
         * @author Sebastian Kurf├╝rst <sebastian@typo3.org>
         */
-       public function convertFromShouldNotCloneTheFetchedObjectIfObjectNeedsToBeModified() {
+       public function convertFromShouldCloneTheFetchedObjectIfObjectNeedsToBeModified() {
                $identifier = '12345';
                $object = new Tx_Extbase_Fixtures_ClassWithSetters();
                $object->someProperty = 'asdf';
@@ -217,7 +217,7 @@ class Tx_Extbase_Tests_Unit_Property_TypeConverter_PersistentObjectConverterTest
                $configuration = $this->buildConfiguration(array(Tx_Extbase_Property_TypeConverter_PersistentObjectConverter::CONFIGURATION_MODIFICATION_ALLOWED => TRUE));
                $actual = $this->converter->convertFrom($source, 'MySpecialType', $convertedChildProperties, $configuration);
 
-               $this->assertSame($object, $actual, 'The object has been cloned.');
+               $this->assertNotSame($object, $actual, 'The object has not been cloned.');
                $this->assertEquals('asdf', $actual->someProperty, 'The object somehow lost its current state.');
                $this->assertEquals('someConvertedValue', $actual->property1, 'The sub properties have not been set.');
        }