Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
tree: 6b1d27020d
Fetching contributors…

Cannot retrieve contributors at this time

executable file 129 lines (111 sloc) 6.56 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129
<?php //$Id$

// MySQL commands for upgrading this enrolment module

function enrol_authorize_upgrade($oldversion=0) {
    global $CFG, $THEME, $db;
    require_once("$CFG->dirroot/enrol/authorize/const.php");

    $result = true;

    if ($oldversion < 2005071600) {
        // Be sure, only last 4 digit is inserted.
        table_column('enrol_authorize', 'cclastfour', 'cclastfour', 'integer', '4', 'unsigned', '0', 'not null');
        table_column('enrol_authorize', 'courseid', 'courseid', 'integer', '10', 'unsigned', '0', 'not null');
        table_column('enrol_authorize', 'userid', 'userid', 'integer', '10', 'unsigned', '0', 'not null');
        // Add some indexes for speed.
        execute_sql("ALTER TABLE `{$CFG->prefix}enrol_authorize` ADD INDEX courseid(courseid)", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}enrol_authorize` ADD INDEX userid(userid)", false);
    }

    if ($oldversion && $oldversion < 2005071602) {
        notify("If you are using the authorize.net enrolment plugin for credit card
handling, please ensure that you have turned loginhttps ON in Admin >> Variables >> Security.");
    }

    if ($oldversion < 2005112100) {
        table_column('enrol_authorize', '', 'authcode', 'varchar', '6', '', '', '', 'avscode'); // CAPTURE_ONLY
        table_column('enrol_authorize', '', 'status', 'integer', '10', 'unsigned', '0', 'not null', 'transid');
        table_column('enrol_authorize', '', 'timecreated', 'integer', '10', 'unsigned', '0', 'not null', 'status');
        table_column('enrol_authorize', '', 'timeupdated', 'integer', '10', 'unsigned', '0', 'not null', 'timecreated');
        // status index for speed.
        execute_sql("ALTER TABLE `{$CFG->prefix}enrol_authorize` ADD INDEX status(status)");
        // defaults.
        $status = AN_STATUS_AUTH | AN_STATUS_CAPTURE;
        execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET status='$status' WHERE transid<>'0'", false);
        $timenow = time();
        execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET timecreated='$timenow', timeupdated='$timenow'", false);
    }

    if ($oldversion < 2005121200) {
        // new fields for refund and sales reports.
        $defaultcurrency = empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency;
        table_column('enrol_authorize', '', 'amount', 'varchar', '10', '', '0', 'not null', 'timeupdated');
        table_column('enrol_authorize', '', 'currency', 'varchar', '3', '', $defaultcurrency, 'not null', 'amount');
        modify_database("","CREATE TABLE prefix_enrol_authorize_refunds (
`id` int(10) unsigned NOT NULL auto_increment,
`orderid` int(10) unsigned NOT NULL default 0,
`refundtype` int(1) unsigned NOT NULL default 0,
`amount` varchar(10) NOT NULL default '',
`transid` int(10) unsigned NULL default 0,
PRIMARY KEY (`id`),
KEY `orderid` (`orderid`));");
        // defaults.
        if ($courses = get_records_select('course', '', '', 'id, cost, currency')) {
            foreach ($courses as $course) {
                execute_sql("UPDATE {$CFG->prefix}enrol_authorize
SET amount = '$course->cost', currency = '$course->currency'
WHERE courseid = '$course->id'", false);
            }
        }
    }

    if ($oldversion < 2005122200) { // settletime
        table_column('enrol_authorize_refunds', 'refundtype', 'status', 'integer', '1', 'unsigned', '0', 'not null');
        table_column('enrol_authorize_refunds', '', 'settletime', 'integer', '10', 'unsigned', '0', 'not null', 'transid');
        table_column('enrol_authorize', 'timeupdated', 'settletime', 'integer', '10', 'unsigned', '0', 'not null');
        $status = AN_STATUS_AUTH | AN_STATUS_CAPTURE;
        if ($settlements = get_records_select('enrol_authorize', "status='$status'", '', 'id, settletime')) {
            include_once("$CFG->dirroot/enrol/authorize/authorizenetlib.php");
            foreach ($settlements as $settlement) {
                execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET settletime = '" .
                authorize_getsettletime($settlement->settletime) . "' WHERE id = '$settlement->id'", false);
            }
        }
    }

    if ($oldversion < 2005122800) { // no need anymore some fields.
        execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize DROP ccexp", false);
        execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize DROP cvv", false);
        execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize DROP avscode", false);
        execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize DROP authcode", false);
    }

    if ($oldversion < 2006010200) { // rename an_review_day
        if (isset($CFG->an_review_day)) {
            set_config('an_capture_day', $CFG->an_review_day);
            delete_records('config', 'name', 'an_review_day');
        }
    }

    if ($oldversion < 2006020100) { // rename an_cutoff_hour and an_cutoff_min to an_cutoff
        if (isset($CFG->an_cutoff_hour) && isset($CFG->an_cutoff_min)) {
            $an_cutoff_hour = intval($CFG->an_cutoff_hour);
            $an_cutoff_min = intval($CFG->an_cutoff_min);
            $an_cutoff = ($an_cutoff_hour * 60) + $an_cutoff_min;
            if (set_config('an_cutoff', $an_cutoff)) {
                delete_records('config', 'name', 'an_cutoff_hour');
                delete_records('config', 'name', 'an_cutoff_min');
            }
        }
    }

    if ($oldversion < 2006021500) { // transid is int
        table_column('enrol_authorize', 'transid', 'transid', 'integer', '10', 'unsigned', '0', 'not null');
    }

    if ($oldversion < 2006021501) { // delete an_nextmail record from config_plugins table
        delete_records('config_plugins', 'name', 'an_nextmail');
    }

    if ($oldversion < 2006050400) { // Create transid indexes for backup & restore speed.
        execute_sql("ALTER TABLE `{$CFG->prefix}enrol_authorize` ADD INDEX transid(transid)", false);
        execute_sql("ALTER TABLE `{$CFG->prefix}enrol_authorize_refunds` ADD INDEX transid(transid)", false);
    }

    if ($oldversion < 2006060500) { // delete an_nextmail record from config_plugins table
        delete_records('config_plugins', 'name', 'an_nextmail'); // run twice.
    }

    if ($oldversion < 2006081401) { // no need an_teachermanagepay in 1.7
        if (isset($CFG->an_teachermanagepay)) {
            delete_records('config', 'name', 'an_teachermanagepay');
        }
    }

    return $result;
}

?>
Something went wrong with that request. Please try again.