-
Bug
-
Resolution: Fixed
-
Minor
-
3.3
-
MOODLE_33_STABLE
-
MOODLE_32_STABLE, MOODLE_33_STABLE
-
wip-
MDL-59308-master -
In the course_delete_module function the module instance gets deleted before all events get removed.
All events get constructed during the removal process.
// Delete events from calendar.
|
if ($events = $DB->get_records('event', array('instance' => $cm->instance, 'modulename' => $modulename))) { |
foreach($events as $event) {
|
$calendarevent = calendar_event::load($event);
|
$calendarevent->delete();
|
}
|
}
|
In the calendar_event constructor the context in calculated. In this calculate_context function it may hit the get_course_module_from_instance which require the module instance in the db we deleted before.
protected function calculate_context() { |
global $USER, $DB;
|
|
$context = null; |
if (isset($this->properties->courseid) && $this->properties->courseid > 0) { |
$context = \context_course::instance($this->properties->courseid); |
} else if (isset($this->properties->course) && $this->properties->course > 0) { |
$context = \context_course::instance($this->properties->course); |
} else if (isset($this->properties->groupid) && $this->properties->groupid > 0) { |
$group = $DB->get_record('groups', array('id' => $this->properties->groupid)); |
$context = \context_course::instance($group->courseid);
|
} else if (isset($this->properties->userid) && $this->properties->userid > 0 |
&& $this->properties->userid == $USER->id) { |
$context = \context_user::instance($this->properties->userid); |
} else if (isset($this->properties->userid) && $this->properties->userid > 0 |
&& $this->properties->userid != $USER->id && |
isset($this->properties->instance) && $this->properties->instance > 0) { |
$cm = get_coursemodule_from_instance($this->properties->modulename, $this->properties->instance, 0, |
false, MUST_EXIST); |
$context = \context_course::instance($cm->course);
|
} else { |
$context = \context_user::instance($this->properties->userid); |
}
|
|
return $context; |
}
|
My solution to this would be to move the event removal before the module instance deletion.
- caused a regression
-
MDL-59441 calendar/tests/container_test.php wrongly assumes that all modules already support generators
-
- Closed
-