MDL-57730 core_calendar: handle '0' as a courseid

User overrides set the course id as 0 in the events table
(Moodle can be stupid). We need to deal with this.

Part of MDL-55611 epic.
This commit is contained in:
Mark Nelson 2017-02-23 17:06:44 +08:00 committed by Damyon Wiese
parent 5e6e3babf4
commit bb19f80414

View File

@ -87,12 +87,15 @@ abstract class event_abstract_factory implements event_factory_interface {
$module = null;
$subscription = null;
if ($dbrow->courseid) {
$course = new std_proxy($dbrow->courseid, function($id) use ($coursecache) {
return \core_calendar\api::get_course_cached($coursecache, $id);
});
if ($dbrow->courseid == 0) {
$cm = get_coursemodule_from_instance($dbrow->modulename, $dbrow->instance);
$dbrow->courseid = get_course($cm->course)->id;
}
$course = new std_proxy($dbrow->courseid, function($id) use ($coursecache) {
return \core_calendar\api::get_course_cached($coursecache, $id);
});
if ($dbrow->groupid) {
$group = new std_proxy($dbrow->groupid, function($id) {
return \core_calendar\api::get_group_cached($id);