Delete legacy avatar thumbnails in UserRebuildDataWorker
authorTim Düsterhus <duesterhus@woltlab.com>
Tue, 23 Feb 2021 15:53:26 +0000 (16:53 +0100)
committerTim Düsterhus <duesterhus@woltlab.com>
Tue, 23 Feb 2021 15:53:26 +0000 (16:53 +0100)
Resolves #4010

wcfsetup/install/files/lib/data/user/avatar/UserAvatarEditor.class.php
wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php

index ea7e85958802a90dc4c2b00d118332122362084c..f8352f08a7e804ac635bbef297eb5826520a2052 100644 (file)
@@ -58,19 +58,26 @@ class UserAvatarEditor extends DatabaseObjectEditor
     }
 
     /**
-     * Deletes avatar files.
+     * Deletes the legacy thumbnail sizes.
+     *
+     * @since 5.4
+     * @deprecated 5.4 This relies on the deprecated UserAvatar::$avatarThumbnailSizes.
      */
-    public function deleteFiles()
+    public function deleteLegacyThumbnails(): void
     {
         // delete wcf2.1 files
         foreach (UserAvatar::$avatarThumbnailSizes as $size) {
-            if ($this->width < $size && $this->height < $size) {
-                break;
-            }
-
             @\unlink($this->getLocation($size, false));
         }
         @\unlink($this->getLocation('resize', false));
+    }
+
+    /**
+     * Deletes avatar files.
+     */
+    public function deleteFiles()
+    {
+        $this->deleteLegacyThumbnails();
 
         // delete original size
         @\unlink($this->getLocation(null, false));
index ea1b517482843b3d63f8233ad008b327750d4a67..6423618e513e52c8152718a4986ab6c3ce2c5f64 100644 (file)
@@ -271,6 +271,7 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker
                     $width = $height = UserAvatar::AVATAR_SIZE;
                 }
 
+                $editor->deleteLegacyThumbnails();
                 $editor->createAvatarVariant();
 
                 $editor->update([