From 9267829ceaf48aef8c54aac13c31a0a9bcb748b0 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Wed, 15 Nov 2023 06:49:48 -0600 Subject: [PATCH] Fix how invalid problem ids from set definition files are handled. This identifies the maximum valid problem id, and then invalid problem ids that are found use one more than that. Of course the max is incremented for later invalid problem ids. This is the simplest approach. So this gives the following numberings: set def -> result `0,1,2,3` -> `1,2,3,4` `0,2,3,4` -> `2,3,4,5` `0,1,2,5` -> `1,2,5,6` Another option that could be implemented is to fill when gaps in the valid numbers are found. That takes a bit more work, but could be done. --- lib/WeBWorK/File/SetDef.pm | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/WeBWorK/File/SetDef.pm b/lib/WeBWorK/File/SetDef.pm index 6a3c9b409c..ab7805e723 100644 --- a/lib/WeBWorK/File/SetDef.pm +++ b/lib/WeBWorK/File/SetDef.pm @@ -194,13 +194,13 @@ sub importSetsFromDef ($ce, $db, $setDefFiles, $existingSets = undef, $assign = debug("$set_definition_file: adding problems to database"); # Add problems - my $freeProblemID = WeBWorK::Utils::max($db->listGlobalProblems($setData->{setID})) + 1; + my $freeProblemID = WeBWorK::Utils::max(grep { $_ } map { $_->{problem_id} } @{ $setData->{problemData} }) + 1; for my $rh_problem (@{ $setData->{problemData} }) { addProblemToSet( $db, $ce->{problemDefaults}, setName => $setData->{setID}, sourceFile => $rh_problem->{source_file}, - problemID => $rh_problem->{problem_id} ? $rh_problem->{problem_id} : $freeProblemID++, + problemID => $rh_problem->{problem_id} || $freeProblemID++, value => $rh_problem->{value}, maxAttempts => $rh_problem->{max_attempts}, showMeAnother => $rh_problem->{showMeAnother},