capability riskbitmasks and user trustbitmask patch #1 see MDL-6412

This commit is contained in:
skodak 2006-08-31 08:36:36 +00:00
parent 2b3447c38a
commit be4486da83
7 changed files with 34 additions and 9 deletions

View file

@ -1237,17 +1237,29 @@ function get_cached_capabilities($component='moodle') {
function update_capabilities($component='moodle') {
$storedcaps = array();
$filecaps = array();
$filecaps = load_capability_def($component);
$cachedcaps = get_cached_capabilities($component);
if ($cachedcaps) {
foreach ($cachedcaps as $cachedcap) {
array_push($storedcaps, $cachedcap->name);
// update risk bitmasks in existing capabilitites if needed
if (array_key_exists($cachedcap->name, $filecaps)) {
if (!array_key_exists('riskbitmask', $filecaps[$cachedcap->name])) {
$filecaps[$cachedcap->name]['riskbitmask'] = 0; // no risk by default
}
if ($cachedcap->riskbitmask != $filecaps[$cachedcap->name]['riskbitmask']) {
$updatecap = new object;
$updatecap->id = $cachedcap->id;
$updatecap->riskbitmask = $filecaps[$cachedcap->name]['riskbitmask'];
if (!update_record('capabilities', $updatecap)) {
return false;
}
}
}
}
}
$filecaps = load_capability_def($component);
// Are there new capabilities in the file definition?
$newcaps = array();
@ -1264,6 +1276,7 @@ function update_capabilities($component='moodle') {
$capability->captype = $capdef['captype'];
$capability->contextlevel = $capdef['contextlevel'];
$capability->component = $component;
$capability->riskbitmask = $capdef['riskbitmask'];
if (!insert_record('capabilities', $capability, false, 'id')) {
return false;
@ -1905,4 +1918,4 @@ function get_users_by_capability($context, $capability, $fields='distinct u.*',
return get_records_sql($select.$from.$where);
}
?>
?>