From 0d25cd3a813765278c369f71a224888b4b82f1db Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 19 Sep 2007 07:10:09 +0000 Subject: [PATCH] accesslib: Introduce functions to deal with dirty contexts The accessinfo held in $USER->access can easily get out of sync with reality if and admin has removed our access, or expanded it after we loaded our accessinfo. To handle this, we'll use the config_plugins table with an 'accesslib/dirtycontexts' plugin signature to store the paths of recently changed contexts. To handle those dirrrty entries, here we introduce get_dirty_contexts() - for lib/setup mark_context_dirty() cleanup_dirty_contexts() - for cron --- lib/accesslib.php | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) diff --git a/lib/accesslib.php b/lib/accesslib.php index 798338a943..bced2ff91a 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -4629,4 +4629,53 @@ function make_context_subobj($rec) { return $rec; } +/* + * Fetch recent dirty contexts to know cheaply whether our $USER->access + * is stale and needs to be reloaded. + * + * Uses config_plugins. + * + */ +function get_dirty_contexts($time=NULL) { + global $CFG; + + $timecond = ''; + if (!is_null($time)) { + $timecond = " AND CAST(value to integer) > $time"; + } + $sql = "SELECT name, value + FROM {$CFG->prefix}config_plugins + WHERE plugin='accesslib/dirtycontexts' + $timecond"; + if ($ctx = get_records_sql($sql)) { + return $ctx; + } + return array(); +} + +/* + * Mark a context as dirty (with timestamp) + * so as to force reloading of the context. + * + */ +function mark_context_dirty($path) { + // Trivial (for now?) + set_config($path, time(), 'accesslib/dirtycontexts'); +} + +/* + * Cleanup all the old/stale dirty contexts. + * Any context exceeding our session + * timeout is stale. We only keep these for ongoing + * sessions. + * + */ +function cleanup_dirty_contexts() { + global $CFG; + + $sql = "plugin='accesslib/dirtycontexts' AND + CAST(value to integer) < " . time() - $CFG->sessiontimeout; + delete_records_select('config_plugins', $sql); +} + ?> -- 2.39.5