Skip to content

Commit

Permalink
Handle assignment missing when fetching content (#13)
Browse files Browse the repository at this point in the history
Using "MUST_EXIST" throws an error if the assignment course module is
missing or multiple assignments match the criteria, making the course
inaccessible, as the error thrown by the block module bubbles up.

This change catches the trown exceptions and displays the "no assignment
selected" message as the content.

Signed-off-by: Darius Mihai <[email protected]>
  • Loading branch information
darius-m authored Oct 17, 2024
1 parent 9aa8e38 commit 4b63b54
Showing 1 changed file with 6 additions and 1 deletion.
7 changes: 6 additions & 1 deletion block_vmchecker.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,12 @@ public function get_content() {
return $this->content;
}

$cm = get_coursemodule_from_instance('assign', $this->config->assignment, 0, false, MUST_EXIST);
try {
$cm = get_coursemodule_from_instance('assign', $this->config->assignment, 0, false, MUST_EXIST);
} catch (dml_missing_record_exception | dml_multiple_records_exception $e) {
$this->content->text = get_string('no_assignment_selected', 'block_vmchecker');
return $this->content;
}
$context = \context_module::instance($cm->id);

$assign = new \assign($context, null, null);
Expand Down

0 comments on commit 4b63b54

Please sign in to comment.