]> git.mjollnir.org Git - moodle.git/commitdiff
tweak has_capability() debug mode to add only one query per page for cap name verific...
authorskodak <skodak>
Wed, 16 Jan 2008 17:24:08 +0000 (17:24 +0000)
committerskodak <skodak>
Wed, 16 Jan 2008 17:24:08 +0000 (17:24 +0000)
lib/accesslib.php

index 7dec6b4c039d768ddfa43c55f64caa504fefc6b2..b2a061336ba72f09de0675be487d3af439c1a0b3 100755 (executable)
@@ -329,10 +329,22 @@ function has_capability($capability, $context, $userid=NULL, $doanything=true) {
 
 /// Some sanity checks
     if (debugging('',DEBUG_DEVELOPER)) {
-        if (!record_exists('capabilities', 'name', $capability)) {
-            debugging('Capability "'.$capability.'" was not found! This should be fixed in code.');
+        static $capsnames = null; // one request per page only
+        
+        if (is_null($capsnames)) {
+            if ($caps = get_records('capabilities', '', '', '', 'id, name')) {
+                $capsnames = array();
+                foreach ($caps as $cap) {
+                    $capsnames[$cap->name] = true;
+                }
+            }
+        }
+        if ($capsnames) { // ignore if can not fetch caps
+            if (!isset($capsnames[$capability])) {
+                debugging('Capability "'.$capability.'" was not found! This should be fixed in code.');
+            }
         }
-        if ($doanything != true and $doanything != false) {
+        if (!is_bool($doanything)) {
             debugging('Capability parameter "doanything" is wierd ("'.$doanything.'"). This should be fixed in code.');
         }
     }