Skip to content

Commit

Permalink
Issue catalyst#447 - Add additional validation when getting links for…
Browse files Browse the repository at this point in the history
… missing files
  • Loading branch information
guillogo committed Nov 22, 2021
1 parent dc5d7ac commit 92b6187
Showing 1 changed file with 13 additions and 5 deletions.
18 changes: 13 additions & 5 deletions classes/local/table/files_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ class files_table extends \table_sql {
public function __construct($uniqueid, $objectlocation) {
parent::__construct($uniqueid);

$fields = 'f.*, ctx.instanceid';
$fields = 'f.*, ctx.instanceid, ctx.contextlevel';
$from = '{files} f';
$from .= ' LEFT JOIN {tool_objectfs_objects} o on f.contenthash = o.contenthash';
$from .= ' LEFT JOIN {context} ctx ON f.contextid = ctx.id';
Expand Down Expand Up @@ -113,11 +113,19 @@ public function col_link(\stdClass $row) {
global $DB;

if (substr($row->component, 0, strlen('mod_')) === "mod_") {
list ($course, $cm) = get_course_and_cm_from_cmid($row->instanceid);
if (!empty($cm)) {
$url = new \moodle_url($cm->url);
switch ((int)$row->contextlevel) {
case CONTEXT_MODULE:
list ($course, $cm) = get_course_and_cm_from_cmid($row->instanceid);
if (!empty($cm)) {
$url = new \moodle_url($cm->url);
}
break;
case CONTEXT_COURSE:
$url = new \moodle_url("/course/view.php", ['id' => $row->instanceid]);
break;
default:
// Do nothing for now, in the future this can handle other contexts.
}

} else if ($row->component === 'course') {
if ($row->filearea === "legacy") {
$params = ['contextid' => $row->contextid];
Expand Down

0 comments on commit 92b6187

Please sign in to comment.