From e1a4b3bd0f0d474d503940f477f4f768373bbc11 Mon Sep 17 00:00:00 2001 From: Matthias Schmidt Date: Sat, 6 Apr 2019 12:07:19 +0200 Subject: [PATCH] Restrict numbers of automatic user group assignments in cronjob Close #2883 --- .../cronjob/UserGroupAssignmentCronjob.class.php | 12 +++++++++++- .../assignment/UserGroupAssignmentHandler.class.php | 6 +++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/wcfsetup/install/files/lib/system/cronjob/UserGroupAssignmentCronjob.class.php b/wcfsetup/install/files/lib/system/cronjob/UserGroupAssignmentCronjob.class.php index 8ce4230920..5373192882 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 cce2c0b1d9..5080328678 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 @@ -90,13 +90,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) { -- 2.20.1