Commit 35f8da6e authored by Frans Saris's avatar Frans Saris
Browse files

[FOLLOWUP][FEATURE] Ajax call to check if file already exists

The fileExist call now returns all info about a file just like
done after fileupload.

Resolves: #67545
Releases: master
Change-Id: Ie70f1597b98ea0c2b9cb7999686eb8a062b5ecaa
Reviewed-on: http://review.typo3.org/41398


Reviewed-by: Benni Mack's avatarBenjamin Mack <benni@typo3.org>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez's avatarAndreas Fernandez <typo3@scripting-base.de>
Tested-by: Frans Saris's avatarFrans Saris <franssaris@gmail.com>
parent 9a406661
......@@ -15,6 +15,7 @@ namespace TYPO3\CMS\Backend\Controller\File;
*/
use TYPO3\CMS\Core\Http\AjaxRequestHandler;
use TYPO3\CMS\Core\Resource\Folder;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use TYPO3\CMS\Backend\Utility\BackendUtility;
......@@ -209,10 +210,15 @@ class FileController {
/** @var \TYPO3\CMS\Core\Resource\ResourceFactory $fileFactory */
$fileFactory = GeneralUtility::makeInstance(\TYPO3\CMS\Core\Resource\ResourceFactory::class);
/** @var Folder $fileTargetObject */
$fileTargetObject = $fileFactory->retrieveFileOrFolderObject($fileTarget);
$processedFileName = $fileTargetObject->getStorage()->processUploadedFileName($fileTargetObject, $fileName);
$ajaxObj->addContent('result', $fileTargetObject->hasFile($processedFileName));
$result = FALSE;
if ($fileTargetObject->hasFile($processedFileName)) {
$result = $this->flattenResultDataValue($fileTargetObject->getStorage()->getFileInFolder($processedFileName, $fileTargetObject));
}
$ajaxObj->addContent('result', $result);
$ajaxObj->setContentFormat('json');
}
......@@ -226,11 +232,19 @@ class FileController {
*/
protected function flattenResultDataValue($result) {
if ($result instanceof \TYPO3\CMS\Core\Resource\File) {
$thumbUrl = '';
if (GeneralUtility::inList($GLOBALS['TYPO3_CONF_VARS']['GFX']['imagefile_ext'], $result->getExtension())) {
$processedFile = $result->process(\TYPO3\CMS\Core\Resource\ProcessedFile::CONTEXT_IMAGEPREVIEW, array());
if ($processedFile) {
$thumbUrl = $processedFile->getPublicUrl(TRUE);
}
}
$result = array_merge(
$result->toArray(),
array (
'date' => BackendUtility::date($result->getModificationTime()),
'iconClasses' => \TYPO3\CMS\Backend\Utility\IconUtility::mapFileExtensionToSpriteIconClass($result->getExtension()),
'thumbUrl' => $thumbUrl
)
);
} elseif ($result instanceof \TYPO3\CMS\Core\Resource\Folder) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment