From: tjhunt <tjhunt>
Date: Tue, 8 Jan 2008 15:04:00 +0000 (+0000)
Subject: Put back DEBUG_DEVELOPER sanity check in has_capability, that makes sure the capabilt... 
X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=cc3d5e10ec5f5695b8b3c7a92bad5a610175abd0;p=moodle.git

Put back DEBUG_DEVELOPER sanity check in has_capability, that makes sure the capabiltiy you are asking about actually exists. I know it takes an extra DB query, but it is DEBUG_DEVELOPER only, and it is worth its weight in gold, because otherwise you get really subtle bugs that take forever to diagnose. I know, I have just been banging my head against the wall for an hour.
---

diff --git a/lib/accesslib.php b/lib/accesslib.php
index bd8e27ab9e..3de14bee8c 100755
--- a/lib/accesslib.php
+++ b/lib/accesslib.php
@@ -327,6 +327,16 @@ function has_capability($capability, $context, $userid=NULL, $doanything=true) {
         return false;
     }
 
+/// 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.');
+        }
+        if ($doanything != true and $doanything != false) {
+            debugging('Capability parameter "doanything" is wierd ("'.$doanything.'"). This should be fixed in code.');
+        }
+    }
+
     if (empty($userid)) { // we must accept null, 0, '0', '' etc. in $userid
         $userid = $USER->id;
     }