From: Matthias Schmidt Date: Sat, 6 Apr 2019 10:07:19 +0000 (+0200) Subject: Restrict numbers of automatic user group assignments in cronjob X-Git-Tag: 5.2.0_Beta_2~10^2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=f865c3df7afb4686b9c5a11174a49516808d250c;p=GitHub%2FWoltLab%2FWCF.git Restrict numbers of automatic user group assignments in cronjob Close #2883 (cherry picked from commit e1a4b3bd0f0d474d503940f477f4f768373bbc11) --- diff --git a/wcfsetup/install/files/lib/system/cronjob/UserGroupAssignmentCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/UserGroupAssignmentCronjob.class.php index 374d2c12e0..07dddaf37e 100644 --- a/wcfsetup/install/files/lib/system/cronjob/UserGroupAssignmentCronjob.class.php +++ b/wcfsetup/install/files/lib/system/cronjob/UserGroupAssignmentCronjob.class.php @@ -14,6 +14,8 @@ use wcf\system\user\group\assignment\UserGroupAssignmentHandler; * @package WoltLabSuite\Core\System\Cronjob */ class UserGroupAssignmentCronjob extends AbstractCronjob { + const MAXIMUM_ASSIGNMENTS = 1000; + /** * @inheritDoc */ @@ -22,12 +24,20 @@ class UserGroupAssignmentCronjob extends AbstractCronjob { $assignments = UserGroupAssignmentCacheBuilder::getInstance()->getData(); $usersToGroup = []; + + $assignmentCount = 0; foreach ($assignments as $assignment) { if (!isset($usersToGroup[$assignment->groupID])) { $usersToGroup[$assignment->groupID] = []; } - $usersToGroup[$assignment->groupID] = array_merge($usersToGroup[$assignment->groupID], UserGroupAssignmentHandler::getInstance()->getUsers($assignment)); + $newUsers = UserGroupAssignmentHandler::getInstance()->getUsers($assignment, self::MAXIMUM_ASSIGNMENTS); + $usersToGroup[$assignment->groupID] = array_merge($usersToGroup[$assignment->groupID], $newUsers); + + $assignmentCount += count($newUsers); + if ($assignmentCount > self::MAXIMUM_ASSIGNMENTS) { + break; + } } foreach ($usersToGroup as $groupID => $users) { diff --git a/wcfsetup/install/files/lib/system/user/group/assignment/UserGroupAssignmentHandler.class.php b/wcfsetup/install/files/lib/system/user/group/assignment/UserGroupAssignmentHandler.class.php index f18e4a97e0..6fd7ff93ff 100644 --- a/wcfsetup/install/files/lib/system/user/group/assignment/UserGroupAssignmentHandler.class.php +++ b/wcfsetup/install/files/lib/system/user/group/assignment/UserGroupAssignmentHandler.class.php @@ -91,13 +91,17 @@ class UserGroupAssignmentHandler extends SingletonFactory { * assignment. * * @param UserGroupAssignment $assignment + * @param integer $maxUsers * @return User[] */ - public function getUsers(UserGroupAssignment $assignment) { + public function getUsers(UserGroupAssignment $assignment, $maxUsers = null) { $userList = new UserList(); $userList->getConditionBuilder()->add('user_table.userID NOT IN (SELECT userID FROM wcf'.WCF_N.'_user_to_group WHERE groupID = ?)', [ $assignment->groupID ]); + if ($maxUsers !== null) { + $userList->sqlLimit = $maxUsers; + } $conditions = $assignment->getConditions(); foreach ($conditions as $condition) {