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 scorm_upgrade($oldversion) {
9 /// This function does anything necessary to upgrade
10 /// older versions to match current functionality
12 if ($oldversion < 2004033000) {
13 table_column("scorm", "", "auto", "TINYINT", "1", "UNSIGNED", "0", "NOT NULL", "summary");
15 if ($oldversion < 2004040900) {
16 table_column("scorm_sco_users", "", "cmi_core_score_raw", "FLOAT", "3", "", "0", "NOT NULL", "cmi_core_session_time");
18 if ($oldversion < 2004061800) {
19 table_column("scorm", "", "popup", "VARCHAR", "255", "", "", "NOT NULL", "auto");
20 table_column("scorm", "reference", "reference", "VARCHAR", "255", "", "", "NOT NULL");
22 if ($oldversion < 2004070800) {
23 table_column("scorm_scoes", "", "datafromlms", "TEXT", "", "", "", "NOT NULL", "title");
24 modify_database("", "ALTER TABLE `{$CFG->prefix}scorm_sco_users` DROP `cmi_launch_data`;");
26 if ($oldversion < 2004071700) {
27 table_column("scorm_scoes", "", "manifest", "VARCHAR", "255", "", "", "NOT NULL", "scorm");
28 table_column("scorm_scoes", "", "organization", "VARCHAR", "255", "", "", "NOT NULL", "manifest");
30 if ($oldversion < 2004071900) {
31 table_column("scorm", "", "maxgrade", "FLOAT", "3", "", "0", "NOT NULL", "reference");
32 table_column("scorm", "", "grademethod", "TINYINT", "2", "", "0", "NOT NULL", "maxgrade");
35 if ($oldversion < 2004111200) {
36 execute_sql("ALTER TABLE {$CFG->prefix}scorm DROP INDEX course;",false);
37 execute_sql("ALTER TABLE {$CFG->prefix}scorm_scoes DROP INDEX scorm;",false);
38 execute_sql("ALTER TABLE {$CFG->prefix}scorm_sco_users DROP INDEX scormid;",false);
39 execute_sql("ALTER TABLE {$CFG->prefix}scorm_sco_users DROP INDEX userid;",false);
40 execute_sql("ALTER TABLE {$CFG->prefix}scorm_sco_users DROP INDEX scoid;",false);
42 modify_database('','ALTER TABLE prefix_scorm ADD INDEX course (course);');
43 modify_database('','ALTER TABLE prefix_scorm_scoes ADD INDEX scorm (scorm);');
44 modify_database('','ALTER TABLE prefix_scorm_sco_users ADD INDEX scormid (scormid);');
45 modify_database('','ALTER TABLE prefix_scorm_sco_users ADD INDEX userid (userid);');
46 modify_database('','ALTER TABLE prefix_scorm_sco_users ADD INDEX scoid (scoid);');
49 if ($oldversion < 2005031300) {
50 table_column("scorm_scoes", "", "prerequisites", "VARCHAR", "200", "", "", "NOT NULL", "title");
51 table_column("scorm_scoes", "", "maxtimeallowed", "VARCHAR", "13", "", "", "NOT NULL", "prerequisites");
52 table_column("scorm_scoes", "", "timelimitaction", "VARCHAR", "19", "", "", "NOT NULL", "maxtimeallowed");
53 table_column("scorm_scoes", "", "masteryscore", "VARCHAR", "200", "", "", "NOT NULL", "datafromlms");
55 $oldscoes = get_records_select("scorm_scoes","1","id ASC");
56 table_column("scorm_scoes", "type", "scormtype", "VARCHAR", "5", "", "", "NOT NULL");
57 if(!empty($oldscoes)) {
58 foreach ($oldscoes as $sco) {
59 $sco->scormtype
= $sco->type
;
61 update_record("scorm_scoes",$sco);
65 execute_sql("CREATE TABLE {$CFG->prefix}scorm_scoes_track (
66 id int(10) unsigned NOT NULL auto_increment,
67 userid int(10) unsigned NOT NULL default '0',
68 scormid int(10) NOT NULL default '0',
69 scoid int(10) unsigned NOT NULL default '0',
70 element varchar(255) NOT NULL default '',
71 value longtext NOT NULL default '',
72 PRIMARY KEY (userid, scormid, scoid, element),
73 UNIQUE (userid, scormid, scoid, element),
74 KEY userdata (userid, scormid, scoid),
76 ) TYPE=MyISAM;",false);
78 $oldtrackingdata = get_records_select("scorm_sco_users","1","id ASC");
79 $oldelements = array ('cmi_core_lesson_location',
80 'cmi_core_lesson_status',
82 'cmi_core_total_time',
86 if(!empty($oldtrackingdata)) {
87 foreach ($oldtrackingdata as $oldtrack) {
89 $newtrack->userid
= $oldtrack->userid
;
90 $newtrack->scormid
= $oldtrack->scormid
;
91 $newtrack->scoid
= $oldtrack->scoid
;
93 foreach ( $oldelements as $element) {
94 $newtrack->element
= $element;
95 $newtrack->value
= $oldtrack->$element;
96 if ($newtrack->value
== NULL) {
97 $newtrack->value
= '';
99 insert_record("scorm_scoes_track",$newtrack,false);
104 modify_database('',"DROP TABLE prefix_scorm_sco_users");
105 modify_database('',"INSERT INTO prefix_log_display (module, action, mtable, field) VALUES ('scorm', 'review', 'resource', 'name')");
108 if ($oldversion < 2005040200) {
109 execute_sql('ALTER TABLE `'.$CFG->prefix
.'scorm` DROP `popup`'); // Old field
112 if ($oldversion < 2005040400) {
113 table_column("scorm_scoes", "", "parameters", "VARCHAR", "255", "", "", "NOT NULL", "launch");
116 if ($oldversion < 2005040700) {
117 execute_sql("ALTER TABLE {$CFG->prefix}scorm_scoes_track DROP PRIMARY KEY;");
118 execute_sql("ALTER TABLE {$CFG->prefix}scorm_scoes_track DROP KEY userdata;");
119 execute_sql("ALTER TABLE {$CFG->prefix}scorm_scoes_track DROP INDEX userid");
120 modify_database('','ALTER TABLE prefix_scorm_scoes_track ADD UNIQUE track (userid,scormid,scoid,element);');
121 modify_database('','ALTER TABLE prefix_scorm_scoes_track ADD PRIMARY KEY id (id);');
122 modify_database('','ALTER TABLE prefix_scorm_scoes_track ADD INDEX scormid (scormid);');
123 modify_database('','ALTER TABLE prefix_scorm_scoes_track ADD INDEX userid (userid);');
124 modify_database('','ALTER TABLE prefix_scorm_scoes_track ADD INDEX scoid (scoid);');
125 modify_database('','ALTER TABLE prefix_scorm_scoes_track ADD INDEX element (element);');
126 execute_sql("ALTER TABLE {$CFG->prefix}scorm_scoes_track DROP INDEX id;");
127 table_column("scorm_scoes", "timelimitaction", "timelimitaction", "VARCHAR", "19", "", "", "NOT NULL");
128 table_column("scorm_scoes", "scormtype", "scormtype", "VARCHAR", "5", "", "", "NOT NULL");
131 if ($oldversion < 2005041500) {
132 if ($scorms = get_records_select("scorm","1","id ASC")) {
133 foreach ($scorms as $scorm) {
134 if (strlen($scorm->datadir
) == 14) {
135 $basedir = $CFG->dataroot
.'/'.$scorm->course
;
136 $scormdir = '/moddata/scorm';
137 rename($basedir.$scormdir.$scorm->datadir
,$basedir.$scormdir.'/'.$scorm->id
);
141 execute_sql('ALTER TABLE `'.$CFG->prefix
.'scorm` DROP `datadir`'); // Old field
144 if ($oldversion < 2005041600) {
145 table_column("scorm", "", "version", "VARCHAR", "9", "", "SCORM_1.2", "NOT NULL", "reference");
148 if ($oldversion < 2005042700) {
149 $trackingdata = get_records_select("scorm_scoes_track","1","id ASC");
150 if (!empty($trackingdata)) {
151 $oldelements = array ('cmi_core_lesson_location',
152 'cmi_core_lesson_status',
154 'cmi_core_total_time',
155 'cmi_core_score_raw',
157 $newelements = array ('cmi.core.lesson_location',
158 'cmi.core.lesson_status',
160 'cmi.core.total_time',
161 'cmi.core.score.raw',
163 foreach ($trackingdata as $track) {
164 if (($pos = array_search($track->element
,$oldelements)) !== false) {
165 $track->element
= $newelements[$pos];
166 update_record('scorm_scoes_track',$track);
172 if ($oldversion < 2005042800) {
173 table_column("scorm", "", "browsemode", "TINYINT", "2", "", "1", "NOT NULL", "summary");
176 if ($oldversion < 2005050800) {
177 table_column("scorm", "", "width", "INT", "10", "", "800", "NOT NULL", "auto");
178 table_column("scorm", "", "height", "INT", "10", "", "600", "NOT NULL", "width");
181 if ($oldversion < 2005052200) {
182 table_column("scorm_scoes_track", "", "timemodified", "INT", "10", "UNSIGNED", "0", "NOT NULL", "value");
185 if ($oldversion < 2005052700) {
186 table_column("scorm", "", "popup", "TINYINT", "1", "UNSIGNED", "0", "NOT NULL", "auto");
189 if ($oldversion < 2005070600) {
190 table_column("scorm", "", "hidetoc", "TINYINT", "1", "UNSIGNED", "0", "NOT NULL", "browsemode");
191 $scorms = get_records_select("scorm","1","id ASC");
192 table_column("scorm", "browsemode", "hidebrowse", "TINYINT", "1", "UNSIGNED", "0", "NOT NULL", "");
193 if (!empty($scorms)) {
194 foreach($scorms as $scorm) {
195 if ($scorm->browsemode
= 1) {
196 $scorm->hidebrowse
= 0;
198 $scorm->hidebrowse
= 1;
200 update_record('scorm',$scorm);
205 if ($oldversion < 2005092500) {
206 table_column("scorm", "", "hidenav", "TINYINT", "1", "UNSIGNED", "0", "NOT NULL", "hidetoc");
207 table_column("scorm", "", "options", "VARCHAR", "255", "", "", "NOT NULL","popup");
210 if ($oldversion < 2005092600) {
211 table_column("scorm_scoes_track", "", "attempt", "INT", "10", "UNSIGNED", "1", "NOT NULL", "scoid");
212 execute_sql("ALTER TABLE {$CFG->prefix}scorm_scoes_track DROP INDEX track");
213 modify_database('','ALTER TABLE prefix_scorm_scoes_track ADD UNIQUE track (userid,scormid,scoid,attempt,element);');
216 if ($oldversion < 2005102800) {
217 table_column("scorm", "", "maxattempt", "INT", "10", "UNSIGNED", "1", "NOT NULL", "maxgrade");
220 if ($oldversion < 2006021400) { //some people have this werid key - see bug 4742
221 execute_sql("ALTER TABLE {$CFG->prefix}scorm_scoes_track DROP INDEX elemeny;",false); // do it silently
222 execute_sql("ALTER TABLE {$CFG->prefix}scorm_scoes_track ADD INDEX element(element(255));",false);
225 if ($oldversion < 2006102600) {
226 table_column("scorm", "", "skipview", "TINYINT", "1", "UNSIGNED", "1", "NOT NULL", "launch");
229 if ($oldversion < 2006102702) { /// A month in advance!
230 execute_sql("DELETE FROM {$CFG->prefix}log_display WHERE module = 'scorm' AND action = 'review' AND mtable = 'resource' AND field = 'name';", false); // MDL-6516
231 execute_sql("INSERT INTO {$CFG->prefix}log_display (module, action, mtable, field) VALUES ('scorm', 'review', 'scorm', 'name');", false);
234 ////// DO NOT ADD NEW THINGS HERE!! USE upgrade.php and the lib/ddllib.php functions.