From af662d1451c217f4dacab4bfdace6751515c4722 Mon Sep 17 00:00:00 2001
From: Thomas Hohn <thomas@hohn.dk>
Date: Sun, 26 Feb 2017 12:01:33 +0100
Subject: [PATCH] [BUGFIX] If User TSConfig disables avatar it gets lost when
 saved

If the user is not allow to modify the avatar it gets
lost since there was no distinction between deleted and
not allowed to modify causing the avatar to be deleted
on save.

Resolves: #80002
Releases: master
Change-Id: I1cf6fa93c2af1122c481b52860990c2433d86594
Reviewed-on: https://review.typo3.org/51860
Reviewed-by: Josef Glatz <josef.glatz@typo3.org>
Tested-by: Josef Glatz <josef.glatz@typo3.org>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: TYPO3com <no-reply@typo3.com>
---
 .../Classes/Controller/SetupModuleController.php     | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/typo3/sysext/setup/Classes/Controller/SetupModuleController.php b/typo3/sysext/setup/Classes/Controller/SetupModuleController.php
index 78bcc7ee613a..64ea54136d19 100644
--- a/typo3/sysext/setup/Classes/Controller/SetupModuleController.php
+++ b/typo3/sysext/setup/Classes/Controller/SetupModuleController.php
@@ -960,6 +960,11 @@ class SetupModuleController extends AbstractModule
             return;
         }
 
+        // If user is not allowed to modify avatar $fileUid is empty - so don't overwrite existing avatar
+        if (empty($fileUid)) {
+            return;
+        }
+
         $queryBuilder = GeneralUtility::makeInstance(ConnectionPool::class)->getQueryBuilderForTable('sys_file_reference');
         $queryBuilder->getRestrictions()->removeAll();
         $queryBuilder
@@ -984,6 +989,11 @@ class SetupModuleController extends AbstractModule
             )
             ->execute();
 
+        // If Avatar is marked for delete => set it to empty string so it will be updated properly
+        if ($fileUid === 'delete') {
+            $fileUid = '';
+        }
+
         // Create new reference
         if ($fileUid) {
 
@@ -1035,7 +1045,7 @@ class SetupModuleController extends AbstractModule
             function clearExistingImage() {
                 $(' . GeneralUtility::quoteJSvalue('#image_' . htmlspecialchars($fieldName)) . ').hide();
                 $(' . GeneralUtility::quoteJSvalue('#clear_button_' . htmlspecialchars($fieldName)) . ').hide();
-                $(' . GeneralUtility::quoteJSvalue('#field_' . htmlspecialchars($fieldName)) . ').val(\'\');
+                $(' . GeneralUtility::quoteJSvalue('#field_' . htmlspecialchars($fieldName)) . ').val(\'delete\');
             }
 
             function setFileUid(field, value, fileUid) {
-- 
GitLab