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 workshop_upgrade($oldversion) {
9 // This function does anything necessary to upgrade
10 // older versions to match current functionality
14 if ($oldversion < 2003050400) {
15 table_column("workshop","graded", "agreeassessments", "INT","2", "", "0" ,"NOT NULL");
16 table_column("workshop", "showgrades","hidegrades", "INT","2", "","0", "NOT NULL");
17 table_column("workshop_assessments","","timeagreed", "INT","8", "UNSIGNED", "0", "NOT NULL" );
20 CREATE TABLE {$CFG->prefix}workshop_comments (
21 id SERIAL8 PRIMARY KEY ,
22 workshopid int8 NOT NULL default '0',
23 assessmentid int8 NOT NULL default '0',
24 userid int8 NOT NULL default '0',
25 timecreated int8 NOT NULL default '0',
26 mailed int2 NOT NULL default '0',
27 comments text NOT NULL
32 if ($oldversion < 2003051400) {
33 table_column("workshop","","showleaguetable", "INTEGER", "4", "unsigned", "0", "not null", "gradingweight");
35 CREATE TABLE {$CFG->prefix}workshop_rubrics (
36 id SERIAL8 PRIMARY KEY,
37 workshopid int8 NOT NULL default '0',
38 elementid int8 NOT NULL default '0',
39 rubricno int4 NOT NULL default '0',
40 description text NOT NULL,
45 if ($oldversion < 2003082200) {
46 table_column("workshop_rubrics", "elementid", "elementno", "INTEGER", "10", "unsigned", "0", "not null", "id");
49 if ($oldversion < 2003092500) {
50 table_column("workshop", "", "overallocation", "INTEGER", "4", "unsigned", "0", "not null", "nsassesments");
53 if ($oldversion < 2003100200) {
55 table_column("workshop_assesments", "", "resubmission", "INTEGER", "4", "unsigned", "0", "not null", "mailed");
58 if ($oldversion < 2003100800) {
59 // tidy up log_display entries
60 execute_sql("DELETE FROM {$CFG->prefix}log_display WHERE module = 'workshop'");
61 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES('workshop', 'assessments', 'workshop', 'name')");
62 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('workshop', 'close', 'workshop', 'name')");
63 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('workshop', 'display', 'workshop', 'name')");
64 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('workshop', 'resubmit', 'workshop', 'name')");
65 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('workshop', 'set up', 'workshop', 'name')");
66 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('workshop', 'submissions', 'workshop', 'name')");
67 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('workshop', 'view', 'workshop', 'name')");
68 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('workshop', 'update', 'workshop', 'name')");
71 if ($oldversion < 2003113000) {
72 table_column("workshop", "", "teacherloading", "INTEGER", "4", "unsigned", "5", "NOT NULL", "mailed");
73 table_column("workshop", "", "assessmentstodrop", "INTEGER", "4", "unsigned", "0", "NOT NULL", "");
74 table_column("workshop_assessments", "", "donotuse", "INTEGER", "4", "unsigned", "0", "NOT NULL", "resubmission");
75 execute_sql("CREATE INDEX {$CFG->prefix}workshop_grades_assesmentid_idx ON {$CFG->prefix}workshop_grades (assessmentid)");
78 if ($oldversion < 2004052100) {
79 include_once("$CFG->dirroot/mod/workshop/lib.php");
80 workshop_refresh_events();
83 if ($oldversion < 2004081100) {
84 table_column("workshop", "", "gradinggrade", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "grade");
85 table_column("workshop", "", "assessmentcomps", "INTEGER", "4", "UNSIGNED", "2", "NOT NULL", "ntassessments");
86 execute_sql("ALTER TABLE {$CFG->prefix}workshop DROP COLUMN gradingweight");
87 execute_sql("ALTER TABLE {$CFG->prefix}workshop DROP COLUMN mergegrades");
88 execute_sql("ALTER TABLE {$CFG->prefix}workshop DROP COLUMN peerweight");
89 execute_sql("ALTER TABLE {$CFG->prefix}workshop DROP COLUMN includeteachersgrade");
90 execute_sql("ALTER TABLE {$CFG->prefix}workshop DROP COLUMN biasweight");
91 execute_sql("ALTER TABLE {$CFG->prefix}workshop DROP COLUMN reliabilityweight");
92 execute_sql("ALTER TABLE {$CFG->prefix}workshop DROP COLUMN teacherloading",false); //silent
93 execute_sql("ALTER TABLE {$CFG->prefix}workshop DROP COLUMN assessmentstodrop",false); //silent
96 if ($oldversion < 2004092400) {
97 table_column("workshop", "", "nattachments", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "nelements");
98 table_column("workshop_submissions", "", "description", "TEXT", "", "", "", "", "mailed");
99 // these need to be dropped first in case we're upgrading from 1.4.3 and they already exist
100 execute_sql("DROP INDEX {$CFG->prefix}workshop_submissions_userid_idx;",false);
101 execute_sql("DROP INDEX {$CFG->prefix}workshop_assessments_submissionid_idx;",false);
102 execute_sql("DROP INDEX {$CFG->prefix}workshop_assessments_userid_idx;",false);
104 execute_sql("CREATE INDEX {$CFG->prefix}workshop_submissions_userid_idx ON {$CFG->prefix}workshop_submissions (userid)");
105 execute_sql("CREATE INDEX {$CFG->prefix}workshop_assessments_submissionid_idx ON {$CFG->prefix}workshop_assessments (submissionid)");
106 execute_sql("CREATE INDEX {$CFG->prefix}workshop_assessments_userid_idx ON {$CFG->prefix}workshop_assessments (userid)");
109 if ($oldversion < 2004092700) {
110 table_column("workshop", "", "wtype", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL", "description");
111 table_column("workshop", "", "usepassword", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL");
112 table_column("workshop", "", "password", "VARCHAR", "32", "", "", "NOT NULL");
113 table_column("workshop_submissions", "", "late", "INTEGER", "4", "UNSIGNED", "0", "NOT NULL");
116 if ($workshops = get_records("workshop")) {
117 foreach ($workshops as $workshop) {
118 $wtype = 0; // 3 phases, no grading grades
119 if ($workshop->includeself
or $workshop->ntassessments
) $wtype = 1; // 3 phases with grading grades
120 if ($workshop->nsassessments
) $wtype = 2; // 5 phases with grading grades
121 set_field("workshop", "wtype", $wtype, "id", $workshop->id
);
126 if ($oldversion < 2004102800) {
127 table_column("workshop", "", "releasegrades", "INTEGER", "10", "UNSIGNED", "0", "NOT NULL", "deadline");
129 CREATE TABLE {$CFG->prefix}workshop_stockcomments (
130 id SERIAL PRIMARY KEY,
131 workshopid INT8 NOT NULL default '0',
132 elementno INT8 NOT NULL default '0',
133 comments text NOT NULL
138 if ($oldversion < 2004111000) {
139 table_column("workshop_elements", "", "stddev", "FLOAT", "", "", "0", "NOT NULL");
140 table_column("workshop_elements", "", "totalassessments", "INTEGER", "10", "", "0", "NOT NULL");
141 table_column("workshop_elements", "weight", "weight", "INTEGER", "4", "UNSIGNED", "11", "NOT NULL");
142 table_column("workshop_submissions", "", "nassessments", "INTEGER", "10", "", "0", "NOT NULL");
143 execute_sql("ALTER TABLE {$CFG->prefix}workshop_submissions DROP COLUMN teachergrade");
144 execute_sql("ALTER TABLE {$CFG->prefix}workshop_submissions DROP COLUMN peergrade");
145 execute_sql("ALTER TABLE {$CFG->prefix}workshop_submissions DROP COLUMN biasgrade");
146 execute_sql("ALTER TABLE {$CFG->prefix}workshop_submissions DROP COLUMN reliabilitygrade");
149 if ($oldversion < 2004111200) {
150 execute_sql("DROP INDEX {$CFG->prefix}workshop_course_idx;",false);
151 execute_sql("DROP INDEX {$CFG->prefix}workshop_assessments_workshopid_idx;",false);
152 execute_sql("DROP INDEX {$CFG->prefix}workshop_assessments_submissionid_idx;",false);
153 execute_sql("DROP INDEX {$CFG->prefix}workshop_assessments_userid_idx;",false);
154 execute_sql("DROP INDEX {$CFG->prefix}workshop_assessments_mailed_idx;",false);
155 execute_sql("DROP INDEX {$CFG->prefix}workshop_comments_workshopid_idx;",false);
156 execute_sql("DROP INDEX {$CFG->prefix}workshop_comments_assessmentid_idx;",false);
157 execute_sql("DROP INDEX {$CFG->prefix}workshop_comments_userid_idx;",false);
158 execute_sql("DROP INDEX {$CFG->prefix}workshop_comments_mailed_idx;",false);
159 execute_sql("DROP INDEX {$CFG->prefix}workshop_elements_workshopid_idx;",false);
160 execute_sql("DROP INDEX {$CFG->prefix}workshop_grades_workshopid_idx;",false);
161 execute_sql("DROP INDEX {$CFG->prefix}workshop_grades_assessmentid_idx;",false);
162 execute_sql("DROP INDEX {$CFG->prefix}workshop_submissions_workshopid_idx;",false);
163 execute_sql("DROP INDEX {$CFG->prefix}workshop_submissions_userid_idx;",false);
164 execute_sql("DROP INDEX {$CFG->prefix}workshop_submissions_mailed_idx;",false);
166 modify_database('','CREATE INDEX prefix_workshop_course_idx ON prefix_workshop (course);');
167 modify_database('','CREATE INDEX prefix_workshop_assessments_workshopid_idx ON prefix_workshop_assessments (workshopid);');
168 modify_database('','CREATE INDEX prefix_workshop_assessments_submissionid_idx ON prefix_workshop_assessments (submissionid);');
169 modify_database('','CREATE INDEX prefix_workshop_assessments_userid_idx ON prefix_workshop_assessments (userid);');
170 modify_database('','CREATE INDEX prefix_workshop_assessments_mailed_idx ON prefix_workshop_assessments (mailed);');
171 modify_database('','CREATE INDEX prefix_workshop_comments_workshopid_idx ON prefix_workshop_comments (workshopid);');
172 modify_database('','CREATE INDEX prefix_workshop_comments_assessmentid_idx ON prefix_workshop_comments (assessmentid);');
173 modify_database('','CREATE INDEX prefix_workshop_comments_userid_idx ON prefix_workshop_comments (userid);');
174 modify_database('','CREATE INDEX prefix_workshop_comments_mailed_idx ON prefix_workshop_comments (mailed);');
175 modify_database('','CREATE INDEX prefix_workshop_elements_workshopid_idx ON prefix_workshop_elements (workshopid);');
176 modify_database('','CREATE INDEX prefix_workshop_grades_workshopid_idx ON prefix_workshop_grades (workshopid);');
177 modify_database('','CREATE INDEX prefix_workshop_grades_assessmentid_idx ON prefix_workshop_grades (assessmentid);');
178 modify_database('','CREATE INDEX prefix_workshop_submissions_workshopid_idx ON prefix_workshop_submissions (workshopid);');
179 modify_database('','CREATE INDEX prefix_workshop_submissions_userid_idx ON prefix_workshop_submissions (userid);');
180 modify_database('','CREATE INDEX prefix_workshop_submissions_mailed_idx ON prefix_workshop_submissions (mailed);');
183 if ($oldversion < 2004120402) {
184 table_column('workshop', '', 'submissionstart', 'INTEGER', '10', 'UNSIGNED', '0', 'NOT NULL', 'maxbytes');
185 table_column('workshop', '', 'assessmentstart', 'INTEGER', '10', 'UNSIGNED', '0', 'NOT NULL', 'submissionstart');
186 table_column('workshop', 'deadline', 'submissionend', 'INTEGER', '10', 'UNSIGNED', '0', 'NOT NULL');
187 table_column('workshop', '', 'assessmentend', 'INTEGER', '10', 'UNSIGNED', '0', 'NOT NULL', 'submissionend');
189 $workshops = get_records('workshop');
190 if(!empty($workshops)) {
191 foreach ($workshops as $workshop) {
192 $early = (time() < $workshop->submissionend
) ?
0 : $workshop->submissionend
;
193 $late = (time() > $workshop->submissionend
) ?
0 : $workshop->submissionend
;
194 set_field('workshop', 'submissionstart', ($workshop->phase
> 1) ?
$early : $late, 'id', $workshop->id
);
195 set_field('workshop', 'assessmentstart', ($workshop->phase
> 2) ?
$early : $late, 'id', $workshop->id
);
196 set_field('workshop', 'submissionend', ($workshop->phase
> 3) ?
$early : $late, 'id', $workshop->id
);
197 set_field('workshop', 'assessmentend', ($workshop->phase
> 4) ?
$early : $late, 'id', $workshop->id
);
200 execute_sql('ALTER TABLE '. $CFG->prefix
.'workshop DROP COLUMN phase');
202 execute_sql("UPDATE {$CFG->prefix}event SET eventtype = 'submissionend' WHERE eventtype = 'deadline' AND modulename = 'workshop'", false);
205 if ($oldversion < 2004120900) {
206 table_column('workshop_assessments', '', 'teachergraded', 'INTEGER', '4', 'UNSIGNED', '0', 'NOT NULL', 'gradinggrade');
209 if ($oldversion < 2005041200) { // replace wiki-like with markdown
210 include_once( "$CFG->dirroot/lib/wiki_to_markdown.php" );
211 $wtm = new WikiToMarkdown();
212 $wtm->update( 'workshop','description','format' );
215 if ($oldversion < 2005041201) { // Mass cleanup of bad upgrade scripts
216 // Some of those steps might fail, it is normal.
217 table_column('workshop','assessmentend','assessmentend','integer','16');
218 table_column('workshop','assessmentstart','assessmentstart','integer','16');
219 table_column('workshop','','phase','integer','4');
220 table_column('workshop','','showleaguetable','integer','8');
221 table_column('workshop','releasegrades','releasegrades','integer','16');
222 table_column('workshop','submissionend','submissionend','integer','16');
223 table_column('workshop','submissionstart','submissionstart','integer','16');
224 modify_database('','ALTER TABLE prefix_workshop ALTER teacherweight SET DEFAULT 1');
225 modify_database('','ALTER TABLE prefix_workshop DROP timeagreed');
226 modify_database('','ALTER TABLE prefix_workshop RENAME inalgrade TO finalgrade');
227 table_column('workshop_assessments','','donotuse','integer','8');
228 table_column('workshop_assessments','','timeagreed','integer','16');
229 modify_database('','ALTER TABLE prefix_workshop_assessments DROP teachergraded');
230 modify_database('','ALTER TABLE prefix_workshop_elements RENAME totalrassesments TO totalassessments');
231 modify_database('','ALTER TABLE prefix_workshop_submissions ALTER description DROP DEFAULT');
232 table_column('workshop_submissions','nassessments','nassessments','integer','16');
233 table_column('workshop_elements','totalassessments','totalassessments','integer','16');
235 CREATE TABLE {$CFG->prefix}workshop_rubrics (
236 id SERIAL PRIMARY KEY,
237 workshopid int8 NOT NULL default '0',
238 elementno int8 NOT NULL default '0',
239 rubricno int4 NOT NULL default '0',
240 description text NOT NULL
245 if ($oldversion < 2006090500) {
246 $columns = $db->MetaColumns($CFG->prefix
.'workshop_assessments');
247 $columns = array_change_key_case($columns, CASE_LOWER
);
248 if (!isset($columns['teachergraded'])) {
249 table_column('workshop_assessments', '', 'teachergraded', 'INTEGER', '4', 'UNSIGNED', '0', 'NOT NULL', 'gradinggrade');
253 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.