diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 313c252398a..84507759b7d 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -4536,5 +4536,16 @@ privatefiles,moodle|/user/files.php'; upgrade_main_savepoint(true, 2022041901.07); } + if ($oldversion < 2022041904.03) { + + // Remove any orphaned tag instance records (pointing to non-existing context). + $DB->delete_records_select('tag_instance', 'NOT EXISTS ( + SELECT ctx.id FROM {context} ctx WHERE ctx.id = {tag_instance}.contextid + )'); + + // Main savepoint reached. + upgrade_main_savepoint(true, 2022041904.03); + } + return true; } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index e979690b8fd..d0e564461f3 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5186,6 +5186,10 @@ function remove_course_contents($courseid, $showfeedback = true, array $options question_delete_activity($cm); // Notify the competency subsystem. \core_competency\api::hook_course_module_deleted($cm); + + // Delete all tag instances associated with the instance of this module. + core_tag_tag::delete_instances("mod_{$modname}", null, context_module::instance($cm->id)->id); + core_tag_tag::remove_all_item_tags('core', 'course_modules', $cm->id); } if (function_exists($moddelete)) { // This purges all module data in related tables, extra user prefs, settings, etc. diff --git a/version.php b/version.php index c4633a2355b..c96b893441b 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2022041904.02; // 20220419 = branching date YYYYMMDD - do not modify! +$version = 2022041904.03; // 20220419 = branching date YYYYMMDD - do not modify! // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.0.4+ (Build: 20220922)'; // Human-friendly version name