MDL-17589 fixed handling of missing caps in admin tree; merged from MOODLE_19_STABLE

This commit is contained in:
skodak 2008-12-12 10:50:25 +00:00
parent 83f0fef567
commit 1a5b427e44
2 changed files with 14 additions and 4 deletions

View File

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

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