|
@ -1684,78 +1684,3 @@ function att_log_convert_url(moodle_url $fullurl) { |
|
|
return substr($fullurl->out(), strlen($baseurl)); |
|
|
return substr($fullurl->out(), strlen($baseurl)); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
function attforblock_upgrade() { |
|
|
|
|
|
global $DB, $CFG; |
|
|
|
|
|
$module = $DB->get_record('modules', array('name' => 'attforblock')); |
|
|
|
|
|
|
|
|
|
|
|
// Deal with Moodle versions above 2013092001.02, where version is in config |
|
|
|
|
|
$versioninmodtable = true; |
|
|
|
|
|
if (!isset($module->version)) { |
|
|
|
|
|
$versioninmodtable = false; |
|
|
|
|
|
$module->version = get_config('mod_attforblock', 'version'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
if ($module->version <= '2011061800') { |
|
|
|
|
|
print_error("noupgradefromthisversion", 'attendance'); |
|
|
|
|
|
} |
|
|
|
|
|
if (file_exists($CFG->dirroot.'/mod/attforblock')) { |
|
|
|
|
|
print_error("attforblockdirstillexists", 'attendance'); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Now rename attforblock table and replace with attendance? |
|
|
|
|
|
$dbman = $DB->get_manager(); // Loads ddl manager and xmldb classes. |
|
|
|
|
|
$table = new xmldb_table('attforblock'); |
|
|
|
|
|
$newtable = new xmldb_table('attendance'); // Sanity check to make sure 'attendance' table doesn't already exist. |
|
|
|
|
|
if ($dbman->table_exists($table) && !$dbman->table_exists($newtable)) { |
|
|
|
|
|
$dbman->rename_table($table, 'attendance'); |
|
|
|
|
|
} else { |
|
|
|
|
|
print_error("tablerenamefailed", 'attendance'); |
|
|
|
|
|
} |
|
|
|
|
|
// Now convert module record. |
|
|
|
|
|
$module->name = 'attendance'; |
|
|
|
|
|
if (!$versioninmodtable) { |
|
|
|
|
|
set_config('version', $module->version, 'mod_attendance'); |
|
|
|
|
|
unset($module->version); |
|
|
|
|
|
} |
|
|
|
|
|
$DB->update_record('modules', $module); |
|
|
|
|
|
|
|
|
|
|
|
// Now convert grade items to 'attendance' |
|
|
|
|
|
$sql = "UPDATE {grade_items} |
|
|
|
|
|
SET itemmodule = ? |
|
|
|
|
|
WHERE itemmodule = ?"; |
|
|
|
|
|
$DB->execute($sql, array('attendance', 'attforblock')); |
|
|
|
|
|
|
|
|
|
|
|
$sql = "UPDATE {grade_items_history} |
|
|
|
|
|
SET itemmodule = 'attendance' |
|
|
|
|
|
WHERE itemmodule = 'attforblock'"; |
|
|
|
|
|
$DB->execute($sql); |
|
|
|
|
|
|
|
|
|
|
|
/* |
|
|
|
|
|
* The user's custom capabilities need to be preserved due to the module renaming. |
|
|
|
|
|
* Capabilities with a modifierid = 0 value are installed by default. |
|
|
|
|
|
* Only update the user's custom capabilities where modifierid is not zero. |
|
|
|
|
|
*/ |
|
|
|
|
|
$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. |
|
|
|
|
|
$attendances = $DB->get_recordset('attendance', array(), '', 'course'); |
|
|
|
|
|
foreach ($attendances as $attendance) { |
|
|
|
|
|
rebuild_course_cache($attendance->course, true); |
|
|
|
|
|
} |
|
|
|
|
|
$attendances->close(); |
|
|
|
|
|
} |
|
|
|
|
|