Reset the avatar cache to force the use of the WebP variants
authorAlexander Ebert <ebert@woltlab.com>
Thu, 5 Aug 2021 11:39:03 +0000 (13:39 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Thu, 5 Aug 2021 11:39:03 +0000 (13:39 +0200)
Fixes #4424

com.woltlab.wcf/package.xml
wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4.3_resetAvatarCache.php [new file with mode: 0644]
wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php

index 888fa1b456b77a08c8ffadfdd51716bde987649a..b4d7a5e27f217923fe0bc54bf9b22deed7e4985c 100644 (file)
@@ -156,5 +156,6 @@ tar cvf com.woltlab.wcf/files_pre.tar -C wcfsetup/install/files/ \
 
        <instructions type="update" fromversion="5.4.2">
                <instruction type="script" run="standalone">acp/update_com.woltlab.wcf_5.4.3_deleteDsStore.php</instruction>
+               <instruction type="script" run="standalone">acp/update_com.woltlab.wcf_5.4.3_resetAvatarCache.php</instruction>
        </instructions>
 </package>
diff --git a/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4.3_resetAvatarCache.php b/wcfsetup/install/files/acp/update_com.woltlab.wcf_5.4.3_resetAvatarCache.php
new file mode 100644 (file)
index 0000000..28d1b43
--- /dev/null
@@ -0,0 +1,16 @@
+<?php
+
+/**
+ * Resets the user storage cache for avatars. These had not been updated after
+ * generating the WebP variants of avatars, causing the "old" avatar to be
+ * presented to the browser despite WebP being available.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @package WoltLabSuite\Core
+ */
+
+use wcf\system\user\storage\UserStorageHandler;
+
+UserStorageHandler::getInstance()->resetAll('avatar');
index 0df26ad722873d7fbeaf0595eee6c7071ed94f25..77f32e3fc70e25c54dca467fac4c027e29ed42fe 100644 (file)
@@ -17,6 +17,7 @@ use wcf\system\database\util\PreparedStatementConditionBuilder;
 use wcf\system\exception\SystemException;
 use wcf\system\html\input\HtmlInputProcessor;
 use wcf\system\image\ImageHandler;
+use wcf\system\user\storage\UserStorageHandler;
 use wcf\system\WCF;
 
 /**
@@ -227,7 +228,10 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker
                 ]
             );
             $avatarList->readObjects();
+            $resetAvatarCache = [];
             foreach ($avatarList as $avatar) {
+                $resetAvatarCache[] = $avatar->userID;
+
                 $editor = new UserAvatarEditor($avatar);
                 if (!\file_exists($avatar->getLocation()) || @\getimagesize($avatar->getLocation()) === false) {
                     // delete avatars that are missing or broken
@@ -282,6 +286,11 @@ class UserRebuildDataWorker extends AbstractRebuildDataWorker
                 ]);
             }
 
+            // Reset the avatar cache for all avatars that had been processed.
+            if (!empty($resetAvatarCache)) {
+                UserStorageHandler::getInstance()->reset($resetAvatarCache, 'avatar');
+            }
+
             // Create WebP variants of existing cover photos.
             $userProfiles = new UserProfileList();
             $userProfiles->getConditionBuilder()->add("user_table.userID IN (?)", [$userIDs]);