Project

General

Profile

Actions

Bug #78044

open

Can't create \TYPO3\CMS\Extbase\Domain\Model\FileReference from \TYPO3\CMS\Core\Resource\File nor from \TYPO3\CMS\Extbase\Domain\Model\File

Added by Philipp Seßner over 7 years ago. Updated about 1 year ago.

Status:
Under Review
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
-
Start date:
2016-09-22
Due date:
% Done:

0%

Estimated time:
TYPO3 Version:
7
PHP Version:
Tags:
Complexity:
Is Regression:
No
Sprint Focus:

Description

Use Case: I am uploading a file and want to create a file reference to that file, to add it to my model.

Code:

$folder = ResourceFactory::getInstance()->retrieveFileOrFolderObject($folderPath);
$movedFile = $folder->addFile($attachment['tmp_name'], hash_file('md5', $attachment['tmp_name']), DuplicationBehavior::RENAME);

$fileReference = $objectManager->get(TYPO3\CMS\Extbase\Domain\Model\FileReference::class);
$fileReference->setOriginalResource($movedFile);

Exception:

Call to undefined method TYPO3\CMS\Core\Resource\File::getOriginalFile()

Reason:
That is because the requested \TYPO3\CMS\Core\Resource\ResourceInterface (which does not implement method getOriginalFile()) is implemented by \TYPO3\CMS\Core\Resource\FileReference (which is probably expected), aswell as \TYPO3\CMS\Core\Resource\File
The breaking commit is https://forge.typo3.org/projects/typo3cms-core/repository/revisions/159fd37d509e00983a4348a2e860b3579f5f1b5b

Suggested Solutions:
I see 3 possible solutions for the TYPO3\CMS\Extbase\Domain\Model\FileReference::setOriginalResource() method:
  1. It requires \TYPO3\CMS\Core\Resource\FileReference (like before, but I don't favour this solution as I cannot find an easy way to get an object of the ...\Resource\FileReference from a \TYPO3\CMS\Core\Resource\File)
  2. It requires \TYPO3\CMS\Core\Resource\File (or \TYPO3\CMS\Core\Resource\AbstractFile) and calls "getUid()" directly
  3. It requires \TYPO3\CMS\Extbase\Domain\Model\File (this would be package compliant, and you can easily get an object of the required class from \TYPO3\CMS\Core\Resource\File)

Related issues 1 (1 open0 closed)

Related to TYPO3 Core - Feature #90374: Add setOriginaFile / setFile setter to TYPO3\CMS\Extbase\Domain\Model\FileReferenceUnder Review2020-02-15

Actions
Actions

Also available in: Atom PDF