Skip to content

Commit 09048cf

Browse files
committed
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.
1 parent fdb5b27 commit 09048cf

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

wcfsetup/install/files/lib/system/worker/UserRebuildDataWorker.class.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use wcf\data\user\User;
1212
use wcf\data\user\UserEditor;
1313
use wcf\data\user\UserList;
14+
use wcf\data\user\UserProfile;
1415
use wcf\data\user\UserProfileAction;
1516
use wcf\data\user\UserProfileList;
1617
use wcf\system\bbcode\BBCodeHandler;
@@ -48,6 +49,7 @@ protected function initObjectList()
4849
parent::initObjectList();
4950

5051
$this->objectList->sqlSelects = 'user_option_value.userOption' . User::getUserOptionID('aboutMe') . ' AS aboutMe';
52+
$this->objectList->sqlSelects .= ',user_option_value.userOption' . User::getUserOptionID('canViewOnlineStatus') . ' AS canViewOnlineStatus';
5153
$this->objectList->sqlJoins = "
5254
LEFT JOIN wcf" . WCF_N . "_user_option_value user_option_value
5355
ON user_option_value.userID = user_table.userID";
@@ -74,6 +76,8 @@ public function execute()
7476
$action->executeAction();
7577
}
7678

79+
$this->updateUserOnlineStatus($users);
80+
7781
if (!empty($userIDs)) {
7882
// update article counter
7983
$conditionBuilder = new PreparedStatementConditionBuilder();
@@ -334,4 +338,28 @@ public function execute()
334338
}
335339
}
336340
}
341+
342+
/**
343+
* This method checks whether a user has restricted the visibility of their online status in the past,
344+
* but has since lost the permission for it.
345+
* In this case, the visibility of the online status is automatically set to default.
346+
*
347+
* @param UserEditor[] $users
348+
*/
349+
private function updateUserOnlineStatus(array $users): void
350+
{
351+
foreach ($users as $user) {
352+
if (!$user->canViewOnlineStatus) {
353+
continue;
354+
}
355+
$userProfile = new UserProfile($user->getDecoratedObject());
356+
if ($userProfile->getPermission('user.profile.canHideOnlineStatus')) {
357+
continue;
358+
}
359+
360+
$user->updateUserOptions([
361+
User::getUserOptionID('canViewOnlineStatus') => 0,
362+
]);
363+
}
364+
}
337365
}

0 commit comments

Comments
 (0)