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.

This commit is contained in:
tjhunt 2008-01-08 15:04:00 +00:00
parent 4282d047c2
commit cc3d5e10ec

View File

@ -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;
}