]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-17589 fixed handling of missing caps in admin tree; merged from MOODLE_19_STABLE
authorskodak <skodak>
Fri, 12 Dec 2008 10:50:25 +0000 (10:50 +0000)
committerskodak <skodak>
Fri, 12 Dec 2008 10:50:25 +0000 (10:50 +0000)
lib/accesslib.php
lib/adminlib.php

index b74c4139fd6e90ba203084773f67d7fdf76d8840..47aaf63aed5f6931eacc07e77e00757dcb050fce 100755 (executable)
@@ -3295,6 +3295,9 @@ function update_capabilities($component='moodle') {
     // role assignments?
     capabilities_cleanup($component, $filecaps);
 
+    // reset static caches
+    is_valid_capability('reset', false);
+
     return true;
 }
 
@@ -3894,10 +3897,17 @@ function get_related_contexts_string($context) {
     }
 }
 
-function is_valid_capability($capabilityname) {
+/**
+ * Verifies if given capability installed.
+ *
+ * @param string $capabilityname
+ * @param bool $cached
+ * @return book true if capability exists
+ */
+function is_valid_capability($capabilityname, $cached=true) {
     static $capsnames = null; // one request per page only
 
-    if (is_null($capsnames)) {
+    if (is_null($capsnames) or !$cached) {
         global $DB;
         $capsnames = $DB->get_records_menu('capabilities', null, '', 'name, 1');
     }
index 724b81e38f2eb51e77055cc391104dfc7445f482..dbf59e2e8623a05ad5673024b2dc4c940bd430fb 100644 (file)
@@ -2196,7 +2196,7 @@ class admin_externalpage extends part_of_admin_tree {
         }
         $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
         foreach($this->req_capability as $cap) {
-            if (has_capability($cap, $context)) {
+            if (is_valid_capability($cap) and has_capability($cap, $context)) {
                 return true;
             }
         }
@@ -2346,7 +2346,7 @@ class admin_settingpage extends part_of_admin_tree {
         }
         $context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
         foreach($this->req_capability as $cap) {
-            if (has_capability($cap, $context)) {
+            if (is_valid_capability($cap) and has_capability($cap, $context)) {
                 return true;
             }
         }