MDL-86010 competency: Delete competency evidence on cm delete

Evidence recorded against course module competencies was not deleted
with the course module. This led to errors when attempting to view the
competency record on a learning plan.

This change will delete associated evidence records with the cm, and
will clean up any existing orphaned records on upgrade.

Co-Authored-By: Mark Johnson <[email protected]>
This commit is contained in:
Michael Kotlyar
2025-11-06 11:50:22 +08:00
committed by Mihail Geshoski
co-authored by Mark Johnson
parent be0041c992
commit c38c373db5
3 changed files with 13 additions and 1 deletions
+2
View File
@@ -4781,6 +4781,8 @@ class api {
public static function hook_course_module_deleted(stdClass $cm) {
global $DB;
$DB->delete_records(course_module_competency::TABLE, array('cmid' => $cm->id));
$context = context_module::instance($cm->id);
$DB->delete_records(evidence::TABLE, ['contextid' => $context->id]);
}
/**
+10
View File
@@ -2304,5 +2304,15 @@ function xmldb_main_upgrade($oldversion) {
// Automatically generated Moodle v5.1.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2025100600.05) {
// Remove any orphaned competency evidence records (pointing to non-existing contexts).
$DB->delete_records_select('competency_evidence', 'NOT EXISTS (
SELECT ctx.id FROM {context} ctx WHERE ctx.id = {competency_evidence}.contextid
)');
// Main savepoint reached.
upgrade_main_savepoint(true, 2025100600.05);
}
return true;
}
+1 -1
View File
@@ -29,7 +29,7 @@
defined('MOODLE_INTERNAL') || die();
$version = 2025100600.04; // 20251006 = branching date YYYYMMDD - do not modify!
$version = 2025100600.05; // 20251006 = branching date YYYYMMDD - do not modify!
// RR = release increments - 00 in DEV branches.
// .XX = incremental changes.
$release = '5.1+ (Build: 20251030)'; // Human-friendly version name