* @package WoltLabSuite\Core\System\Cronjob
*/
class UserGroupAssignmentCronjob extends AbstractCronjob {
+ const MAXIMUM_ASSIGNMENTS = 1000;
+
/**
* @inheritDoc
*/
$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) {
* 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) {