Skip to content

Commit

Permalink
MDL-82958 user: Return general error if course/context not valid
Browse files Browse the repository at this point in the history
  • Loading branch information
mickhawkins committed Sep 19, 2024
1 parent 3d2052d commit 5895b0e
Showing 1 changed file with 13 additions and 8 deletions.
21 changes: 13 additions & 8 deletions user/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,21 @@
'id' => $courseid,
'newcourse' => $newcourse));

if ($contextid) {
$context = context::instance_by_id($contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSE) {
throw new \moodle_exception('invalidcontext');
try {
if ($contextid) {
$context = context::instance_by_id($contextid, MUST_EXIST);
if ($context->contextlevel != CONTEXT_COURSE) {
throw new \moodle_exception('invaliddata');
}
$course = $DB->get_record('course', ['id' => $context->instanceid], '*', MUST_EXIST);
} else {
$course = $DB->get_record('course', ['id' => $courseid], '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
}
$course = $DB->get_record('course', array('id' => $context->instanceid), '*', MUST_EXIST);
} else {
$course = $DB->get_record('course', array('id' => $courseid), '*', MUST_EXIST);
$context = context_course::instance($course->id, MUST_EXIST);
} catch (\dml_exception $e) {
throw new \moodle_exception('invaliddata');
}

// Not needed anymore.
unset($contextid);
unset($courseid);
Expand Down

0 comments on commit 5895b0e

Please sign in to comment.