Skip to content
Snippets Groups Projects
Commit 74b5bf5a authored by Stefan Galinski's avatar Stefan Galinski :video_game:
Browse files

[BUGFIX] Crash if the same is uploaded in the application, Tmp folder not removed on error

parent d7c764f5
No related branches found
No related tags found
No related merge requests found
......@@ -46,6 +46,7 @@ use TYPO3\CMS\Core\Core\Environment;
use TYPO3\CMS\Core\Error\Http\PageNotFoundException;
use TYPO3\CMS\Core\Exception\SiteNotFoundException;
use TYPO3\CMS\Core\Http\ImmediateResponseException;
use TYPO3\CMS\Core\Resource\Exception\AbstractFileOperationException;
use TYPO3\CMS\Core\Resource\Exception\ExistingTargetFileNameException;
use TYPO3\CMS\Core\Resource\Exception\ExistingTargetFolderException;
use TYPO3\CMS\Core\Resource\Exception\InsufficientFolderAccessPermissionsException;
......@@ -704,12 +705,13 @@ class JoblistController extends ActionController {
*
* @param string $folderName
* @param JobApplication $applicationData
* @throws TypeConverterException
* @throws ExistingTargetFileNameException
* @throws ExistingTargetFolderException
* @throws InsufficientFolderAccessPermissionsException
* @throws InsufficientFolderReadPermissionsException
* @throws InsufficientFolderWritePermissionsException
* @throws TypeConverterException
* @throws AbstractFileOperationException
*/
protected function moveTmpFolder(string $folderName, JobApplication $applicationData): void {
$allowedFileExtensions = $this->getAllowedFileExtensions();
......@@ -726,6 +728,7 @@ class JoblistController extends ActionController {
}
// Move uploaded files & csv fo real folder and delete the tmp folder
$uploadedFiles = [];
foreach (self::UPLOADED_FILES as $singleFilePostKey) {
if (!array_key_exists($singleFilePostKey, $_POST)) {
throw new TypeConverterException(
......@@ -739,7 +742,6 @@ class JoblistController extends ActionController {
// get the first uploaded document, should be prevented in the frontend to upload more than one
$singleUploadedFile = current($_POST[$singleFilePostKey])['path'];
$filePathInfo = PathUtility::pathinfo($singleUploadedFile);
if (!GeneralUtility::inList($allowedFileExtensions, strtolower($filePathInfo['extension']))) {
throw new TypeConverterException(
......@@ -749,19 +751,25 @@ class JoblistController extends ActionController {
}
$basename = $filePathInfo['basename'];
if (!$newFolder->hasFile($basename)) {
/** @noinspection PhpUnreachableStatementInspection */
$singleFileToMove = $storage->getFileInFolder($basename, $tempFolder);
$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'])
);
if (!$usableFile) {
throw new \RuntimeException('File not found (' . $singleFilePostKey . ')!');
}
$usableFile = $storage->copyFile($usableFile, $newFolder, $newFilename);
} elseif (!$newFolder->hasFile($newFilename)) {
// when we reload etc. this image might already be moved.
$usableFile = $storage->moveFile(
$singleFileToMove,
$newFolder,
$singleFilePostKey . '.' . $filePathInfo['extension']
);
/** @noinspection PhpUnreachableStatementInspection */
$singleFileToMove = $storage->getFileInFolder($basename, $tempFolder);
$usableFile = $storage->moveFile($singleFileToMove, $newFolder, $newFilename);
} else {
/** @noinspection PhpUnreachableStatementInspection */
$usableFile = $newFolder->getFile($basename);
$usableFile = $newFolder->getFile($newFilename);
}
$fileReference = $this->fileAndFolderService->createFileReferenceFromFalFileObject($usableFile);
......@@ -776,6 +784,8 @@ class JoblistController extends ActionController {
if ($singleFilePostKey === 'certificate') {
$applicationData->setCertificate($fileReference);
}
$uploadedFiles[$singleUploadedFile] = strtolower($singleFilePostKey);
}
}
......@@ -798,7 +808,7 @@ class JoblistController extends ActionController {
$resourceFactory = $this->objectManager->get(ResourceFactory::class);
$storage = $resourceFactory->getStorageObject(1);
try {
$tempFolder = $storage->getFolder('/JobApplication/temp/' . $folderName);
$tempFolder = $storage->getFolder('/JobApplication/' . $folderName);
$storage->deleteFolder($tempFolder, TRUE);
} catch (\Exception $exception) {
// folder is already deleted for some reason
......
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