Skip to content

Commit

Permalink
Fix how invalid problem ids from set definition files are handled.
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
drgrice1 committed Nov 15, 2023
1 parent 759c3b9 commit 9267829
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions lib/WeBWorK/File/SetDef.pm
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down

0 comments on commit 9267829

Please sign in to comment.