]> git.mjollnir.org Git - moodle.git/commitdiff
weblib: build_navigation() try to avoid pointless capchecks
authormartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:52:42 +0000 (07:52 +0000)
committermartinlanghoff <martinlanghoff>
Wed, 19 Sep 2007 07:52:42 +0000 (07:52 +0000)
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

index c142f8bf94904043acf9b5ced061c42ccf8c9dc7..f42d9f9c8e15007a2943295fec5000ccddf8b640 100644 (file)
@@ -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;