Skip to content

Commit

Permalink
Merge pull request openwebwork#2517 from drgrice1/bugfix/null-course-…
Browse files Browse the repository at this point in the history
…title-hotfix

Prevent a NULL title from being saved in the database when a course is created/copied (hotfix of openwebwork#2516)
  • Loading branch information
somiaj committed Aug 17, 2024
2 parents 34b9011 + d82e189 commit bbf5108
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 15 deletions.
11 changes: 6 additions & 5 deletions lib/WeBWorK/ContentGenerator.pm
Original file line number Diff line number Diff line change
Expand Up @@ -688,12 +688,13 @@ sub page_title ($c) {
my $db = $c->db;

# If the current route name is 'set_list' and the course has a course title then display that.
if ($c->current_route eq 'set_list' && $db->settingExists('courseTitle')) {
return $db->getSettingValue('courseTitle');
} else {
# Display the route name
return route_title($c, $c->current_route, 1);
if ($c->current_route eq 'set_list') {
my $courseTitle = $db->getSettingValue('courseTitle');
return $courseTitle if defined $courseTitle && $courseTitle ne '';
}

# Display the route name
return route_title($c, $c->current_route, 1);
}

=item webwork_url
Expand Down
6 changes: 3 additions & 3 deletions lib/WeBWorK/ContentGenerator/CourseAdmin.pm
Original file line number Diff line number Diff line change
Expand Up @@ -300,9 +300,9 @@ sub do_add_course ($c) {
my $db = $c->db;
my $authz = $c->authz;

my $add_courseID = trim_spaces($c->param('new_courseID')) // '';
my $add_courseTitle = trim_spaces($c->param('add_courseTitle')) // '';
my $add_courseInstitution = trim_spaces($c->param('add_courseInstitution')) // '';
my $add_courseID = trim_spaces($c->param('new_courseID')) // '';
my $add_courseTitle = ($c->param('add_courseTitle') // '') =~ s/^\s*|\s*$//gr;
my $add_courseInstitution = ($c->param('add_courseInstitution') // '') =~ s/^\s*|\s\*$//gr;

my $add_initial_userID = trim_spaces($c->param('add_initial_userID')) // '';
my $add_initial_password = trim_spaces($c->param('add_initial_password')) // '';
Expand Down
15 changes: 8 additions & 7 deletions lib/WeBWorK/Utils/CourseManagement.pm
Original file line number Diff line number Diff line change
Expand Up @@ -431,10 +431,11 @@ sub addCourse {
# copy title and/or institution if requested
for my $setting ('Title', 'Institution') {
if ($db0 && $options{"copy$setting"}) {
$db->setSettingValue("course$setting", $db0->getSettingValue("course$setting"))
if ($options{"copy$setting"});
my $settingValue = $db0->getSettingValue("course$setting");
$db->setSettingValue("course$setting", $settingValue) if defined $settingValue && $settingValue ne '';
} else {
$db->setSettingValue("course$setting", $options{"course$setting"}) if (exists $options{"course$setting"});
$db->setSettingValue("course$setting", $options{"course$setting"})
if defined $options{"course$setting"} && $options{"course$setting"} ne '';
}
}

Expand Down Expand Up @@ -649,10 +650,10 @@ sub renameCourse {
#update title and institution
my $newDB = new WeBWorK::DB($newCE->{dbLayouts}{$dbLayoutName});
eval {
if (exists($options{courseTitle}) and $options{courseTitle}) {
if (defined $options{courseTitle} && $options{courseTitle} ne '') {
$newDB->setSettingValue('courseTitle', $options{courseTitle});
}
if (exists($options{courseInstitution}) and $options{courseInstitution}) {
if (defined $options{courseInstitution} && $options{courseInstitution} ne '') {
$newDB->setSettingValue('courseInstitution', $options{courseInstitution});
}
};
Expand Down Expand Up @@ -692,10 +693,10 @@ sub retitleCourse {
my $dbLayoutName = $ce->{dbLayoutName};
my $db = new WeBWorK::DB($ce->{dbLayouts}{$dbLayoutName});
eval {
if (exists($options{courseTitle}) and $options{courseTitle}) {
if (defined $options{courseTitle} && $options{courseTitle} ne '') {
$db->setSettingValue('courseTitle', $options{courseTitle});
}
if (exists($options{courseInstitution}) and $options{courseInstitution}) {
if (defined $options{courseInstitution} && $options{courseInstitution} ne '') {
$db->setSettingValue('courseInstitution', $options{courseInstitution});
}
};
Expand Down

0 comments on commit bbf5108

Please sign in to comment.