Browse Source

use cross-db update of capabilities

MOODLE_26_STABLE
Dan Marsden 11 years ago
parent
commit
68c8ff6626
  1. 27
      locallib.php

27
locallib.php

@ -1466,12 +1466,27 @@ function attforblock_upgrade() {
WHERE itemmodule = 'attforblock'"; WHERE itemmodule = 'attforblock'";
$DB->execute($sql); $DB->execute($sql);
// Now convert role capabilities to 'attendance' /*
$sql = "UPDATE {role_capabilities} * The user's custom capabilities need to be preserved due to the module renaming.
SET capability = REPLACE(capability, ?, ?) * Capabilities with a modifierid = 0 value are installed by default.
WHERE " . $DB->sql_like('capability', '?'); * Only update the user's custom capabilities where modifierid is not zero.
$params = array("mod/attforblock:", "mod/attendance:", "mod/attforblock:%"); */
$DB->execute($sql, $params); $sql = $DB->sql_like('capability', '?').' AND modifierid <> 0';
$rs = $DB->get_recordset_select('role_capabilities', $sql, array('%mod/attforblock%'));
foreach ($rs as $cap) {
$renamedcapability = str_replace('mod/attforblock', 'mod/attendance', $cap->capability);
$exists = $DB->record_exists('role_capabilities', array('roleid' => $cap->roleid, 'capability' => $renamedcapability));
if (!$exists) {
$DB->update_record('role_capabilities', array('id' => $cap->id, 'capability' => $renamedcapability));
}
}
// Delete old role capabilities.
$sql = $DB->sql_like('capability', '?');
$DB->delete_records_select('role_capabilities', $sql, array('%mod/attforblock%'));
// Delete old capabilities.
$DB->delete_records_select('capabilities', 'component = ?', array('mod_attforblock'));
// Clear cache for courses with attendances. // Clear cache for courses with attendances.
$attendances = $DB->get_recordset('attendance', array(), '', 'course'); $attendances = $DB->get_recordset('attendance', array(), '', 'course');

Loading…
Cancel
Save