[BUGFIX] Fix invalid type hints in EXT:form's file upload converter 84/54784/6
authorOliver Hader <oliver@typo3.org>
Mon, 27 Nov 2017 11:11:48 +0000 (12:11 +0100)
committerSusanne Moog <susanne.moog@typo3.org>
Fri, 8 Dec 2017 12:16:30 +0000 (13:16 +0100)
Due to invalid PHP type hints updating a previously uploaded file
reference in a mail form fails in the frontend.

Resolves: #83112
Releases: master, 8.7
Change-Id: Ibf98267a60f076b5654fb0d0d9181a4caeed49b3
Reviewed-on: https://review.typo3.org/54784
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Susanne Moog <susanne.moog@typo3.org>
Tested-by: Susanne Moog <susanne.moog@typo3.org>
typo3/sysext/form/Classes/Mvc/Property/TypeConverter/UploadedFileReferenceConverter.php

index f86c03b..567b7c2 100644 (file)
@@ -132,11 +132,11 @@ class UploadedFileReferenceConverter extends AbstractTypeConverter
      * Actually convert from $source to $targetType, taking into account the fully
      * built $convertedChildProperties and $configuration.
      *
-     * @param string|int $source
+     * @param array $source
      * @param string $targetType
      * @param array $convertedChildProperties
      * @param PropertyMappingConfigurationInterface $configuration
-     * @return AbstractFileFolder
+     * @return AbstractFileFolder|Error|null
      * @internal
      */
     public function convertFrom($source, $targetType, array $convertedChildProperties = [], PropertyMappingConfigurationInterface $configuration = null)
@@ -144,12 +144,17 @@ class UploadedFileReferenceConverter extends AbstractTypeConverter
         if (!isset($source['error']) || $source['error'] === \UPLOAD_ERR_NO_FILE) {
             if (isset($source['submittedFile']['resourcePointer'])) {
                 try {
+                    // File references use numeric resource pointers, direct
+                    // file relations are using "file:" prefix (e.g. "file:5")
                     $resourcePointer = $this->hashService->validateAndStripHmac($source['submittedFile']['resourcePointer']);
                     if (strpos($resourcePointer, 'file:') === 0) {
-                        $fileUid = substr($resourcePointer, 5);
+                        $fileUid = (int)substr($resourcePointer, 5);
                         return $this->createFileReferenceFromFalFileObject($this->resourceFactory->getFileObject($fileUid));
                     }
-                    return $this->createFileReferenceFromFalFileReferenceObject($this->resourceFactory->getFileReferenceObject($resourcePointer), $resourcePointer);
+                    return $this->createFileReferenceFromFalFileReferenceObject(
+                        $this->resourceFactory->getFileReferenceObject($resourcePointer),
+                        (int)$resourcePointer
+                    );
                 } catch (\InvalidArgumentException $e) {
                     // Nothing to do. No file is uploaded and resource pointer is invalid. Discard!
                 }
@@ -240,6 +245,10 @@ class UploadedFileReferenceConverter extends AbstractTypeConverter
     }
 
     /**
+     * In case no $resourcePointer is given a new file reference domain object
+     * will be returned. Otherwise the file reference is reconstituted from
+     * storage and will be updated(!) with the provided $falFileReference.
+     *
      * @param CoreFileReference $falFileReference
      * @param int $resourcePointer
      * @return ExtbaseFileReference