diff --git a/course/lib.php b/course/lib.php index eab20cf3ef6..5178efc8d77 100644 --- a/course/lib.php +++ b/course/lib.php @@ -2275,7 +2275,7 @@ function create_course($data, $editoroptions = NULL) { cache_helper::purge_by_event('changesincourse'); // new context created - better mark it as dirty - mark_context_dirty($context->path); + $context->mark_dirty(); // Save any custom role names. save_local_role_names($course->id, (array)$data); diff --git a/lib/accesslib.php b/lib/accesslib.php index a3e2a224eb0..7c938cff61d 100644 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -7247,39 +7247,6 @@ function context_instance_preload_sql($joinon, $contextlevel, $tablealias) { return array($select, $join); } -/** - * Mark a context as dirty (with timestamp) so as to force reloading of the context. - * - * @deprecated since 2.2, use $context->mark_dirty() instead - * @param string $path context path - */ -function mark_context_dirty($path) { - global $CFG, $USER, $ACCESSLIB_PRIVATE; - - if (during_initial_install()) { - return; - } - - // only if it is a non-empty string - if (is_string($path) && $path !== '') { - set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout); - if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) { - $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1; - } else { - if (CLI_SCRIPT) { - $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1); - } else { - if (isset($USER->access['time'])) { - $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2); - } else { - $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1); - } - // flags not loaded yet, it will be done later in $context->reload_if_dirty() - } - } - } -} - /** * Remove a context record and any dependent entries, * removes context from static context cache too diff --git a/lib/deprecatedlib.php b/lib/deprecatedlib.php index 90f48bfb501..dbe8f09176b 100644 --- a/lib/deprecatedlib.php +++ b/lib/deprecatedlib.php @@ -4076,3 +4076,38 @@ function print_context_name(context $context, $withprefix = true, $short = false debugging('print_context_name() is deprecated, please use $context->get_context_name() instead.', DEBUG_DEVELOPER); return $context->get_context_name($withprefix, $short); } + +/** + * Mark a context as dirty (with timestamp) so as to force reloading of the context. + * + * @deprecated since 2.2, use $context->mark_dirty() instead + * @see context::mark_dirty() + * @param string $path context path + */ +function mark_context_dirty($path) { + global $CFG, $USER, $ACCESSLIB_PRIVATE; + debugging('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER); + + if (during_initial_install()) { + return; + } + + // only if it is a non-empty string + if (is_string($path) && $path !== '') { + set_cache_flag('accesslib/dirtycontexts', $path, 1, time()+$CFG->sessiontimeout); + if (isset($ACCESSLIB_PRIVATE->dirtycontexts)) { + $ACCESSLIB_PRIVATE->dirtycontexts[$path] = 1; + } else { + if (CLI_SCRIPT) { + $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1); + } else { + if (isset($USER->access['time'])) { + $ACCESSLIB_PRIVATE->dirtycontexts = get_cache_flags('accesslib/dirtycontexts', $USER->access['time']-2); + } else { + $ACCESSLIB_PRIVATE->dirtycontexts = array($path => 1); + } + // flags not loaded yet, it will be done later in $context->reload_if_dirty() + } + } + } +} diff --git a/lib/moodlelib.php b/lib/moodlelib.php index cc6faf0d93a..fac50e81b9d 100644 --- a/lib/moodlelib.php +++ b/lib/moodlelib.php @@ -5237,7 +5237,7 @@ function reset_course_userdata($data) { } $DB->delete_records('role_capabilities', array('contextid'=>$context->id)); //force refresh for logged in users - mark_context_dirty($context->path); + $context->mark_dirty(); $status[] = array('component'=>$componentstr, 'item'=>get_string('deletecourseoverrides', 'role'), 'error'=>false); } @@ -5247,7 +5247,7 @@ function reset_course_userdata($data) { role_unassign_all(array('contextid'=>$child->id)); } //force refresh for logged in users - mark_context_dirty($context->path); + $context->mark_dirty(); $status[] = array('component'=>$componentstr, 'item'=>get_string('deletelocalroles', 'role'), 'error'=>false); } diff --git a/lib/tests/accesslib_test.php b/lib/tests/accesslib_test.php index e4d292b1fca..ed4bdcb8ba3 100644 --- a/lib/tests/accesslib_test.php +++ b/lib/tests/accesslib_test.php @@ -2442,6 +2442,7 @@ class accesslib_testcase extends advanced_testcase { accesslib_clear_all_caches(true); $DB->delete_records('cache_flags', array()); mark_context_dirty($systemcontext->path); + $this->assertDebuggingCalled('mark_context_dirty() is deprecated, please use $context->mark_dirty() instead.', DEBUG_DEVELOPER); $dirty = get_cache_flags('accesslib/dirtycontexts', time()-2); $this->assertTrue(isset($dirty[$systemcontext->path])); diff --git a/lib/upgrade.txt b/lib/upgrade.txt index ebc204d8320..8918067f8e3 100644 --- a/lib/upgrade.txt +++ b/lib/upgrade.txt @@ -22,6 +22,7 @@ information provided here is intended especially for developers. * context_instance_preload() is deprecated, please use context_helper::preload_from_record(). * get_contextlevel_name() is deprecated, please use context_helper::get_level_name(). * print_context_name() is deprecated, please use $context->get_context_name(). +* mark_context_dirty() is deprecated, please use $context->mark_dirty(). === 2.5.1 ===