Skip to content

Commit e183ba6

Browse files
committed
Hotfix: Prevent error when adding new course.
When adding a new course if the initial instructor entered into the add course form has the same user ID as a user in the course non-student users, sets, and achievements are being copied from, this user gets assigned to sets and achievements twice, causing an error. This skips assigning the initial user to the original sets they may have been assigned to and will always assign the initial user to all sets and achievements, so no error occurs.
1 parent c37af2b commit e183ba6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

lib/WeBWorK/Utils/CourseManagement.pm

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,8 @@ sub addCourse {
402402
}
403403
if ($options{copyNonStudents}) {
404404
foreach my $userTriple (@users) {
405-
my $user_id = $userTriple->[0]{user_id};
405+
my $user_id = $userTriple->[0]{user_id};
406+
next if $user_id eq $initialUser->[0]{user_id}; # Skip, will be assigned to all sets below.
406407
my @user_sets = $db0->listUserSets($user_id);
407408
assignSetsToUsers($db, $ce, \@user_sets, [$user_id]);
408409
}
@@ -425,7 +426,8 @@ sub addCourse {
425426
}
426427
if ($options{copyNonStudents}) {
427428
foreach my $userTriple (@users) {
428-
my $user_id = $userTriple->[0]{user_id};
429+
my $user_id = $userTriple->[0]{user_id};
430+
next if $user_id eq $initialUser->[0]{user_id}; # Skip, was assigned to all achievements above.
429431
my @user_achievements = $db0->listUserAchievements($user_id);
430432
for my $achievement_id (@user_achievements) {
431433
my $userAchievement = $db->newUserAchievement();

0 commit comments

Comments
 (0)