[BUGFIX] Misleading frontend output when deleting images in edit mode 79/58679/2
authorStanislas Rolland <typo3@sjbr.ca>
Wed, 24 Oct 2018 02:32:04 +0000 (22:32 -0400)
committerStanislas Rolland <typo3@sjbr.ca>
Wed, 24 Oct 2018 02:35:02 +0000 (04:35 +0200)
If a frontend user is trying to delete an existing profile image
using the trashcan symbol shown next to the image file name
the page and form is reloaded and the image is removed from file
system but still not removed from user record in database.
This issue arises with TYPO3 7 LTS, but not with TYPO3 8 LTS.
With TYPO3 8 LTS, the file and the reference are deleted as soon as
the trash can is hit, so that when the form is reloaded the file is
not shown anymore, even though the whole form is not yet saved.
This solution will be applied to TYPO3 7 LTS as well.

Resolves: #84569
Change-Id: Ibe52d0c1930c069c1cdb5c8e923fc636cf0717e0
Reviewed-on: https://review.typo3.org/58679
Reviewed-by: Stanislas Rolland <typo3@sjbr.ca>
Tested-by: Stanislas Rolland <typo3@sjbr.ca>
ChangeLog
Classes/Hooks/FileUploadHooks.php

index d472775..4c4cced 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,6 +1,7 @@
 2018-10-23 Stanislas Rolland  <typo3(arobas)sjbr.ca>
        * Resolves #85925: PHP codeinspection returns errors
        * Resolves #84694: Backslash missing in user image preview link path
+       * Resolves #84569: Misleading frontend output while deleting images in EDIT mode
 
 2018-04-04 Stanislas Rolland  <typo3(arobas)sjbr.ca>
        * Resolves #84605: PHP Warning: count() in SJBR\SrFeuserRegister\Request\Parameters
index 050599e..f1ddbfd 100644 (file)
@@ -350,10 +350,25 @@ class FileUploadHooks
                                }
                        }
                } else {
-                       $uploadPath = $GLOBALS['TCA'][$theTable]['columns'][$theField]['config']['uploadfolder'];
-                       $uploadPath = $uploadPath ?: $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_feuser_register']['uploadfolder'];
-                       if (@is_file(PATH_site . $uploadPath . '/' . $file['name'])) {
-                               @unlink(PATH_site . $uploadPath . '/' . $file['name']);
+                       if ($fieldConf['config']['type'] === 'group' && $fieldConf['config']['internal_type'] === 'file') {
+                               // TYPO3 7 LTS
+                               $uploadPath = $fieldConf['uploadfolder'];
+                               $uploadPath = $uploadPath ?: $GLOBALS['TYPO3_CONF_VARS']['EXTCONF']['sr_feuser_register']['uploadfolder'];
+                               $record = $GLOBALS['TSFE']->sys_page->getRawRecord($theTable, (int)$uid);
+                               if (is_array($rec)) {
+                                       $fileArray = explode(',', $record[$theField]);
+                                       foreach ($fileArray as $index => $fileItem) {
+                                               if ($fileItem == $file['name']) {
+                                                       unset($fileArray[$index]]);
+                                               }
+                                       }
+                                       $updateFields = [];
+                                       $updateFields[$theField] = implode(',', $fileArray);
+                                       $res = $GLOBALS['TSFE']->cObj->DBgetUpdate($theTable, (int)$uid, $updateFields, $theField, true);
+                               }
+                               if (@is_file(PATH_site . $uploadPath . '/' . $file['name'])) {
+                                       @unlink(PATH_site . $uploadPath . '/' . $file['name']);
+                               }
                        }
                }
        }