Remove attforblock upgrade code.
authorDan Marsden <dan@danmarsden.com>
Sun, 29 Mar 2015 22:09:24 +0000 (11:09 +1300)
committerDan Marsden <dan@danmarsden.com>
Sun, 29 Mar 2015 22:11:48 +0000 (11:11 +1300)
People must upgrade to the 2.7 version of this code to support attforblock
upgrades.

locallib.php
version.php

index 68417da..2700b9e 100644 (file)
@@ -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();
-}
index 427a816..b10a3d6 100644 (file)
@@ -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();
-    }
-
-}