From 8f9a180282dc6ffcb48d479ac551d64fbb166430 Mon Sep 17 00:00:00 2001 From: martinlanghoff Date: Wed, 19 Sep 2007 07:52:42 +0000 Subject: [PATCH] weblib: build_navigation() try to avoid pointless capchecks Prevent calls to has_capability() in build_navigation() from messing with upgrades. Most calls to has_capability() in weblib should be moved to the callers. --- lib/weblib.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/lib/weblib.php b/lib/weblib.php index c142f8bf94..f42d9f9c8e 100644 --- a/lib/weblib.php +++ b/lib/weblib.php @@ -3370,7 +3370,18 @@ function build_navigation($extranavlinks) { continue; } // Check the link type to see if this link should appear in the trail - $cap = has_capability('moodle/course:manageactivities', get_context_instance(CONTEXT_COURSE, $COURSE->id)); + // + // NOTE: we should move capchecks _out_ to the callers. build_navigation() is + // called from many places -- install & upgrade for example -- where we cannot + // count on the roles infrastructure to be defined. + // + $cap = 0; + if (!empty($COURSE->id) && $COURSE->id != SITEID) { + if (!isset($COURSE->context)) { + $COURSE->context = get_context_instance(CONTEXT_COURSE, $COURSE->id); + } + $cap = has_capability('moodle/course:manageactivities', $COURSE->context); + } $hidetype_is2 = $CFG->hideactivitytypenavlink == 2; $hidetype_is1 = $CFG->hideactivitytypenavlink == 1; -- 2.39.5