Bug #38184

PersistenceManager chokes on empty uploads

Added by Bastian Waidelich about 3 years ago. Updated about 3 years ago.

Status:Resolved Start date:2012-06-19
Priority:Must have Due date:
Assigned To:Bastian Waidelich % Done:

100%

Category:Property
Target version:TYPO3 Flow Base Distribution - 1.1
PHP Version: Complexity:
Has patch:No Affected Flow version:Git 1.2 (master)

Description

Given following setup:

Domain/Model/SomeObject.php
 1/**
 2 * @FLOW3\Entity
 3 */
 4class SomeObject {
 5
 6    /**
 7     * @var \Doctrine\Common\Collections\ArrayCollection<\TYPO3\FLOW3\Resource\Resource>
 8     * @ORM\ManyToMany
 9     */
10    protected $resources;
11
12    // ...
13
14}


Template.html
1<f:form method="post" action="create" object="{newObject}" objectName="newObject" enctype="multipart/form-data">
2    <f:form.upload property="resources.0" />
3    <f:form.upload property="resources.1" />
4    <f:form.submit value="Create"/>
5</f:form>

If you submit the form, following exception is thrown:

#1337934455: Could not add object of type "MyPackage\Domain\Model\SomeObject" (in PersistenceManager:264)
Warning: spl_object_hash() expects parameter 1 to be object, null given in Packages/Framework/Doctrine.ORM/Classes/UnitOfWork.php line 1509

A similar problem occurs when adding an intermediate object like "File" as OneToMany relation which contains a relation to one resource:

Domain/Model/SomeObject.php
 1/**
 2 * @FLOW3\Entity
 3 */
 4class SomeObject {
 5
 6    /**
 7     * @var \Doctrine\Common\Collections\ArrayCollection<\TYPO3\FLOW3\Resource\Resource>
 8     * @ORM\OneToMany(mappedBy="someObject",cascade={"all"})
 9     */
10    protected $files;
11
12    // ...
13
14}


Template.html
1<f:form method="post" action="create" object="{newObject}" objectName="newObject" enctype="multipart/form-data">
2    <f:form.upload property="files.0.originalResource" />
3    <f:form.upload property="files.1.originalResource" />
4    <f:form.submit value="Create"/>
5</f:form>

In that case the exception is thrown while property mapping already:

#1297759968: Exception while property mapping for target type "MyPackage\Domain\Model\SomeObject", at property path "files.0": Catchable Fatal Error: Argument 1 passed to MyPackage\Domain\Model\File::setOriginalResource() must be an instance of TYPO3\FLOW3\Resource\Resource, null given, called in Packages/Framework/TYPO3.FLOW3/Classes/Reflection\ObjectAccess.php on line 182

So, I'm not sure if that's a problem of the property mapper or the persistence actually. But this was not present before and is a blocker IMO

Associated revisions

Revision 38fcda54
Added by Bastian Waidelich about 3 years ago

[BUGFIX] Only map file uploads to arguments if not empty

Currently the HTTP request converts the FILES superglobal
to request arguments even if no file has been uploaded.
This leads to an exception when submitting a form without
uploading a file because the property mapper receives a
corrupt source array in that case.

This adjust the HTTP request to only map values from the
FILES superglobal to arguments if a file has been uploaded.

This also tweaks the ResourceTypeConverter to accept
an empty source. Besides the converter now only outputs
filer errors (for too large or corrupt files) to the user.
Server errors (e.g. non-existing/read-only tmp directory)
are logged to the systemLogger.

Change-Id: I31519231086cd71feff73ff675806d0382ae6b40
Fixes: #38184
Releases: 1.1, 1.2

Revision 4441c3cb
Added by Bastian Waidelich about 3 years ago

[BUGFIX] Only map file uploads to arguments if not empty

Currently the HTTP request converts the FILES superglobal
to request arguments even if no file has been uploaded.
This leads to an exception when submitting a form without
uploading a file because the property mapper receives a
corrupt source array in that case.

This adjust the HTTP request to only map values from the
FILES superglobal to arguments if a file has been uploaded.

This also tweaks the ResourceTypeConverter to accept
an empty source. Besides the converter now only outputs
filer errors (for too large or corrupt files) to the user.
Server errors (e.g. non-existing/read-only tmp directory)
are logged to the systemLogger.

Change-Id: I718893e38204ceef2d5ed13e48c17bccf0f226b6
Fixes: #38184
Releases: 1.1, 1.2

History

#1 Updated by Bastian Waidelich about 3 years ago

Update: This is most probably a regression introduced with https://review.typo3.org/#/c/11709/1

#2 Updated by Bastian Waidelich about 3 years ago

  • Category changed from Persistence to Property

#3 Updated by Karsten Dambekalns about 3 years ago

  • Assigned To set to Bastian Waidelich

#4 Updated by Karsten Dambekalns about 3 years ago

  • Status changed from New to Accepted

#5 Updated by Gerrit Code Review about 3 years ago

  • Status changed from Accepted to Under Review

Patch set 1 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/12216

#6 Updated by Gerrit Code Review about 3 years ago

Patch set 2 for branch master has been pushed to the review server.
It is available at http://review.typo3.org/12216

#7 Updated by Bastian Waidelich about 3 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100

#8 Updated by Gerrit Code Review about 3 years ago

  • Status changed from Resolved to Under Review

Patch set 1 for branch FLOW3-1.1 has been pushed to the review server.
It is available at http://review.typo3.org/12228

#9 Updated by Bastian Waidelich about 3 years ago

  • Status changed from Under Review to Resolved

Also available in: Atom PDF