[BUGFIX] Allow integers to be converted to objects 92/32592/2
authorHelmut Hummel <helmut.hummel@typo3.org>
Mon, 1 Sep 2014 09:43:40 +0000 (11:43 +0200)
committerMarkus Klein <klein.t3@reelworx.at>
Thu, 4 Sep 2014 22:37:10 +0000 (00:37 +0200)
In TYPO3 CMS the identity of objects/ records are
integers (uids). Because of that, the persistent object
type converter should be able to convert integers to
objects, not only strings.

Releases: 6.2, 6.3
Resolves: #61292
Change-Id: I0b69295ae7adfdbe49cf19056614b984f34290c6
Reviewed-on: http://review.typo3.org/32592
Reviewed-by: Markus Klein <klein.t3@reelworx.at>
Tested-by: Markus Klein <klein.t3@reelworx.at>
typo3/sysext/extbase/Classes/Property/TypeConverter/PersistentObjectConverter.php
typo3/sysext/extbase/Tests/Unit/Property/TypeConverter/PersistentObjectConverterTest.php

index aaefa4c..56a8f1e 100644 (file)
@@ -49,7 +49,7 @@ class PersistentObjectConverter extends ObjectConverter {
        /**
         * @var array
         */
-       protected $sourceTypes = array('string', 'array');
+       protected $sourceTypes = array('integer', 'string', 'array');
 
        /**
         * @var string
@@ -85,7 +85,7 @@ class PersistentObjectConverter extends ObjectConverter {
         * @return array
         */
        public function getSourceChildPropertiesToBeConverted($source) {
-               if (is_string($source)) {
+               if (is_string($source) || is_int($source)) {
                        return array();
                }
                if (isset($source['__identity'])) {
@@ -139,13 +139,13 @@ class PersistentObjectConverter extends ObjectConverter {
                                unset($source['__identity']);
                        }
                        $object = $this->handleArrayData($source, $targetType, $convertedChildProperties, $configuration);
-               } elseif (is_string($source)) {
-                       if ($source === '' || $source === '0') {
+               } elseif (is_string($source) || is_int($source)) {
+                       if (empty($source)) {
                                return NULL;
                        }
                        $object = $this->fetchObjectFromPersistence($source, $targetType);
                } else {
-                       throw new \InvalidArgumentException('Only strings and arrays are accepted.', 1305630314);
+                       throw new \InvalidArgumentException('Only integers, strings and arrays are accepted.', 1305630314);
                }
                foreach ($convertedChildProperties as $propertyName => $propertyValue) {
                        $result = \TYPO3\CMS\Extbase\Reflection\ObjectAccess::setProperty($object, $propertyName, $propertyValue);
index 3401a12..80b7680 100644 (file)
@@ -62,7 +62,7 @@ class PersistentObjectConverterTest extends \TYPO3\CMS\Core\Tests\UnitTestCase {
         * @test
         */
        public function checkMetadata() {
-               $this->assertEquals(array('string', 'array'), $this->converter->getSupportedSourceTypes(), 'Source types do not match');
+               $this->assertEquals(array('integer', 'string', 'array'), $this->converter->getSupportedSourceTypes(), 'Source types do not match');
                $this->assertEquals('object', $this->converter->getSupportedTargetType(), 'Target type does not match');
                $this->assertEquals(1, $this->converter->getPriority(), 'Priority does not match');
        }