mirrored from git://git.moodle.org/moodle.git
/
postgres7.php
146 lines (127 loc) · 7.1 KB
/
postgres7.php
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
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
<?PHP //$Id$
// PostgreSQL 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 (!$tables = $db->MetaColumns($CFG->prefix . 'enrol_authorize')) {
$installfirst = true;
}
if ($oldversion == 0 || !empty($installfirst)) { // First time install
$result = modify_database("$CFG->dirroot/enrol/authorize/db/postgres7.sql");
return $result; // RETURN, sql file contains last upgrades.
}
// Authorize module was installed before. Upgrades must be applied to SQL file.
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 < 2005080200) {
// 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("CREATE INDEX {$CFG->prefix}enrol_authorize_courseid_idx ON {$CFG->prefix}enrol_authorize (courseid);", false);
execute_sql("CREATE INDEX {$CFG->prefix}enrol_authorize_userid_idx ON {$CFG->prefix}enrol_authorize (userid);", false);
}
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.
modify_database('',"CREATE INDEX prefix_enrol_authorize_status_idx ON prefix_enrol_authorize (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 SERIAL PRIMARY KEY,
orderid INTEGER NOT NULL default 0,
refundtype INTEGER NOT NULL default 0,
amount varchar(10) NOT NULL default '',
transid INTEGER NULL default 0
);");
modify_database("","CREATE INDEX prefix_enrol_authorize_refunds_orderid_idx ON prefix_enrol_authorize_refunds (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 < 2006021531) { // Don't show authorize.net login info at config page
if (isset($CFG->an_login)) {
if (!empty($CFG->an_login)) {
set_config('an_login', rc4encrypt($CFG->an_login), 'enrol/authorize');
}
delete_records('config', 'name', 'an_login');
}
if (isset($CFG->an_tran_key)) {
if (!empty($CFG->an_tran_key)) {
set_config('an_tran_key', rc4encrypt($CFG->an_tran_key), 'enrol/authorize');
}
delete_records('config', 'name', 'an_tran_key');
}
if (isset($CFG->an_password)) {
if (!empty($CFG->an_password)) {
set_config('an_password', rc4encrypt($CFG->an_password), 'enrol/authorize');
}
delete_records('config', 'name', 'an_password');
}
}
return $result;
}
?>