Browse Source

Remove attforblock upgrade code.

People must upgrade to the 2.7 version of this code to support attforblock
upgrades.
MOODLE_28_STABLE
Dan Marsden 10 years ago
parent
commit
93d00b1cc1
  1. 75
      locallib.php
  2. 17
      version.php

75
locallib.php

@ -1684,78 +1684,3 @@ function att_log_convert_url(moodle_url $fullurl) {
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();
}

17
version.php

@ -29,20 +29,3 @@ $plugin->maturity = MATURITY_STABLE;
$plugin->cron = 0;
$plugin->component = 'mod_attendance';
// Nasty upgrade code to check if need to upgrade from attforblock.
// TODO: remove this asap.
if (defined('MOODLE_INTERNAL')) { // Only run if config.php has already been included.
global $DB;
$moduleexists = false;
try {
$moduleexists = $DB->record_exists('modules', array('name' =>'attforblock'));
} catch (Exception $e) {
// Probably a fresh install - modules table doesn't exist
}
if ($moduleexists) {
require_once('locallib.php');
attforblock_upgrade();
}
}

Loading…
Cancel
Save