MDL-71370 course: Make showcompletionconditions nullable

* When completion tracking is not enabled for the course, it does not
make sense for the course's showcompletionconditions setting to
be set according to the default value indicated by the
"moodlecourse | showcompletionconditions" admin setting. Setting
showcompletionconditions as enabled when completion tracking is disabled
makes even less sense. So in such a case, we should not be setting a
default value for showcompletionconditions and allow it to be null.

* When the course is edited and completion tracking is enabled, this
also would set the "Show completion conditions" field to default to the
value set in the "moodlecourse | showcompletionconditions" admin
setting.
This commit is contained in:
Jun Pataleta
2021-04-24 19:07:42 +08:00
parent 146a38dc45
commit fca42002f7
6 changed files with 67 additions and 16 deletions
+21
View File
@@ -2621,5 +2621,26 @@ function xmldb_main_upgrade($oldversion) {
upgrade_main_savepoint(true, 2021052500.85);
}
if ($oldversion < 2021052500.87) {
// Changing the default of field showcompletionconditions on table course to 0.
$table = new xmldb_table('course');
$field = new xmldb_field('showcompletionconditions', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'showactivitydates');
// Launch change of nullability for field showcompletionconditions.
$dbman->change_field_notnull($table, $field);
// Launch change of default for field showcompletionconditions.
$dbman->change_field_default($table, $field);
// Set showcompletionconditions to null for courses which don't track completion.
$sql = "UPDATE {course}
SET showcompletionconditions = null
WHERE enablecompletion <> 1";
$DB->execute($sql);
// Main savepoint reached.
upgrade_main_savepoint(true, 2021052500.87);
}
return true;
}