[BUGFIX] Adjust response usage for `file/exists` route 71/55371/2
authorAndreas Fernandez <a.fernandez@scripting-base.de>
Tue, 16 Jan 2018 11:21:06 +0000 (12:21 +0100)
committerBenni Mack <benni@typo3.org>
Tue, 16 Jan 2018 13:20:43 +0000 (14:20 +0100)
With #83267 a JSON response object was introduced. The patch has the side
effect that any response is now an array but some usages in JavaScript
were not adjusted.

This patch does two things:

- `FileController::fileExistsInFolderAction()` does now either return an
  array for falsy results OR the file object.
- The JavaScript code is adjusted to check for a valid file object by
  requiring the `uid` property instead.

Resolves: #83568
Related: #83267
Releases: master
Change-Id: I9878f5f70b8af3ba8ec151a6ed514780547ec1ea
Reviewed-on: https://review.typo3.org/55371
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Frans Saris <franssaris@gmail.com>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Reviewed-by: Markus Klein <markus.klein@typo3.org>
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Stefan Neufeind <typo3.neufeind@speedpartner.de>
Reviewed-by: Benni Mack <benni@typo3.org>
Tested-by: Benni Mack <benni@typo3.org>
typo3/sysext/backend/Classes/Controller/File/FileController.php
typo3/sysext/backend/Resources/Private/TypeScript/RenameFile.ts
typo3/sysext/backend/Resources/Public/JavaScript/DragUploader.js
typo3/sysext/backend/Resources/Public/JavaScript/RenameFile.js

index ebbc728..c6e0a13 100644 (file)
@@ -255,11 +255,11 @@ class FileController
         $fileTargetObject = $fileFactory->retrieveFileOrFolderObject($fileTarget);
         $processedFileName = $fileTargetObject->getStorage()->sanitizeFileName($fileName, $fileTargetObject);
 
-        $result = false;
+        $result = [];
         if ($fileTargetObject->hasFile($processedFileName)) {
             $result = $this->flattenResultDataValue($fileTargetObject->getStorage()->getFileInFolder($processedFileName, $fileTargetObject));
         }
-        return GeneralUtility::makeInstance(JsonResponse::class)->setPayload([$result]);
+        return GeneralUtility::makeInstance(JsonResponse::class)->setPayload($result);
     }
 
     /**
index 455d1f0..2225043 100644 (file)
@@ -45,7 +45,7 @@ class RenameFile {
         fileTarget: form.find('input[name="data[rename][0][destination]"]').val(),
       },
       success: (response: any): void => {
-        const fileExists: boolean = response !== false;
+        const fileExists: boolean = typeof response.uid !== 'undefined';
         const originalFileName: string = fileNameField.data('original');
         const newFileName: string = fileNameField.val();
 
index bbcbabf..267bf7d 100644 (file)
@@ -175,7 +175,7 @@ define(['jquery',
                                        },
                                        cache: false,
                                        success: function(response) {
-                                               var fileExists = response !== false;
+                                               var fileExists = typeof response.uid !== 'undefined';
                                                if (fileExists) {
                                                        askForOverride.push({
                                                                original: response,
index 5350e22..9e1ae35 100644 (file)
@@ -37,7 +37,7 @@ define(["require", "exports", "jquery", "TYPO3/CMS/Backend/Modal", "TYPO3/CMS/Ba
                     fileTarget: form.find('input[name="data[rename][0][destination]"]').val(),
                 },
                 success: function (response) {
-                    var fileExists = response !== false;
+                    var fileExists = typeof response.uid !== 'undefined';
                     var originalFileName = fileNameField.data('original');
                     var newFileName = fileNameField.val();
                     if (fileExists && originalFileName !== newFileName) {