Delete user avatar files when user accounts are deleted
authorCyperghost <olaf_schmitz_1@t-online.de>
Fri, 8 Nov 2024 09:07:58 +0000 (10:07 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Fri, 8 Nov 2024 09:07:58 +0000 (10:07 +0100)
wcfsetup/install/files/lib/data/user/UserAction.class.php

index 7be5ec915b386290a32fedf8eb92cb166b29cc1c..96dd66b904d6e826cf81a12771a9d397c351280f 100644 (file)
@@ -4,6 +4,7 @@ namespace wcf\data\user;
 
 use ParagonIE\ConstantTime\Hex;
 use wcf\data\AbstractDatabaseObjectAction;
+use wcf\data\file\FileAction;
 use wcf\data\IClipboardAction;
 use wcf\data\ISearchAction;
 use wcf\data\object\type\ObjectTypeCache;
@@ -139,16 +140,22 @@ class UserAction extends AbstractDatabaseObjectAction implements IClipboardActio
         }
 
         // delete avatars
-        $avatarIDs = [];
+        $avatarIDs = $avatarFileIDs = [];
         foreach ($this->getObjects() as $user) {
             if ($user->avatarID) {
                 $avatarIDs[] = $user->avatarID;
             }
+            if ($user->avatarFileID !== null) {
+                $avatarFileIDs[] = $user->avatarFileID;
+            }
         }
         if (!empty($avatarIDs)) {
             $action = new UserAvatarAction($avatarIDs, 'delete');
             $action->executeAction();
         }
+        if (!empty($avatarFileIDs)) {
+            (new FileAction($avatarFileIDs, 'delete'))->executeAction();
+        }
 
         // delete profile comments and signature attachments
         if (!empty($this->objectIDs)) {