[BUGFIX] Extbase: Optional arguments must not throw an Exception 46/39946/3
authorAnja Leichsenring <aleichsenring@ab-softlab.de>
Thu, 4 Jun 2015 09:27:42 +0000 (11:27 +0200)
committerStefan Neufeind <typo3.neufeind@speedpartner.de>
Sun, 16 Aug 2015 16:39:20 +0000 (18:39 +0200)
Example:
public function barAction(\Vendor\Ext\Domain\Model\Foo $foo = NULL)

If the property mapper receives NULL, 0 or a valid value
the property mapping does not fail. But if the value is
a valid uid (>0) and there is no record with that uid
the whole property mapping fails.

While this is totally valid for required arguments,
optional arguments must be skipped.

Resolves: #55861
Resolves: #55837
Resolves: #62951
Releases: master, 6.2
Change-Id: I4c954bac50be1d34ea09bfc21f8978e9165683d1
Reviewed-on: http://review.typo3.org/39946
Reviewed-by: Alexander Schnitzler <typo3@alexanderschnitzler.de>
Tested-by: Alexander Schnitzler <typo3@alexanderschnitzler.de>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Tested-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
typo3/sysext/extbase/Classes/Mvc/Controller/Argument.php
typo3/sysext/extbase/Classes/Property/PropertyMapper.php

index 0661892..350269a 100644 (file)
@@ -14,6 +14,7 @@ namespace TYPO3\CMS\Extbase\Mvc\Controller;
  * The TYPO3 project - inspiring people to share!
  */
 
+use TYPO3\CMS\Extbase\Property\Exception\TargetNotFoundException;
 use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility;
 
 /**
@@ -238,8 +239,9 @@ class Argument {
         * Sets the value of this argument.
         *
         * @param mixed $rawValue The value of this argument
+        *
         * @return \TYPO3\CMS\Extbase\Mvc\Controller\Argument
-        * @throws \TYPO3\CMS\Extbase\Mvc\Exception\InvalidArgumentValueException if the argument is not a valid object of type $dataType
+        * @throws \TYPO3\CMS\Extbase\Property\Exception
         */
        public function setValue($rawValue) {
                if ($rawValue === NULL) {
@@ -250,7 +252,14 @@ class Argument {
                        $this->value = $rawValue;
                        return $this;
                }
-               $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration);
+               try {
+                       $this->value = $this->propertyMapper->convert($rawValue, $this->dataType, $this->propertyMappingConfiguration);
+               } catch (TargetNotFoundException $e) {
+                       // for optional arguments no exeption is thrown.
+                       if ($this->isRequired()) {
+                               throw $e;
+                       }
+               }
                $this->validationResults = $this->propertyMapper->getMessages();
                if ($this->validator !== NULL) {
                        // @todo Validation API has also changed!!!
index dedeb9c..3840d2a 100644 (file)
@@ -20,6 +20,7 @@ namespace TYPO3\CMS\Extbase\Property;
  *                                                                        *
  * The TYPO3 project - inspiring people to share!                         *
  *                                                                        */
+use TYPO3\CMS\Extbase\Property\Exception\TargetNotFoundException;
 use TYPO3\CMS\Extbase\Property\TypeConverter\AbstractTypeConverter;
 use TYPO3\CMS\Extbase\Utility\TypeHandlingUtility;
 
@@ -117,6 +118,8 @@ class PropertyMapper implements \TYPO3\CMS\Core\SingletonInterface {
                        }
 
                        return $result;
+               } catch (TargetNotFoundException $e) {
+                       throw $e;
                } catch (\Exception $e) {
                        throw new Exception('Exception while property mapping at property path "' . implode('.', $currentPropertyPath) . '":' . $e->getMessage(), 1297759968, $e);
                }