From b36064f7425a2664dd4c5d7c005ba2a9b95e4687 Mon Sep 17 00:00:00 2001 From: toyomoyo Date: Fri, 23 Mar 2007 07:20:16 +0000 Subject: [PATCH] fix for MDL-9016, clearing context cache after remove_course_content() --- lib/accesslib.php | 9 +++++++++ lib/moodlelib.php | 7 ++++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/lib/accesslib.php b/lib/accesslib.php index feb752605ac..e3c98c6b26d 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -1521,6 +1521,15 @@ function get_context_instance($contextlevel=NULL, $instance=SITEID) { if ($contextlevel == CONTEXT_COURSE && $instance == SITEID) { $contextlevel = CONTEXT_SYSTEM; } + + // fix for MDL-9016 + if ($contextlevel == 'clearcache') { + // Clear ALL cache + $context_cache = array(); + $context_cache_id = array(); + $CONTEXT = ''; + return false; + } /// If no level is supplied then return the current global context if there is one if (empty($contextlevel)) { diff --git a/lib/moodlelib.php b/lib/moodlelib.php index 4253e2e0efd..5c274caa1bf 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -2871,7 +2871,12 @@ function remove_course_contents($courseid, $showfeedback=true) { if ($courseid != SITEID) { delete_context(CONTEXT_COURSE, $course->id); } - + + // fix for MDL-9016 + // clear the cache because the course context is deleted, and + // we don't want to write assignment, overrides and context_rel table + // with this old context id! + get_context_instance('clearcache'); return $result; }