[BUGFIX] Persist traversable domain objects via identifier 46/51446/2
authorMathias Brodala <mbrodala@pagemachine.de>
Thu, 12 Jan 2017 13:03:04 +0000 (14:03 +0100)
committerBenni Mack <benni@typo3.org>
Fri, 27 Jan 2017 11:02:48 +0000 (12:02 +0100)
Objects implementing the DomainObjectInterface must always be
persisted using their identifier, even if they implement the
Traversable interface.

Change-Id: Iccb53d6e7ded9b6b5300e111e8503641b10615f4
Resolves: #79294
Related: #57255
Releases: master, 7.6
Reviewed-on: https://review.typo3.org/51446
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapper.php
typo3/sysext/extbase/Tests/Unit/Persistence/Generic/Mapper/DataMapperTest.php

index cf944d1..b4a85ab 100644 (file)
@@ -715,14 +715,14 @@ class DataMapper implements \TYPO3\CMS\Core\SingletonInterface
             } else {
                 $parameter = $input->format('U');
             }
+        } elseif ($input instanceof DomainObjectInterface) {
+            $parameter = (int)$input->getUid();
         } elseif (TypeHandlingUtility::isValidTypeForMultiValueComparison($input)) {
             $plainValueArray = [];
             foreach ($input as $inputElement) {
                 $plainValueArray[] = $this->getPlainValue($inputElement, $columnMap, $parseStringValueCallback, $parseStringValueCallbackParameters);
             }
             $parameter = implode(',', $plainValueArray);
-        } elseif ($input instanceof DomainObjectInterface) {
-            $parameter = (int)$input->getUid();
         } elseif (is_object($input)) {
             if (TypeHandlingUtility::isCoreType($input)) {
                 $parameter = $this->getPlainStringValue($input, $parseStringValueCallback, $parseStringValueCallbackParameters);
index 8a859f2..253039d 100644 (file)
@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper;
  */
 
 use TYPO3\CMS\Core\Tests\AccessibleObjectInterface;
+use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
 use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap;
 use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
 
@@ -296,6 +297,11 @@ class DataMapperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
      */
     public function getPlainValueReturnsExpectedValuesDataProvider()
     {
+        $traversableDomainObject = $this->prophesize()
+            ->willImplement(\Iterator::class)
+            ->willImplement(DomainObjectInterface::class);
+        $traversableDomainObject->getUid()->willReturn(1);
+
         return [
             'datetime to timestamp' => ['1365866253', new \DateTime('@1365866253')],
             'boolean true to 1' => [1, true],
@@ -304,6 +310,7 @@ class DataMapperTest extends \TYPO3\CMS\Core\Tests\UnitTestCase
             'plain value is returned unchanged' => ['RANDOM string', 'RANDOM string'],
             'array is flattened' => ['a,b,c', ['a', 'b', 'c']],
             'deep array is flattened' => ['a,b,c', [['a', 'b'], 'c']],
+            'traversable domain object to identifier' => [1, $traversableDomainObject->reveal()],
         ];
     }