From 09048cf6bef869d1aa938aa89c6b1180ebefacea Mon Sep 17 00:00:00 2001 From: Marcel Werk Date: Fri, 20 Dec 2024 16:09:27 +0100 Subject: [PATCH] Check user online status during user rebuild The new method checks whether a user has restricted the visibility of their online status in the past, but has since lost the permission for it. In this case, the visibility of the online status is automatically set to default. --- .../worker/UserRebuildDataWorker.class.php | 28 +++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php b/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php index a29b883aec..537d52e90c 100644 --- a/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php +++ b/wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php @@ -11,6 +11,7 @@ use wcf\data\user\cover\photo\IWebpUserCoverPhoto; use wcf\data\user\User; use wcf\data\user\UserEditor; use wcf\data\user\UserList; +use wcf\data\user\UserProfile; use wcf\data\user\UserProfileAction; use wcf\data\user\UserProfileList; use wcf\system\bbcode\BBCodeHandler; @@ -48,6 +49,7 @@ final class UserRebuildDataWorker extends AbstractLinearRebuildDataWorker parent::initObjectList(); $this->objectList->sqlSelects = 'user_option_value.userOption' . User::getUserOptionID('aboutMe') . ' AS aboutMe'; + $this->objectList->sqlSelects .= ',user_option_value.userOption' . User::getUserOptionID('canViewOnlineStatus') . ' AS canViewOnlineStatus'; $this->objectList->sqlJoins = " LEFT JOIN wcf" . WCF_N . "_user_option_value user_option_value ON user_option_value.userID = user_table.userID"; @@ -74,6 +76,8 @@ final class UserRebuildDataWorker extends AbstractLinearRebuildDataWorker $action->executeAction(); } + $this->updateUserOnlineStatus($users); + if (!empty($userIDs)) { // update article counter $conditionBuilder = new PreparedStatementConditionBuilder(); @@ -334,4 +338,28 @@ final class UserRebuildDataWorker extends AbstractLinearRebuildDataWorker } } } + + /** + * This method checks whether a user has restricted the visibility of their online status in the past, + * but has since lost the permission for it. + * In this case, the visibility of the online status is automatically set to default. + * + * @param UserEditor[] $users + */ + private function updateUserOnlineStatus(array $users): void + { + foreach ($users as $user) { + if (!$user->canViewOnlineStatus) { + continue; + } + $userProfile = new UserProfile($user->getDecoratedObject()); + if ($userProfile->getPermission('user.profile.canHideOnlineStatus')) { + continue; + } + + $user->updateUserOptions([ + User::getUserOptionID('canViewOnlineStatus') => 0, + ]); + } + } } -- 2.20.1