From: tjhunt Date: Wed, 14 Jan 2009 04:44:20 +0000 (+0000) Subject: accesslib: Nice debug developer warning if you call get_users_with_capability without... X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=fb35c0cf721b382051ac84b34e850386226e6ee9;p=moodle.git accesslib: Nice debug developer warning if you call get_users_with_capability without including u.id in the list of fields. --- diff --git a/lib/accesslib.php b/lib/accesslib.php index a6e26dfd48..593b457554 100755 --- a/lib/accesslib.php +++ b/lib/accesslib.php @@ -4632,8 +4632,8 @@ function get_default_course_role($course) { * case users having any of those capabilities will be returned. * For performance reasons, you are advised to put the capability * that the user is most likely to have first. - * @param $fields - fields to be pulled - * @param $sort - the sort order + * @param $fields - fields to be pulled. The user table is aliased to 'u'. u.id MUST be included. + * @param $sort - the sort order. Default is lastaccess time. * @param $limitfrom - number of records to skip (offset) * @param $limitnum - number of records to fetch * @param $groups - single group or array of groups - only return @@ -4796,6 +4796,11 @@ function get_users_by_capability($context, $capability, $fields='', $sort='', } else { $fields = 'u.*'; } + } else { + if (debugging('', DEBUG_DEVELOPER) && strpos($fields, 'u.*') === false && + strpos($fields, 'u.id') === false) { + debugging('u.id must be included in the list of fields passed to get_users_by_capability.', DEBUG_DEVELOPER); + } } /// Set up default sort