Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent a NULL title from being saved in the database when a course is created/copied. #2516

Merged
merged 2 commits into from
Aug 17, 2024

Conversation

drgrice1
Copy link
Sponsor Member

Also don't use an undefined course title on the course home page. Note that a NULL setting in the database becomes undef when converted to a Perl scalar value.

This fixes issue #2515 and probably #2497 as well.

Copy link
Contributor

@somiaj somiaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes the issue. Tested that it fixes the warning if courseTitle is NULL and also prevents copying over the courseTitle in the settings table if it doesn't exist in the source course.

…s created/copied.

Also don't use an undefined course title on the course home page.  Note
that a NULL setting in the database becomes undef when converted to a
Perl scalar value.
@drgrice1
Copy link
Sponsor Member Author

By the way, with the approach I used a course title or institution of 0 is not allowed. Should it be?

@Alex-Jordan
Copy link
Contributor

I think it should be allowed. Just to be consistent since we let other things be "0" (like set ids).

@drgrice1
Copy link
Sponsor Member Author

Okay, so a course title or institution of 0 is now also allowed.

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')) // '';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This brings to my attention that we also cannot have a course named "0". Is that what we want? I don't think I would ever name a course "0", but I could see someone doing that as some sort of orientation or training course. Maybe.

If you try to create a course named "0" right now using the admin course, you are met with "You must specify a course ID.". And for anyone who is not a perl cognoscente, you would think "But I did!".

I feel like trim_spaces is part of what is broken here and it should not turn 0 into ``. That is not consistent with what the name of the macro suggests it does.

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree that trim_spaces is not doing the right thing. I thought about changing that, but if we do so we need to review all of its uses. There aren't so many of them, so that isn't that hard. Most of the uses are in this file, there is one usage in lib/WeBWorK/Utils.pm (for the password), and the rest are in lib/WeBWorK/ContentGenerator/Instructor/AddUsers.pm.

As to allowing a course id of "0", that may be problematic. I considered changing it when I did this, but then thought that there may be problems with that. The course title is only used in a few places, so it doesn't take much to make sure that is okay. The course institution isn't actually used at all, and is purely something saved in the database (not sure why we have it). The course id, on the other hand, is used everywhere. So it would take some time to verify that everything will work okay with it being "0".

Copy link
Sponsor Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend that any fix for trim_spaces or allowing the course id to be "0" not be done in this pull request since this is paired with a hot fix pull request. Keep the two the same. Those things can be done in another pull request.

@Alex-Jordan Alex-Jordan merged commit 0480b83 into openwebwork:develop Aug 17, 2024
2 checks passed
somiaj added a commit that referenced this pull request Aug 17, 2024
Prevent a NULL title from being saved in the database when a course is created/copied (hotfix of #2516)
This was referenced Aug 17, 2024
@drgrice1 drgrice1 deleted the bugfix/null-course-title branch August 17, 2024 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants