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();
$capability->captype = $capdef['captype'];
$capability->contextlevel = $capdef['contextlevel'];
$capability->component = $component;
+ $capability->riskbitmask = $capdef['riskbitmask'];
if (!insert_record('capabilities', $capability, false, 'id')) {
return false;
return get_records_sql($select.$from.$where);
}
-?>
+?>
\ No newline at end of file
<FIELD NAME="ajax" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="htmleditor" NEXT="autosubscribe"/>
<FIELD NAME="autosubscribe" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="1" SEQUENCE="false" ENUM="false" PREVIOUS="ajax" NEXT="trackforums"/>
<FIELD NAME="trackforums" TYPE="int" LENGTH="1" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="autosubscribe" NEXT="timemodified"/>
- <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="trackforums"/>
+ <FIELD NAME="timemodified" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="trackforums" NEXT="trustbitmask"/>
+ <FIELD NAME="trustbitmask" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Default comment for the field, please edit me" PREVIOUS="timemodified"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for user"/>
<FIELD NAME="name" TYPE="char" LENGTH="255" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="id" NEXT="captype"/>
<FIELD NAME="captype" TYPE="char" LENGTH="50" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="name" NEXT="contextlevel"/>
<FIELD NAME="contextlevel" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" PREVIOUS="captype" NEXT="component"/>
- <FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="contextlevel"/>
+ <FIELD NAME="component" TYPE="char" LENGTH="100" NOTNULL="true" SEQUENCE="false" ENUM="false" PREVIOUS="contextlevel" NEXT="riskbitmask"/>
+ <FIELD NAME="riskbitmask" TYPE="int" LENGTH="10" NOTNULL="true" UNSIGNED="true" DEFAULT="0" SEQUENCE="false" ENUM="false" COMMENT="Default comment for the field, please edit me" PREVIOUS="component"/>
</FIELDS>
<KEYS>
<KEY NAME="primary" TYPE="primary" FIELDS="id" COMMENT="Primary key for capabilities" NEXT="name"/>
table_column('sessions2', 'sessdata', 'sessdata', 'LONGTEXT', '', '', '', '', '');
}
+ if ($oldversion < 2006083002) {
+ table_column('capabilities', '', 'riskbitmask', 'INTEGER', '10', 'unsigned', '0', 'not null', '');
+ }
+
return $result;
}
`captype` varchar(50) NOT NULL default '',
`contextlevel` int(10) unsigned NOT NULL default '0',
`component` varchar(100) NOT NULL default '',
+ `riskbitmask` int(10) unsigned NOT NULL default '0',
UNIQUE KEY `name` (`name`),
PRIMARY KEY (`id`)
) TYPE=MYISAM COMMENT ='this defines all capabilities';
execute_sql("
CREATE INDEX {$CFG->prefix}sess_exp2_ix ON {$CFG->prefix}sessions2 (expireref);", true);
}
+
+ if ($oldversion < 2006083002) {
+ table_column('capabilities', '', 'riskbitmask', 'INTEGER', '10', 'unsigned', '0', 'not null', '');
+ }
return $result;
}
captype varchar(50) NOT NULL default '',
contextlevel integer NOT NULL default 0,
component varchar(100) NOT NULL default ''
+ riskbitmask integer NOT NULL default 0,
);
CREATE UNIQUE INDEX prefix_capabilities_name_idx ON prefix_capabilities (name);
// This is compared against the values stored in the database to determine
// whether upgrades should be performed (see lib/db/*.php)
- $version = 2006083001; // YYYYMMDD = date
+ $version = 2006083003; // YYYYMMDD = date
// XY = increments within a single day
$release = '1.7 dev'; // Human-friendly version name