From: Cyperghost Date: Fri, 8 Nov 2024 10:09:09 +0000 (+0100) Subject: No longer use `wcf1_user_avatar` to load the user's avatar X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=614553ea9dfce325a0f13ecf2cbe714edf0cb420;p=GitHub%2FWoltLab%2FWCF.git No longer use `wcf1_user_avatar` to load the user's avatar --- diff --git a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php index c03a1e2c2f..e4ea36d586 100755 --- a/wcfsetup/install/files/lib/acp/page/UserListPage.class.php +++ b/wcfsetup/install/files/lib/acp/page/UserListPage.class.php @@ -286,12 +286,10 @@ class UserListPage extends SortablePage $statement->execute($conditions->getParameters()); $userToGroups = $statement->fetchMap('userID', 'groupID', false); - $sql = "SELECT user_avatar.*, option_value.*, user_table.* + $sql = "SELECT option_value.*, user_table.* FROM wcf1_user user_table LEFT JOIN wcf1_user_option_value option_value ON option_value.userID = user_table.userID - LEFT JOIN wcf1_user_avatar user_avatar - ON user_avatar.avatarID = user_table.avatarID " . $conditions . " ORDER BY " . (($this->sortField != 'email' && isset($this->options[$this->sortField])) ? 'option_value.userOption' . $this->options[$this->sortField]->optionID : 'user_table.' . $this->sortField) . " " . $this->sortOrder; $statement = WCF::getDB()->prepare($sql); diff --git a/wcfsetup/install/files/lib/data/user/TUserAvatarObjectList.class.php b/wcfsetup/install/files/lib/data/user/TUserAvatarObjectList.class.php new file mode 100644 index 0000000000..7c9ef00b1a --- /dev/null +++ b/wcfsetup/install/files/lib/data/user/TUserAvatarObjectList.class.php @@ -0,0 +1,50 @@ + + * + * @property UserProfile[] $objects + * @mixin DatabaseObjectList + */ +trait TUserAvatarObjectList +{ + public bool $loadAvatarFiles = true; + + protected function loadAvatarFiles(): void + { + if (!$this->loadAvatarFiles) { + return; + } + + $avatarFileIDs = []; + foreach ($this->objects as $user) { + if ($user->avatarFileID !== null) { + $avatarFileIDs[] = $user->avatarFileID; + } + } + if ($avatarFileIDs === []) { + return; + } + + $fileList = new FileList(); + $fileList->loadThumbnails = true; + $fileList->setObjectIDs($avatarFileIDs); + $fileList->readObjects(); + $files = $fileList->getObjects(); + + foreach ($this->objects as $user) { + if ($user->avatarFileID !== null) { + $user->setFileAvatar($files[$user->avatarFileID]); + } + } + } +} diff --git a/wcfsetup/install/files/lib/data/user/UserProfile.class.php b/wcfsetup/install/files/lib/data/user/UserProfile.class.php index 6fa145aaae..c56761dddf 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfile.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfile.class.php @@ -4,14 +4,13 @@ namespace wcf\data\user; use wcf\data\DatabaseObjectDecorator; use wcf\data\file\File; -use wcf\data\file\thumbnail\FileThumbnailList; +use wcf\data\file\FileList; use wcf\data\ITitledLinkObject; use wcf\data\trophy\Trophy; use wcf\data\trophy\TrophyCache; use wcf\data\user\avatar\AvatarDecorator; use wcf\data\user\avatar\DefaultAvatar; use wcf\data\user\avatar\IUserAvatar; -use wcf\data\user\avatar\UserAvatar; use wcf\data\user\cover\photo\DefaultUserCoverPhoto; use wcf\data\user\cover\photo\IUserCoverPhoto; use wcf\data\user\cover\photo\UserCoverPhoto; @@ -347,21 +346,18 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject */ public function getAvatar() { - // TODO simplify this function? if ($this->avatar === null) { if (!$this->disableAvatar) { if ($this->canSeeAvatar()) { if ($this->avatarFileID !== null) { $data = UserStorageHandler::getInstance()->getField('avatar', $this->userID); if ($data === null) { - $this->avatar = new File($this->avatarFileID); + $fileList = new FileList(); + $fileList->setObjectIDs([$this->avatarFileID]); + $fileList->loadThumbnails = true; + $fileList->readObjects(); - $thumbnailList = new FileThumbnailList(); - $thumbnailList->getConditionBuilder()->add("fileID = ?", [$this->avatarFileID]); - $thumbnailList->readObjects(); - foreach ($thumbnailList as $thumbnail) { - $this->avatar->addThumbnail($thumbnail); - } + $this->avatar = $fileList->getSingleObject(); UserStorageHandler::getInstance()->update( $this->userID, @@ -371,22 +367,6 @@ class UserProfile extends DatabaseObjectDecorator implements ITitledLinkObject } else { $this->avatar = \unserialize($data); } - } elseif ($this->avatarID) { - if (!$this->fileHash) { - $data = UserStorageHandler::getInstance()->getField('avatar', $this->userID); - if ($data === null) { - $this->avatar = new UserAvatar($this->avatarID); - UserStorageHandler::getInstance()->update( - $this->userID, - 'avatar', - \serialize($this->avatar) - ); - } else { - $this->avatar = \unserialize($data); - } - } else { - $this->avatar = new UserAvatar(null, $this->getDecoratedObject()->data); - } } else { $parameters = ['avatar' => null]; EventHandler::getInstance()->fireAction($this, 'getAvatar', $parameters); diff --git a/wcfsetup/install/files/lib/data/user/UserProfileList.class.php b/wcfsetup/install/files/lib/data/user/UserProfileList.class.php index 869b66fbcd..61d30aa0fe 100644 --- a/wcfsetup/install/files/lib/data/user/UserProfileList.class.php +++ b/wcfsetup/install/files/lib/data/user/UserProfileList.class.php @@ -2,8 +2,6 @@ namespace wcf\data\user; -use wcf\data\file\FileList; - /** * Represents a list of user profiles. * @@ -19,6 +17,8 @@ use wcf\data\file\FileList; */ class UserProfileList extends UserList { + use TUserAvatarObjectList; + /** * @inheritDoc */ @@ -29,8 +29,6 @@ class UserProfileList extends UserList */ public $decoratorClassName = UserProfile::class; - public bool $loadAvatarFiles = true; - /** * @inheritDoc */ @@ -62,33 +60,4 @@ class UserProfileList extends UserList $this->loadAvatarFiles(); } - - protected function loadAvatarFiles(): void - { - if (!$this->loadAvatarFiles) { - return; - } - - $avatarFileIDs = []; - foreach ($this->objects as $user) { - if ($user->avatarFileID !== null) { - $avatarFileIDs[] = $user->avatarFileID; - } - } - if ($avatarFileIDs === []) { - return; - } - - $fileList = new FileList(); - $fileList->loadThumbnails = true; - $fileList->setObjectIDs($avatarFileIDs); - $fileList->readObjects(); - $files = $fileList->getObjects(); - - foreach ($this->objects as $user) { - if ($user->avatarFileID !== null) { - $user->setFileAvatar($files[$user->avatarFileID]); - } - } - } } diff --git a/wcfsetup/install/files/lib/data/user/follow/UserFollowerList.class.php b/wcfsetup/install/files/lib/data/user/follow/UserFollowerList.class.php index d98244c995..5f75ea3e37 100644 --- a/wcfsetup/install/files/lib/data/user/follow/UserFollowerList.class.php +++ b/wcfsetup/install/files/lib/data/user/follow/UserFollowerList.class.php @@ -2,6 +2,7 @@ namespace wcf\data\user\follow; +use wcf\data\user\TUserAvatarObjectList; use wcf\data\user\User; use wcf\data\user\UserProfile; @@ -20,6 +21,8 @@ use wcf\data\user\UserProfile; */ class UserFollowerList extends UserFollowList { + use TUserAvatarObjectList; + /** * @inheritDoc */ @@ -48,12 +51,17 @@ class UserFollowerList extends UserFollowList parent::__construct(); $this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar"; - $this->sqlSelects .= ", user_avatar.*"; $this->sqlJoins .= " LEFT JOIN wcf1_user user_table - ON user_table.userID = user_follow.userID - LEFT JOIN wcf1_user_avatar user_avatar - ON user_avatar.avatarID = user_table.avatarID"; + ON user_table.userID = user_follow.userID"; + } + + #[\Override] + public function readObjects() + { + parent::readObjects(); + + $this->loadAvatarFiles(); } } diff --git a/wcfsetup/install/files/lib/data/user/follow/UserFollowingList.class.php b/wcfsetup/install/files/lib/data/user/follow/UserFollowingList.class.php index 8d266ce42f..04e5741b58 100644 --- a/wcfsetup/install/files/lib/data/user/follow/UserFollowingList.class.php +++ b/wcfsetup/install/files/lib/data/user/follow/UserFollowingList.class.php @@ -25,15 +25,13 @@ class UserFollowingList extends UserFollowerList { UserFollowList::__construct(); - $this->sqlSelects .= "user_avatar.*, user_follow.followID, user_option_value.*"; + $this->sqlSelects .= "user_follow.followID, user_option_value.*"; $this->sqlJoins .= " LEFT JOIN wcf1_user user_table ON user_table.userID = user_follow.followUserID LEFT JOIN wcf1_user_option_value user_option_value - ON user_option_value.userID = user_table.userID - LEFT JOIN wcf1_user_avatar user_avatar - ON user_avatar.avatarID = user_table.avatarID"; + ON user_option_value.userID = user_table.userID"; $this->sqlSelects .= ", user_table.*"; } diff --git a/wcfsetup/install/files/lib/data/user/ignore/ViewableUserIgnoreList.class.php b/wcfsetup/install/files/lib/data/user/ignore/ViewableUserIgnoreList.class.php index 3a682cd71c..7a46f42dd6 100644 --- a/wcfsetup/install/files/lib/data/user/ignore/ViewableUserIgnoreList.class.php +++ b/wcfsetup/install/files/lib/data/user/ignore/ViewableUserIgnoreList.class.php @@ -2,6 +2,7 @@ namespace wcf\data\user\ignore; +use wcf\data\user\TUserAvatarObjectList; use wcf\data\user\User; use wcf\data\user\UserProfile; @@ -14,6 +15,8 @@ use wcf\data\user\UserProfile; */ class ViewableUserIgnoreList extends UserIgnoreList { + use TUserAvatarObjectList; + /** * @inheritDoc */ @@ -46,16 +49,21 @@ class ViewableUserIgnoreList extends UserIgnoreList } $this->sqlSelects .= "user_ignore.ignoreID"; $this->sqlSelects .= ", user_option_value.*"; - $this->sqlSelects .= ", user_avatar.*"; $this->sqlJoins .= " LEFT JOIN wcf1_user user_table ON user_table.userID = user_ignore.ignoreUserID LEFT JOIN wcf1_user_option_value user_option_value - ON user_option_value.userID = user_table.userID - LEFT JOIN wcf1_user_avatar user_avatar - ON user_avatar.avatarID = user_table.avatarID"; + ON user_option_value.userID = user_table.userID"; $this->sqlSelects .= ", user_table.*"; } + + #[\Override] + public function readObjects() + { + parent::readObjects(); + + $this->loadAvatarFiles(); + } } diff --git a/wcfsetup/install/files/lib/data/user/online/UsersOnlineList.class.php b/wcfsetup/install/files/lib/data/user/online/UsersOnlineList.class.php index 06b342d873..8dfdccd6de 100644 --- a/wcfsetup/install/files/lib/data/user/online/UsersOnlineList.class.php +++ b/wcfsetup/install/files/lib/data/user/online/UsersOnlineList.class.php @@ -5,6 +5,7 @@ namespace wcf\data\user\online; use wcf\data\option\OptionAction; use wcf\data\session\SessionList; use wcf\data\user\group\UserGroup; +use wcf\data\user\TUserAvatarObjectList; use wcf\data\user\User; use wcf\data\user\UserProfile; use wcf\system\event\EventHandler; @@ -26,6 +27,8 @@ use wcf\util\StringUtil; */ class UsersOnlineList extends SessionList { + use TUserAvatarObjectList; + /** * @inheritDoc */ @@ -55,7 +58,7 @@ class UsersOnlineList extends SessionList { parent::__construct(); - $this->sqlSelects .= "user_avatar.*, user_option_value.*, user_group.userOnlineMarking, user_table.*"; + $this->sqlSelects .= "user_option_value.*, user_group.userOnlineMarking, user_table.*"; $this->sqlConditionJoins .= " LEFT JOIN wcf1_user user_table @@ -65,8 +68,6 @@ class UsersOnlineList extends SessionList ON user_table.userID = session.userID LEFT JOIN wcf1_user_option_value user_option_value ON user_option_value.userID = user_table.userID - LEFT JOIN wcf1_user_avatar user_avatar - ON user_avatar.avatarID = user_table.avatarID LEFT JOIN wcf1_user_group user_group ON user_group.groupID = user_table.userOnlineGroupID"; @@ -92,6 +93,8 @@ class UsersOnlineList extends SessionList } $this->objectIDs = $this->indexToObject; $this->rewind(); + + $this->loadAvatarFiles(); } /** diff --git a/wcfsetup/install/files/lib/data/user/profile/visitor/UserProfileVisitorList.class.php b/wcfsetup/install/files/lib/data/user/profile/visitor/UserProfileVisitorList.class.php index 39233b8bd9..7e89957688 100644 --- a/wcfsetup/install/files/lib/data/user/profile/visitor/UserProfileVisitorList.class.php +++ b/wcfsetup/install/files/lib/data/user/profile/visitor/UserProfileVisitorList.class.php @@ -3,6 +3,7 @@ namespace wcf\data\user\profile\visitor; use wcf\data\DatabaseObjectList; +use wcf\data\user\TUserAvatarObjectList; use wcf\data\user\User; use wcf\data\user\UserProfile; @@ -21,6 +22,8 @@ use wcf\data\user\UserProfile; */ class UserProfileVisitorList extends DatabaseObjectList { + use TUserAvatarObjectList; + /** * @inheritDoc */ @@ -44,12 +47,17 @@ class UserProfileVisitorList extends DatabaseObjectList parent::__construct(); $this->sqlSelects .= "user_table.username, user_table.email, user_table.disableAvatar"; - $this->sqlSelects .= ", user_avatar.*"; $this->sqlJoins .= " LEFT JOIN wcf1_user user_table - ON user_table.userID = user_profile_visitor.userID - LEFT JOIN wcf1_user_avatar user_avatar - ON user_avatar.avatarID = user_table.avatarID"; + ON user_table.userID = user_profile_visitor.userID"; + } + + #[\Override] + public function readObjects() + { + parent::readObjects(); + + $this->loadAvatarFiles(); } }