Added check for <text> fields that contain markup (an error!)
[moodle-linuxchix.git] / enrol / authorize / db / postgres7.php
blob62c1d87826355192e9c5770edbca89fd0a8b84a6
1 <?php //$Id$
3 // THIS FILE IS DEPRECATED! PLEASE DO NOT MAKE CHANGES TO IT!
4 //
5 // IT IS USED ONLY FOR UPGRADES FROM BEFORE MOODLE 1.7, ALL
6 // LATER CHANGES SHOULD USE upgrade.php IN THIS DIRECTORY.
8 // PostgreSQL commands for upgrading this enrolment module
10 function enrol_authorize_upgrade($oldversion=0) {
11 global $CFG, $THEME, $db;
12 require_once("$CFG->dirroot/enrol/authorize/const.php");
14 $result = true;
16 if (!$tables = $db->MetaColumns($CFG->prefix . 'enrol_authorize')) {
17 $installfirst = true;
20 if ($oldversion == 0 || !empty($installfirst)) { // First time install
21 $result = modify_database("$CFG->dirroot/enrol/authorize/db/postgres7.sql");
22 return $result; // RETURN, sql file contains last upgrades.
25 // Authorize module was installed before. Upgrades must be applied to SQL file.
27 if ($oldversion && $oldversion < 2005071602) {
28 notify("If you are using the authorize.net enrolment plugin for credit card
29 handling, please ensure that you have turned loginhttps ON in Admin >> Variables >> Security.");
32 if ($oldversion < 2005080200) {
33 // Be sure, only last 4 digit is inserted.
34 table_column('enrol_authorize', 'cclastfour', 'cclastfour', 'integer', '4', 'unsigned', '0', 'not null');
35 table_column('enrol_authorize', 'courseid', 'courseid', 'integer', '10', 'unsigned', '0', 'not null');
36 table_column('enrol_authorize', 'userid', 'userid', 'integer', '10', 'unsigned', '0', 'not null');
37 // Add some indexes for speed.
38 execute_sql("CREATE INDEX {$CFG->prefix}enrol_authorize_courseid_idx ON {$CFG->prefix}enrol_authorize (courseid);", false);
39 execute_sql("CREATE INDEX {$CFG->prefix}enrol_authorize_userid_idx ON {$CFG->prefix}enrol_authorize (userid);", false);
42 if ($oldversion < 2005112100) {
43 table_column('enrol_authorize', '', 'authcode', 'varchar', '6', '', '', '', 'avscode'); // CAPTURE_ONLY
44 table_column('enrol_authorize', '', 'status', 'integer', '10', 'unsigned', '0', 'not null', 'transid');
45 table_column('enrol_authorize', '', 'timecreated', 'integer', '10', 'unsigned', '0', 'not null', 'status');
46 table_column('enrol_authorize', '', 'timeupdated', 'integer', '10', 'unsigned', '0', 'not null', 'timecreated');
47 // status index for speed.
48 modify_database('',"CREATE INDEX prefix_enrol_authorize_status_idx ON prefix_enrol_authorize (status);");
49 // defaults.
50 $status = AN_STATUS_AUTH | AN_STATUS_CAPTURE;
51 execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET status='$status' WHERE transid<>'0'", false);
52 $timenow = time();
53 execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET timecreated='$timenow', timeupdated='$timenow'", false);
56 if ($oldversion < 2005121200) {
57 // new fields for refund and sales reports.
58 $defaultcurrency = empty($CFG->enrol_currency) ? 'USD' : $CFG->enrol_currency;
59 table_column('enrol_authorize', '', 'amount', 'varchar', '10', '', '0', 'not null', 'timeupdated');
60 table_column('enrol_authorize', '', 'currency', 'varchar', '3', '', $defaultcurrency, 'not null', 'amount');
61 modify_database("","CREATE TABLE prefix_enrol_authorize_refunds (
62 id SERIAL PRIMARY KEY,
63 orderid INTEGER NOT NULL default 0,
64 refundtype INTEGER NOT NULL default 0,
65 amount varchar(10) NOT NULL default '',
66 transid INTEGER NULL default 0
67 );");
68 modify_database("","CREATE INDEX prefix_enrol_authorize_refunds_orderid_idx ON prefix_enrol_authorize_refunds (orderid);");
69 // defaults.
70 if (($courses = get_records_select('course', '', '', 'id, cost, currency'))) {
71 foreach ($courses as $course) {
72 execute_sql("UPDATE {$CFG->prefix}enrol_authorize
73 SET amount = '$course->cost', currency = '$course->currency'
74 WHERE courseid = '$course->id'", false);
79 if ($oldversion < 2005122200) { // settletime
80 table_column('enrol_authorize_refunds', 'refundtype', 'status', 'integer', '1', 'unsigned', '0', 'not null');
81 table_column('enrol_authorize_refunds', '', 'settletime', 'integer', '10', 'unsigned', '0', 'not null', 'transid');
82 table_column('enrol_authorize', 'timeupdated', 'settletime', 'integer', '10', 'unsigned', '0', 'not null');
83 $status = AN_STATUS_AUTH | AN_STATUS_CAPTURE;
84 if (($settlements = get_records_select('enrol_authorize', "status='$status'", '', 'id, settletime'))) {
85 include_once("$CFG->dirroot/enrol/authorize/authorizenetlib.php");
86 foreach ($settlements as $settlement) {
87 execute_sql("UPDATE {$CFG->prefix}enrol_authorize SET settletime = '" .
88 authorize_getsettletime($settlement->settletime) . "' WHERE id = '$settlement->id'", false);
93 if ($oldversion < 2005122800) { // no need anymore some fields.
94 execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize DROP ccexp", false);
95 execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize DROP cvv", false);
96 execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize DROP avscode", false);
97 execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize DROP authcode", false);
100 if ($oldversion < 2006010200) { // rename an_review_day
101 if (isset($CFG->an_review_day)) {
102 set_config('an_capture_day', $CFG->an_review_day);
103 delete_records('config', 'name', 'an_review_day');
107 if ($oldversion < 2006020100) { // rename an_cutoff_hour and an_cutoff_min to an_cutoff
108 if (isset($CFG->an_cutoff_hour) && isset($CFG->an_cutoff_min)) {
109 $an_cutoff_hour = intval($CFG->an_cutoff_hour);
110 $an_cutoff_min = intval($CFG->an_cutoff_min);
111 $an_cutoff = ($an_cutoff_hour * 60) + $an_cutoff_min;
112 if (set_config('an_cutoff', $an_cutoff)) {
113 delete_records('config', 'name', 'an_cutoff_hour');
114 delete_records('config', 'name', 'an_cutoff_min');
119 if ($oldversion < 2006021500) { // transid is int
120 table_column('enrol_authorize', 'transid', 'transid', 'integer', '10', 'unsigned', '0', 'not null');
123 if ($oldversion < 2006021501) { // delete an_nextmail record from config_plugins table
124 delete_records('config_plugins', 'name', 'an_nextmail');
127 if ($oldversion < 2006050400) { // Create transid indexes for backup & restore speed.
128 execute_sql("CREATE INDEX {$CFG->prefix}enrol_authorize_transid_idx ON {$CFG->prefix}enrol_authorize(transid);", false);
129 execute_sql("CREATE INDEX {$CFG->prefix}enrol_authorize_refunds_transid_idx ON {$CFG->prefix}enrol_authorize_refunds(transid);", false);
132 if ($oldversion < 2006060500) { // delete an_nextmail record from config_plugins table
133 delete_records('config_plugins', 'name', 'an_nextmail'); // run twice.
136 if ($oldversion < 2006081401) { // no need an_teachermanagepay in 1.7
137 if (isset($CFG->an_teachermanagepay)) {
138 delete_records('config', 'name', 'an_teachermanagepay');
142 if ($oldversion < 2006083100) {
143 // enums are lower case
144 if (isset($CFG->an_acceptmethods)) {
145 set_config('an_acceptmethods', strtolower($CFG->an_acceptmethods));
147 // new ENUM field: paymentmethod(cc,echeck)
148 table_column('enrol_authorize', '', 'paymentmethod', 'varchar', '6', '', 'cc', 'not null');
149 execute_sql("ALTER TABLE {$CFG->prefix}enrol_authorize ADD CONSTRAINT enroauth_pay_ck CHECK (paymentmethod IN ('cc', 'echeck'))", true);
152 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
154 return $result;