From fd583ac9f08a4ad2510361b540a11ba87a3de7f5 Mon Sep 17 00:00:00 2001 From: Paul Holden Date: Mon, 5 Sep 2022 22:27:37 +0100 Subject: [PATCH] MDL-75168 tag: cleanup module tag instances upon course deletion. --- lib/db/upgrade.php | 11 +++++++++++ lib/moodlelib.php | 4 ++++ version.php | 2 +- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/lib/db/upgrade.php b/lib/db/upgrade.php index 784f41923df..97776ccba2f 100644 --- a/lib/db/upgrade.php +++ b/lib/db/upgrade.php @@ -2914,5 +2914,16 @@ privatefiles,moodle|/user/files.php'; upgrade_main_savepoint(true, 2022091000.01); } + if ($oldversion < 2022092200.01) { + + // 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, 2022092200.01); + } + return true; } diff --git a/lib/moodlelib.php b/lib/moodlelib.php index fb26c16ad80..6727ed82615 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5189,6 +5189,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 85428f6c3c6..0dc902db353 100644 --- a/version.php +++ b/version.php @@ -29,7 +29,7 @@ defined('MOODLE_INTERNAL') || die(); -$version = 2022092200.00; // YYYYMMDD = weekly release date of this DEV branch. +$version = 2022092200.01; // YYYYMMDD = weekly release date of this DEV branch. // RR = release increments - 00 in DEV branches. // .XX = incremental changes. $release = '4.1dev (Build: 20220922)'; // Human-friendly version name