MDL-10234
[moodle-linuxchix.git] / mod / data / db / mysql.php
blob058939611ba9bdf8bb7c38a3f7f2d5d82cdff548
1 <?php
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 function data_upgrade($oldversion) {
9 /// This function does anything necessary to upgrade
10 /// older versions to match current functionality
12 global $CFG;
14 if ($oldversion < 2006011900) {
15 table_column("data_content", "", "content1", "longtext", "", "", "", "not null");
16 table_column("data_content", "", "content2", "longtext", "", "", "", "not null");
17 table_column("data_content", "", "content3", "longtext", "", "", "", "not null");
18 table_column("data_content", "", "content4", "longtext", "", "", "", "not null");
21 if ($oldversion < 2006011901) {
22 table_column("data", "", "approval", "tinyint", "4");
23 table_column("data_records", "", "approved", "tinyint", "4");
26 if ($oldversion < 2006020801) {
27 table_column("data", "", "scale", "integer", "10", "signed");
28 table_column("data", "", "assessed", "integer", "10");
29 table_column("data", "", "assesspublic", "integer", "4");
32 if ($oldversion < 2006022700) {
33 table_column("data_comments", "", "created", "integer", "10");
34 table_column("data_comments", "", "modified", "integer", "10");
37 if ($oldversion < 2006030700) {
38 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'add', 'data', 'name')");
39 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'update', 'data', 'name')");
40 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'record delete', 'data', 'name')");
41 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'fields add', 'data_fields', 'name')");
42 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'fields update', 'data_fields', 'name')");
43 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'templates saved', 'data', 'name')");
44 modify_database('', "INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('data', 'templates def', 'data', 'name')");
47 if ($oldversion < 2006032700) {
48 table_column('data', '', 'defaultsort', 'integer', '10', 'unsigned', '0');
49 table_column('data', '', 'defaultsortdir', 'tinyint', '4', 'unsigned', '0', 'not null', 'defaultsort');
50 table_column('data', '', 'editany', 'tinyint', '4', 'unsigned', '0', 'not null', 'defaultsortdir');
53 if ($oldversion < 2006032900) {
54 table_column('data', '', 'csstemplate', 'text', '', '', '', 'not null', 'rsstemplate');
57 if ($oldversion < 2006050500) { // 2 fields have got no default null values
58 table_column('data_comments','content','content','text','','','','not null');
59 table_column('data_fields','description','description','text','','','','not null');
60 table_column('data_fields','param1','param1','text','','','','not null');
61 table_column('data_fields','param2','param2','text','','','','not null');
62 table_column('data_fields','param3','param3','text','','','','not null');
63 table_column('data_fields','param4','param4','text','','','','not null');
64 table_column('data_fields','param5','param5','text','','','','not null');
65 table_column('data_fields','param6','param6','text','','','','not null');
66 table_column('data_fields','param7','param7','text','','','','not null');
67 table_column('data_fields','param8','param8','text','','','','not null');
68 table_column('data_fields','param9','param9','text','','','','not null');
69 table_column('data_fields','param10','param10','text','','','','not null');
72 if ($oldversion < 2006052400) {
73 table_column('data','','rsstitletemplate','text','','','','not null','rsstemplate');
76 if ($oldversion < 2006081700) {
77 table_column('data', '', 'jstemplate', 'text', '', '', '', 'not null', 'csstemplate');
80 if ($oldversion < 2006092000) {
81 // Upgrades for new roles and capabilities support.
82 require_once($CFG->dirroot.'/mod/data/lib.php');
84 $datamod = get_record('modules', 'name', 'data');
86 if ($data = get_records('data')) {
88 if (!$teacherroles = get_roles_with_capability('moodle/legacy:teacher', CAP_ALLOW)) {
89 notify('Default teacher role was not found. Roles and permissions '.
90 'for all your forums will have to be manually set after '.
91 'this upgrade.');
93 if (!$studentroles = get_roles_with_capability('moodle/legacy:student', CAP_ALLOW)) {
94 notify('Default student role was not found. Roles and permissions '.
95 'for all your forums will have to be manually set after '.
96 'this upgrade.');
98 foreach ($data as $d) {
99 if (!data_convert_to_roles($d, $teacherroles, $studentroles)) {
100 notify('Data with id '.$d->id.' was not upgraded');
103 // We need to rebuild all the course caches to refresh the state of
104 // the forum modules.
105 include_once( "$CFG->dirroot/course/lib.php" );
106 rebuild_course_cache();
108 } // End if.
110 modify_database('', 'ALTER TABLE prefix_data DROP COLUMN participants;');
111 modify_database('', 'ALTER TABLE prefix_data DROP COLUMN assesspublic;');
112 modify_database('', 'ALTER TABLE prefix_data DROP COLUMN ratings;');
116 if ($oldversion < 2006092302) { // Changing some TEXT fields to NULLable and no default
117 execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE singletemplate singletemplate text NULL AFTER rssarticles");
118 execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE listtemplate listtemplate text NULL AFTER singletemplate");
119 execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE listtemplateheader listtemplateheader text NULL AFTER listtemplate");
120 execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE listtemplatefooter listtemplatefooter text NULL AFTER listtemplateheader");
121 execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE addtemplate addtemplate text NULL AFTER listtemplatefooter");
122 execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE rsstemplate rsstemplate text NULL AFTER addtemplate");
123 execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE rsstitletemplate rsstitletemplate text NULL AFTER rsstemplate");
124 execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE csstemplate csstemplate text NULL AFTER rsstitletemplate");
125 execute_sql("ALTER TABLE {$CFG->prefix}data CHANGE jstemplate jstemplate text NULL AFTER csstemplate");
127 execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param1 param1 text NULL AFTER description");
128 execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param2 param2 text NULL AFTER param1");
129 execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param3 param3 text NULL AFTER param2");
130 execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param4 param4 text NULL AFTER param3");
131 execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param5 param5 text NULL AFTER param4");
132 execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param6 param6 text NULL AFTER param5");
133 execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param7 param7 text NULL AFTER param6");
134 execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param8 param8 text NULL AFTER param7");
135 execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param9 param9 text NULL AFTER param8");
136 execute_sql("ALTER TABLE {$CFG->prefix}data_fields CHANGE param10 param10 text NULL AFTER param9");
138 execute_sql("ALTER TABLE {$CFG->prefix}data_content CHANGE content content longtext NULL AFTER recordid");
139 execute_sql("ALTER TABLE {$CFG->prefix}data_content CHANGE content1 content1 longtext NULL AFTER content");
140 execute_sql("ALTER TABLE {$CFG->prefix}data_content CHANGE content2 content2 longtext NULL AFTER content1");
141 execute_sql("ALTER TABLE {$CFG->prefix}data_content CHANGE content3 content3 longtext NULL AFTER content2");
142 execute_sql("ALTER TABLE {$CFG->prefix}data_content CHANGE content4 content4 longtext NULL AFTER content3");
145 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.
147 return true;