From d70cfe4c8c28dcf5407d44134f284be1d33e7139 Mon Sep 17 00:00:00 2001 From: Ferran Recio Date: Thu, 16 Sep 2021 09:13:06 +0200 Subject: [PATCH] MDL-72566 completion: fix missing mod bug MDL-71899 produces a regression. When an activity plugin is not present but it has activities in the DB the course view returns an exception. With this patch the code will ignore missing modules when calculating the completion. --- lib/completionlib.php | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/lib/completionlib.php b/lib/completionlib.php index eed0e751f8f..6198cf49728 100644 --- a/lib/completionlib.php +++ b/lib/completionlib.php @@ -1063,20 +1063,25 @@ class completion_info { INNER JOIN {modules} m ON m.id = cm.module WHERE m.visible = 1 AND cm.course = ?", [$userid, $this->course->id]); + $cminfos = get_fast_modinfo($cm->course, $userid)->get_cms(); + // Reindex by course module id. foreach ($alldatabycmc as $data) { + + // Filter acitivites with no cm_info (missing plugins or other causes). + if (!isset($cminfos[$data->cmid])) { + continue; + } + if (empty($data->coursemoduleid)) { $cacheddata[$data->cmid] = $defaultdata; $cacheddata[$data->cmid]['coursemoduleid'] = $data->cmid; } else { $cacheddata[$data->cmid] = (array) $data; } - // Make sure we're working on a cm_info object. - $cmstd = new stdClass(); - $cmstd->id = $data->cmid; - $cmstd->course = $this->course->id; - $othercminfo = cm_info::create($cmstd, $userid); + // Add the other completion data for this user in this module instance. + $othercminfo = $cminfos[$data->cmid]; $cacheddata[$othercminfo->id] += $this->get_other_cm_completion_data($othercminfo, $userid); }