Skip to content
Snippets Groups Projects
Commit 4234fdce authored by Kevin von Spiczak's avatar Kevin von Spiczak
Browse files

[BUGFIX] fix exception on TYPO3 10, where Folder does not have a getFile() method yet

parent abdd0bd8
No related branches found
No related tags found
No related merge requests found
......@@ -51,7 +51,11 @@ use TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderReadPermissionsException;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderWritePermissionsException;
use TYPO3\CMS\Core\Resource\File;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Resource\ProcessedFile;
use TYPO3\CMS\Core\Resource\ResourceFactory;
use TYPO3\CMS\Core\Resource\ResourceStorage;
use TYPO3\CMS\Core\Site\SiteFinder;
use TYPO3\CMS\Core\Utility\ExtensionManagementUtility;
use TYPO3\CMS\Core\Utility\GeneralUtility;
......@@ -776,8 +780,9 @@ class JoblistController extends ActionController {
$newFilename = strtolower($singleFilePostKey) . '.' . strtolower($filePathInfo['extension']);
if (array_key_exists($singleUploadedFile, $uploadedFiles)) {
// the same file was uploaded for different sources
$usableFile = $newFolder->getFile(
$uploadedFiles[$singleUploadedFile] . '.' . strtolower($filePathInfo['extension'])
$usableFile = $this->getFileInFolder(
$uploadedFiles[$singleUploadedFile] . '.' . strtolower($filePathInfo['extension']),
$newFolder
);
if (!$usableFile) {
throw new \RuntimeException('File not found (' . $singleFilePostKey . ')!');
......@@ -790,7 +795,7 @@ class JoblistController extends ActionController {
$usableFile = $storage->moveFile($singleFileToMove, $newFolder, $newFilename);
} else {
/** @noinspection PhpUnreachableStatementInspection */
$usableFile = $newFolder->getFile($newFilename);
$usableFile = $this->getFileInFolder($newFilename, $newFolder);
}
$fileReference = $this->fileAndFolderService->createFileReferenceFromFalFileObject($usableFile);
......@@ -810,6 +815,26 @@ class JoblistController extends ActionController {
}
}
/**
* Gets a file in a folder.
* (Backwards compatible with TYPO3 10, where the Folder did not have a getFile() method yet).
*
* @param string $fileName
* @param Folder $folder
* @return null|File|ProcessedFile
*/
protected function getFileInFolder(string $fileName, Folder $folder): ?File {
if (version_compare(VersionNumberUtility::getCurrentTypo3Version(), '11.0.0', '>=')) {
return $folder->getFile($fileName);
}
if ($folder->getStorage()->hasFileInFolder($fileName, $folder)) {
return $folder->getStorage()->getFileInFolder($fileName, $folder);
}
return NULL;
}
/**
* Returns currently set allowedFiles
*
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment