mirror of
https://github.com/moodle/moodle.git
synced 2025-08-06 01:16:44 +02:00
MDL-67116 course: Strict empty string check required
In PHP the following are true: assert('' == ''); assert(0 == ''); assert(null == ''); The options in the course completion settings are now: '' => none selected [int] => itemnumber of activity course completion item. In the case where the itemnumber was 0 this was being incorrectly evaluated as an empty string due to the implicit cast to int of the empty string: (int) '' === 0 As a result, the non-strict comparison means that the following are identical: assert(0 == ''); assert(0 == (int) ''); assert(0 == '0'); Changing the comparison to a strict comparison is correct because it ensures the type consitency between the empty string value, and the int of itemnumber 0. It is safe because the value always comes from the form, where an int is always returned, and not the DB, where a string is returned.
This commit is contained in:
parent
c035141971
commit
0a5a2ca89b
1 changed files with 2 additions and 3 deletions
|
@ -72,7 +72,7 @@ function add_moduleinfo($moduleinfo, $course, $mform = null) {
|
|||
$completion = new completion_info($course);
|
||||
if ($completion->is_enabled()) {
|
||||
$newcm->completion = $moduleinfo->completion;
|
||||
if ($moduleinfo->completiongradeitemnumber == '') {
|
||||
if ($moduleinfo->completiongradeitemnumber === '') {
|
||||
$newcm->completiongradeitemnumber = null;
|
||||
} else {
|
||||
$newcm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
|
||||
|
@ -527,8 +527,7 @@ function update_moduleinfo($cm, $moduleinfo, $course, $mform = null) {
|
|||
// Completion settings that would affect users who have already completed
|
||||
// the activity may be locked; if so, these should not be updated.
|
||||
if (!empty($moduleinfo->completionunlocked)) {
|
||||
$cm->completion = $moduleinfo->completion;
|
||||
if ($moduleinfo->completiongradeitemnumber == '') {
|
||||
if ($moduleinfo->completiongradeitemnumber === '') {
|
||||
$cm->completiongradeitemnumber = null;
|
||||
} else {
|
||||
$cm->completiongradeitemnumber = $moduleinfo->completiongradeitemnumber;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue