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; }