Index: lib/accesslib.php =================================================================== RCS file: /cvsroot/moodle/moodle/lib/accesslib.php,v retrieving revision 1.575 diff -u -r1.575 accesslib.php --- lib/accesslib.php 20 Mar 2009 07:41:49 -0000 1.575 +++ lib/accesslib.php 20 Mar 2009 08:45:25 -0000 @@ -285,7 +285,7 @@ global $CFG, $DB; $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID); - $base = '/'. SYSCONTEXTID .'/'. $frontpagecontext->id; + $base = '/'. get_system_context()->id .'/'. $frontpagecontext->id; // // Overrides for the role in any contexts related to the course @@ -296,7 +296,7 @@ JOIN {role_capabilities} rc ON rc.contextid=ctx.id WHERE rc.roleid = ? - AND (ctx.id = ".SYSCONTEXTID." OR ctx.path LIKE ?) + AND (ctx.id = ".get_system_context()->id." OR ctx.path LIKE ?) AND ctx.contextlevel <= ".CONTEXT_COURSE." ORDER BY ctx.depth, ctx.path"; $params = array($roleid, "$base/%"); @@ -385,8 +385,8 @@ if (is_null($context->path) or $context->depth == 0) { //this should not happen - $contexts = array(SYSCONTEXTID, $context->id); - $context->path = '/'.SYSCONTEXTID.'/'.$context->id; + $contexts = array(get_system_context()->id, $context->id); + $context->path = '/'.get_system_context()->id.'/'.$context->id; debugging('Context id '.$context->id.' does not have valid path, please use build_context_path()', DEBUG_DEVELOPER); } else { @@ -625,7 +625,7 @@ // error_log("found it!"); return true; } - $base = '/' . SYSCONTEXTID; + $base = '/' . get_system_context()->id; while (preg_match('!^(/.+)/\d+$!', $path, $matches)) { $path = $matches[1]; if ($path === $base) { @@ -1348,7 +1348,7 @@ * - below this user's RAs - limited to course level */ - $base = "/" . SYSCONTEXTID; + $base = "/" . get_system_context()->id; // // Replace $context with the target context we will @@ -1548,7 +1548,7 @@ function load_user_accessdata($userid) { global $ACCESS,$CFG; - $base = '/'.SYSCONTEXTID; + $base = '/'.get_system_context()->id; $accessdata = get_user_access_sitewide($userid); $frontpagecontext = get_context_instance(CONTEXT_COURSE, SITEID); @@ -1569,7 +1569,7 @@ // provide "default frontpage role" // if (!empty($CFG->defaultfrontpageroleid)) { - $base = '/'. SYSCONTEXTID .'/'. $frontpagecontext->id; + $base = '/'. get_system_context()->id .'/'. $frontpagecontext->id; $accessdata = get_default_frontpage_role_access($CFG->defaultfrontpageroleid, $accessdata); if (!isset($accessdata['ra'][$base])) { $accessdata['ra'][$base] = array($CFG->defaultfrontpageroleid); @@ -1622,7 +1622,7 @@ return; } - $base = '/'.SYSCONTEXTID; + $base = '/'.get_system_context()->id; if (isguestuser()) { $guest = get_guest_role(); @@ -1656,7 +1656,7 @@ // provide "default frontpage role" // if (!empty($CFG->defaultfrontpageroleid)) { - $base = '/'. SYSCONTEXTID .'/'. $frontpagecontext->id; + $base = '/'. get_system_context()->id .'/'. $frontpagecontext->id; $accessdata = get_default_frontpage_role_access($CFG->defaultfrontpageroleid, $accessdata); if (!isset($accessdata['ra'][$base])) { $accessdata['ra'][$base] = array($CFG->defaultfrontpageroleid); @@ -1945,7 +1945,7 @@ // Define $context->path based on the parent // context. In other words... Who is your daddy? - $basepath = '/' . SYSCONTEXTID; + $basepath = '/' . get_system_context()->id; $basedepth = 1; $result = true; @@ -2097,18 +2097,10 @@ * @return mixed system context or null */ function get_system_context($cache=true) { - global $DB; + global $DB $DB; static $cached = null; - if ($cache and defined('SYSCONTEXTID')) { - if (is_null($cached)) { - $cached = new object(); - $cached->id = SYSCONTEXTID; - $cached->contextlevel = CONTEXT_SYSTEM; - $cached->instanceid = 0; - $cached->path = '/'.SYSCONTEXTID; - $cached->depth = 1; - } + if ($cache && !is_null($cached)) { return $cached; } try { @@ -2148,11 +2140,10 @@ $DB->update_record('context', $context); } - if (!defined('SYSCONTEXTID')) { - define('SYSCONTEXTID', $context->id); - } - $cached = $context; + $context_cache[$context->contextlevel][$context->instanceid] = $context; + $context_cache_id[$context->id] = $context; + return $cached; } @@ -2488,10 +2479,6 @@ function get_context_instance_by_id($id) { global $context_cache, $context_cache_id, $DB; - if ($id == SYSCONTEXTID) { - return get_system_context(); - } - if (isset($context_cache_id[$id])) { // Already cached return $context_cache_id[$id]; }