MDL-72375 completion: Remove id from custom rules

The id stored in the default custom rules was the courseid, and would
incorrectly be applied to new activities as the activity id.
This commit is contained in:
Peter Burnett 2021-08-30 16:33:30 +10:00
parent 222c8cc77c
commit cab836cf8d

View File

@ -416,6 +416,8 @@ class manager {
global $DB;
$courseid = $data->id;
// MDL-72375 Unset the id here, it should not be stored in customrules.
unset($data->id);
$coursecontext = context_course::instance($courseid);
if (!$modids = $data->modids) {
return;
@ -484,6 +486,9 @@ class manager {
if ($data = $DB->get_record('course_completion_defaults', ['course' => $course->id, 'module' => $module->id],
'completion, completionview, completionexpected, completionusegrade, completionpassgrade, customrules')) {
if ($data->customrules && ($customrules = @json_decode($data->customrules, true))) {
// MDL-72375 This will override activity id for new mods. Skip this field, it is already exposed as courseid.
unset($customrules['id']);
if ($flatten) {
foreach ($customrules as $key => $value) {
$data->$key = $value;