From 9734d71f395348258e627c9940365bc7ddeee8b8 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Wed, 15 Nov 2023 05:45:31 -0600 Subject: [PATCH 1/2] Correct the problem numbers when a set definition file is imported. Currently the problem numbers in the set defintion file are completely ignored due to a minor mistake. `problem_id` is used in the set definition file, and `problemID` is used by the `WeBWorK::Utils::Instructor::addProblemToSet` method, and I made didn't translate that correctly. --- lib/WeBWorK/File/SetDef.pm | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/WeBWorK/File/SetDef.pm b/lib/WeBWorK/File/SetDef.pm index b461167ae0..6a3c9b409c 100644 --- a/lib/WeBWorK/File/SetDef.pm +++ b/lib/WeBWorK/File/SetDef.pm @@ -200,7 +200,7 @@ sub importSetsFromDef ($ce, $db, $setDefFiles, $existingSets = undef, $assign = $db, $ce->{problemDefaults}, setName => $setData->{setID}, sourceFile => $rh_problem->{source_file}, - problemID => $rh_problem->{problemID} ? $rh_problem->{problemID} : $freeProblemID++, + problemID => $rh_problem->{problem_id} ? $rh_problem->{problem_id} : $freeProblemID++, value => $rh_problem->{value}, maxAttempts => $rh_problem->{max_attempts}, showMeAnother => $rh_problem->{showMeAnother}, From fa9ea06f0cc10e63be7c77a812e5015e49e9c902 Mon Sep 17 00:00:00 2001 From: Glenn Rice Date: Wed, 15 Nov 2023 06:49:48 -0600 Subject: [PATCH 2/2] 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..9fe3c532ca 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},