3 // THIS FILE IS DEPRECATED! PLEASE DO NOT MAKE CHANGES TO IT!
5 // IT IS USED ONLY FOR UPGRADES FROM BEFORE MOODLE 1.7, ALL
6 // LATER CHANGES SHOULD USE upgrade.php IN THIS DIRECTORY.
8 function data_upgrade($oldversion) {
9 /// This function does anything necessary to upgrade
10 /// older versions to match current functionality
14 if ($oldversion < 2006011900) {
15 table_column("data_content", "", "content1", "text", "", "", "", "not null");
16 table_column("data_content", "", "content2", "text", "", "", "", "not null");
17 table_column("data_content", "", "content3", "text", "", "", "", "not null");
18 table_column("data_content", "", "content4", "text", "", "", "", "not null");
21 if ($oldversion < 2006011901) {
22 table_column("data", "", "approval", "integer", "4", "unsigned", "0", "not null");
23 table_column("data_records", "", "approved", "integer", "4", "unsigned", "0", "not null");
26 if ($oldversion < 2006020801) {
27 table_column("data", "", "scale", "integer");
28 table_column("data", "", "assessed", "integer");
29 table_column("data", "", "assesspublic", "integer");
32 if ($oldversion < 2006022700) {
33 table_column("data_comments", "", "created", "integer");
34 table_column("data_comments", "", "modified", "integer");
37 if ($oldversion < 2006030700) {
38 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'view', 'data', 'name');");
39 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'add', 'data', 'name')");
40 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'update', 'data', 'name')");
41 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'record delete', 'data', 'name')");
42 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'fields add', 'data_fields', 'name')");
43 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'fields update', 'data_fields', 'name')");
44 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'templates saved', 'data', 'name')");
45 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'templates defaults', 'data', 'name')");
48 if ($oldversion < 2006032700) {
49 table_column('data', '', 'defaultsort', 'integer', '10', 'unsigned', '0');
50 table_column('data', '', 'defaultsortdir', 'tinyint', '4', 'unsigned', '0', 'not null', 'defaultsort');
51 table_column('data', '', 'editany', 'tinyint', '4', 'unsigned', '0', 'not null', 'defaultsortdir');
54 if ($oldversion < 2006032900) {
55 table_column('data', '', 'csstemplate', 'text', '', '', '', 'not null', 'rsstemplate');
58 if ($oldversion < 2006050500) { // drop all tables, and create from scratch
60 execute_sql("DROP TABLE {$CFG->prefix}data", false);
61 execute_sql("DROP TABLE {$CFG->prefix}data_content", false);
62 execute_sql("DROP TABLE {$CFG->prefix}data_fields", false);
63 execute_sql("DROP TABLE {$CFG->prefix}data_records", false);
64 execute_sql("DROP TABLE {$CFG->prefix}data_comments", false);
65 execute_sql("DROP TABLE {$CFG->prefix}data_ratings", false);
67 modify_database('',"CREATE TABLE prefix_data (
68 id SERIAL PRIMARY KEY,
69 course integer NOT NULL default '0',
70 name varchar(255) NOT NULL default '',
71 intro text NOT NULL default '',
72 ratings integer NOT NULL default '0',
73 comments integer NOT NULL default '0',
74 timeavailablefrom integer NOT NULL default '0',
75 timeavailableto integer NOT NULL default '0',
76 timeviewfrom integer NOT NULL default '0',
77 timeviewto integer NOT NULL default '0',
78 participants integer NOT NULL default '0',
79 requiredentries integer NOT NULL default '0',
80 requiredentriestoview integer NOT NULL default '0',
81 maxentries integer NOT NULL default '0',
82 rssarticles integer NOT NULL default '0',
83 singletemplate text NOT NULL default '',
84 listtemplate text NOT NULL default '',
85 listtemplateheader text NOT NULL default '',
86 listtemplatefooter text NOT NULL default '',
87 addtemplate text NOT NULL default '',
88 rsstemplate text NOT NULL default '',
89 csstemplate text NOT NULL default '',
90 approval integer NOT NULL default '0',
91 scale integer NOT NULL default '0',
92 assessed integer NOT NULL default '0',
93 assesspublic integer NOT NULL default '0',
94 defaultsort integer NOT NULL default '0',
95 defaultsortdir integer NOT NULL default '0',
96 editany integer NOT NULL default '0'
99 CREATE TABLE prefix_data_content (
100 id SERIAL PRIMARY KEY,
101 fieldid integer NOT NULL default '0',
102 recordid integer NOT NULL default '0',
103 content text NOT NULL default '',
104 content1 text NOT NULL default '',
105 content2 text NOT NULL default '',
106 content3 text NOT NULL default '',
107 content4 text NOT NULL default ''
110 CREATE TABLE prefix_data_fields (
111 id SERIAL PRIMARY KEY,
112 dataid integer NOT NULL default '0',
113 type varchar(255) NOT NULL default '',
114 name varchar(255) NOT NULL default '',
115 description text NOT NULL default '',
116 param1 text NOT NULL default '',
117 param2 text NOT NULL default '',
118 param3 text NOT NULL default '',
119 param4 text NOT NULL default '',
120 param5 text NOT NULL default '',
121 param6 text NOT NULL default '',
122 param7 text NOT NULL default '',
123 param8 text NOT NULL default '',
124 param9 text NOT NULL default '',
125 param10 text NOT NULL default ''
128 CREATE TABLE prefix_data_records (
129 id SERIAL PRIMARY KEY,
130 userid integer NOT NULL default '0',
131 groupid integer NOT NULL default '0',
132 dataid integer NOT NULL default '0',
133 timecreated integer NOT NULL default '0',
134 timemodified integer NOT NULL default '0',
135 approved integer NOT NULL default '0'
138 CREATE TABLE prefix_data_comments (
139 id SERIAL PRIMARY KEY,
140 userid integer NOT NULL default '0',
141 recordid integer NOT NULL default '0',
142 content text NOT NULL default '',
143 created integer NOT NULL default '0',
144 modified integer NOT NULL default '0'
147 CREATE TABLE prefix_data_ratings (
148 id SERIAL PRIMARY KEY,
149 userid integer NOT NULL default '0',
150 recordid integer NOT NULL default '0',
151 rating integer NOT NULL default '0'
156 if ($oldversion < 2006052400) {
157 table_column('data','','rsstitletemplate','text','','','','not null','rsstemplate');
160 if ($oldversion < 2006081700) {
161 table_column('data', '', 'jstemplate', 'text', '', '', '', 'not null', 'csstemplate');
164 if ($oldversion < 2006092000) {
165 // Upgrades for new roles and capabilities support.
166 require_once($CFG->dirroot
.'/mod/data/lib.php');
168 $datamod = get_record('modules', 'name', 'data');
170 if ($data = get_records('data')) {
172 if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW
)) {
173 notify('Default teacher role was not found. Roles and permissions '.
174 'for all your forums will have to be manually set after '.
177 if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW
)) {
178 notify('Default student role was not found. Roles and permissions '.
179 'for all your forums will have to be manually set after '.
182 foreach ($data as $d) {
183 if (!data_convert_to_roles($d, $teacherroles, $studentroles)) {
184 notify('Data with id '.$d->id
.' was not upgraded');
187 // We need to rebuild all the course caches to refresh the state of
188 // the forum modules.
189 include_once( "$CFG->dirroot/course/lib.php" );
190 rebuild_course_cache();
194 modify_database('', 'ALTER TABLE prefix_data DROP COLUMN participants;');
195 modify_database('', 'ALTER TABLE prefix_data DROP COLUMN assesspublic;');
196 modify_database('', 'ALTER TABLE prefix_data DROP COLUMN ratings;');
200 if ($oldversion < 2006092302) { // Changing some TEXT fields to NULLable and no default
201 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN singletemplate DROP NOT NULL");
202 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN singletemplate DROP DEFAULT");
204 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN listtemplate DROP NOT NULL");
205 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN listtemplate DROP DEFAULT");
207 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN listtemplateheader DROP NOT NULL");
208 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN listtemplateheader DROP DEFAULT");
210 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN listtemplatefooter DROP NOT NULL");
211 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN listtemplatefooter DROP DEFAULT");
213 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN addtemplate DROP NOT NULL");
214 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN addtemplate DROP DEFAULT");
216 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN rsstemplate DROP NOT NULL");
217 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN rsstemplate DROP DEFAULT");
219 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN rsstitletemplate DROP NOT NULL");
220 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN rsstitletemplate DROP DEFAULT");
222 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN csstemplate DROP NOT NULL");
223 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN csstemplate DROP DEFAULT");
225 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN jstemplate DROP NOT NULL");
226 execute_sql("ALTER TABLE {$CFG->prefix}data ALTER COLUMN jstemplate DROP DEFAULT");
228 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param1 DROP NOT NULL");
229 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param1 DROP DEFAULT");
231 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param2 DROP NOT NULL");
232 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param2 DROP DEFAULT");
234 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param3 DROP NOT NULL");
235 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param3 DROP DEFAULT");
237 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param4 DROP NOT NULL");
238 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param4 DROP DEFAULT");
240 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param5 DROP NOT NULL");
241 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param5 DROP DEFAULT");
243 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param6 DROP NOT NULL");
244 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param6 DROP DEFAULT");
246 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param7 DROP NOT NULL");
247 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param7 DROP DEFAULT");
249 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param8 DROP NOT NULL");
250 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param8 DROP DEFAULT");
252 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param9 DROP NOT NULL");
253 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param9 DROP DEFAULT");
255 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param10 DROP NOT NULL");
256 execute_sql("ALTER TABLE {$CFG->prefix}data_fields ALTER COLUMN param10 DROP DEFAULT");
258 execute_sql("ALTER TABLE {$CFG->prefix}data_content ALTER COLUMN content DROP NOT NULL");
259 execute_sql("ALTER TABLE {$CFG->prefix}data_content ALTER COLUMN content DROP DEFAULT");
261 execute_sql("ALTER TABLE {$CFG->prefix}data_content ALTER COLUMN content1 DROP NOT NULL");
262 execute_sql("ALTER TABLE {$CFG->prefix}data_content ALTER COLUMN content1 DROP DEFAULT");
264 execute_sql("ALTER TABLE {$CFG->prefix}data_content ALTER COLUMN content2 DROP NOT NULL");
265 execute_sql("ALTER TABLE {$CFG->prefix}data_content ALTER COLUMN content2 DROP DEFAULT");
267 execute_sql("ALTER TABLE {$CFG->prefix}data_content ALTER COLUMN content3 DROP NOT NULL");
268 execute_sql("ALTER TABLE {$CFG->prefix}data_content ALTER COLUMN content3 DROP DEFAULT");
270 execute_sql("ALTER TABLE {$CFG->prefix}data_content ALTER COLUMN content4 DROP NOT NULL");
271 execute_sql("ALTER TABLE {$CFG->prefix}data_content ALTER COLUMN content4 DROP DEFAULT");
274 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.