diff --git a/lbplanner/classes/model/module.php b/lbplanner/classes/model/module.php index b0ba0acb..6e7c77ec 100644 --- a/lbplanner/classes/model/module.php +++ b/lbplanner/classes/model/module.php @@ -156,21 +156,33 @@ public function get_cmobj(): \stdClass { global $DB; if ($this->cmobj === null) { if ($this->cmid !== null) { - $this->cmobj = $DB->get_record( + $res = $DB->get_record( modules_helper::COURSE_MODULES_TABLE, ['id' => $this->cmid] ); + if ($res === false) { + throw new \moodle_exception("couldn't get course module with cmid {$this->cmid}"); + } } else { - assert($this->assignid !== null); - $this->cmobj = $DB->get_record( + if ($this->assignid === null) { + throw new \coding_exception('tried to query cmid on a module object without assignid'); + } + $courseid = $this->get_courseid(); + $res = $DB->get_record( modules_helper::COURSE_MODULES_TABLE, [ - 'course' => $this->get_courseid(), + 'course' => $courseid, 'instance' => $this->assignid, 'module' => 1, ] ); + if ($res === false) { + throw new \moodle_exception( + "couldn't get course module with assignid {$this->assignid} and courseid {$courseid}" + ); + } } + $this->cmobj = $res; } return $this->cmobj; }