Commit 9378ce8b authored by Mathias Brodala's avatar Mathias Brodala Committed by Benni Mack
Browse files

[BUGFIX] Persist traversable domain objects via identifier

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/51287

Tested-by: default avatarTYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent ee644663
......@@ -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);
......
......@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Extbase\Tests\Unit\Persistence\Generic\Mapper;
*/
use TYPO3\CMS\Components\TestingFramework\Core\AccessibleObjectInterface;
use TYPO3\CMS\Extbase\DomainObject\DomainObjectInterface;
use TYPO3\CMS\Extbase\Persistence\Generic\Exception\UnexpectedTypeException;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\ColumnMap;
use TYPO3\CMS\Extbase\Persistence\Generic\Mapper\DataMapper;
......@@ -313,6 +314,11 @@ class DataMapperTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTes
*/
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],
......@@ -321,6 +327,7 @@ class DataMapperTest extends \TYPO3\CMS\Components\TestingFramework\Core\UnitTes
'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()],
];
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment