Added the field external to the mdl_scorm table
[moodle.git] / mod / scorm / db / upgrade.php
CommitLineData
b8a342d7 1<?php //$Id$
2
3// This file keeps track of upgrades to
4// the scorm module
5//
6// Sometimes, changes between versions involve
7// alterations to database structures and other
8// major things that may break installations.
9//
10// The upgrade function in this file will attempt
11// to perform all the necessary actions to upgrade
12// your older installtion to the current version.
13//
14// If there's something it cannot do itself, it
15// will tell you what you need to do.
16//
17// The commands in here will all be database-neutral,
18// using the functions defined in lib/ddllib.php
19
20function xmldb_scorm_upgrade($oldversion=0) {
21
22 global $CFG, $THEME, $db;
23
24 $result = true;
25
b3659259 26 if ($result && $oldversion < 2006103100) {
27 /// Create the new sco optionals data table
28
29 /// Define table scorm_scoes_data to be created
30 $table = new XMLDBTable('scorm_scoes_data');
31
32 /// Adding fields to table scorm_scoes_data
33 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
34 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
35 $table->addFieldInfo('name', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
36 $table->addFieldInfo('value', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, null, null);
37
38 /// Adding keys to table scorm_scoes_data
39 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
40
41 /// Adding indexes to table scorm_scoes_data
42 $table->addIndexInfo('scoid', XMLDB_INDEX_NOTUNIQUE, array('scoid'));
43
44 /// Launch create table for scorm_scoes_data
45 $result = $result && create_table($table);
46
47 /// The old fields used in scorm_scoes
48 $fields = array('parameters' => '',
49 'prerequisites' => '',
50 'maxtimeallowed' => '',
51 'timelimitaction' => '',
52 'datafromlms' => '',
53 'masteryscore' => '',
54 'next' => '0',
55 'previous' => '0');
56
57 /// Retrieve old datas
58 if ($olddatas = get_records('scorm_scoes')) {
59 foreach ($olddatas as $olddata) {
60 $newdata = new stdClass();
61 $newdata->scoid = $olddata->id;
62 foreach ($fields as $field => $value) {
63 if ($olddata->$field != $value) {
64 $newdata->name = addslashes($field);
65 $newdata->value = addslashes($olddata->$field);
66 $id = insert_record('scorm_scoes_data', $newdata);
67 $result = $result && ($id != 0);
68 }
69 }
70 }
71 }
72
73 /// Remove no more used fields
74 $table = new XMLDBTable('scorm_scoes');
75
76 foreach ($fields as $field => $value) {
77 $field = new XMLDBField($field);
78 $result = $result && drop_field($table, $field);
79 }
80 }
b8a342d7 81
0e1bf350 82 if ($result && $oldversion < 2006120900) {
83 /// Define table scorm_seq_objective to be created
84 $table = new XMLDBTable('scorm_seq_objective');
85
86 /// Adding fields to table scorm_seq_objective
87 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
88 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
89 $table->addFieldInfo('primaryobj', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0');
90 $table->addFieldInfo('objectiveid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
91 $table->addFieldInfo('satisfiedbymeasure', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1');
92 $table->addFieldInfo('minnormalizedmeasure', XMLDB_TYPE_FLOAT, '11, 4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0.0000');
93
94 /// Adding keys to table scorm_seq_objective
95 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
96 $table->addKeyInfo('scorm_objective_uniq', XMLDB_KEY_UNIQUE, array('scoid', 'id'));
97 $table->addKeyInfo('scorm_objective_scoid', XMLDB_KEY_FOREIGN, array('scoid'), 'scorm_scoes', array('id'));
98
99 /// Launch create table for scorm_seq_objective
100 $result = $result && create_table($table);
101
102 /// Define table scorm_seq_mapinfo to be created
103 $table = new XMLDBTable('scorm_seq_mapinfo');
104
105 /// Adding fields to table scorm_seq_mapinfo
106 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
107 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
108 $table->addFieldInfo('objectiveid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
109 $table->addFieldInfo('targetobjectiveid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
110 $table->addFieldInfo('readsatisfiedstatus', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1');
111 $table->addFieldInfo('readnormalizedmeasure', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '1');
112 $table->addFieldInfo('writesatisfiedstatus', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0');
113 $table->addFieldInfo('writenormalizedmeasure', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, null, null, '0');
114
115 /// Adding keys to table scorm_seq_mapinfo
116 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
117 $table->addKeyInfo('scorm_mapinfo_uniq', XMLDB_KEY_UNIQUE, array('scoid', 'id', 'objectiveid'));
118 $table->addKeyInfo('scorm_mapinfo_scoid', XMLDB_KEY_FOREIGN, array('scoid'), 'scorm_scoes', array('id'));
119 $table->addKeyInfo('scorm_mapinfo_objectiveid', XMLDB_KEY_FOREIGN, array('objectiveid'), 'scorm_seq_objective', array('id'));
120
121 /// Launch create table for scorm_seq_mapinfo
122 $result = $result && create_table($table);
123
124 /// Define table scorm_seq_ruleconds to be created
125 $table = new XMLDBTable('scorm_seq_ruleconds');
126
127 /// Adding fields to table scorm_seq_ruleconds
128 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
129 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
130 $table->addFieldInfo('conditioncombination', XMLDB_TYPE_CHAR, '3', null, XMLDB_NOTNULL, null, null, null, 'all');
131 $table->addFieldInfo('ruletype', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
132 $table->addFieldInfo('action', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, null, null, null);
133
134 /// Adding keys to table scorm_seq_ruleconds
135 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
136 $table->addKeyInfo('scorm_ruleconds_un', XMLDB_KEY_UNIQUE, array('scoid', 'id'));
137 $table->addKeyInfo('scorm_ruleconds_scoid', XMLDB_KEY_FOREIGN, array('scoid'), 'scorm_scoes', array('id'));
138
139 /// Launch create table for scorm_seq_ruleconds
140 $result = $result && create_table($table);
141
142 /// Define table scorm_seq_rulecond to be created
143 $table = new XMLDBTable('scorm_seq_rulecond');
144
145 /// Adding fields to table scorm_seq_rulecond
146 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
147 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
148 $table->addFieldInfo('ruleconditionsid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
149 $table->addFieldInfo('refrencedobjective', XMLDB_TYPE_CHAR, '255', null, XMLDB_NOTNULL, null, null, null, null);
150 $table->addFieldInfo('measurethreshold', XMLDB_TYPE_FLOAT, '11, 4', null, XMLDB_NOTNULL, null, null, null, '0.0000');
151 $table->addFieldInfo('operator', XMLDB_TYPE_CHAR, '5', null, XMLDB_NOTNULL, null, null, null, 'noOp');
152 $table->addFieldInfo('cond', XMLDB_TYPE_CHAR, '30', null, XMLDB_NOTNULL, null, null, null, 'always');
153
154 /// Adding keys to table scorm_seq_rulecond
155 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
156 $table->addKeyInfo('scorm_rulecond_uniq', XMLDB_KEY_UNIQUE, array('id', 'scoid', 'ruleconditionsid'));
157 $table->addKeyInfo('scorm_rulecond_scoid', XMLDB_KEY_FOREIGN, array('scoid'), 'scorm_scoes', array('id'));
158 $table->addKeyInfo('scorm_rulecond_ruleconditionsid', XMLDB_KEY_FOREIGN, array('ruleconditionsid'), 'scorm_seq_ruleconds', array('id'));
159
160 /// Launch create table for scorm_seq_rulecond
161 $result = $result && create_table($table);
162
163 /// Define table scorm_seq_rolluprule to be created
164 $table = new XMLDBTable('scorm_seq_rolluprule');
165
166 /// Adding fields to table scorm_seq_rolluprule
167 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
168 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
169 $table->addFieldInfo('childactivityset', XMLDB_TYPE_CHAR, '15', null, XMLDB_NOTNULL, null, null, null, null);
170 $table->addFieldInfo('minimumcount', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
171 $table->addFieldInfo('minimumpercent', XMLDB_TYPE_FLOAT, '11, 4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0.0000');
172 $table->addFieldInfo('conditioncombination', XMLDB_TYPE_CHAR, '3', null, XMLDB_NOTNULL, null, null, null, 'all');
173 $table->addFieldInfo('action', XMLDB_TYPE_CHAR, '15', null, XMLDB_NOTNULL, null, null, null, null);
174
175 /// Adding keys to table scorm_seq_rolluprule
176 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
177 $table->addKeyInfo('scorm_rolluprule_uniq', XMLDB_KEY_UNIQUE, array('scoid', 'id'));
178 $table->addKeyInfo('scorm_rolluprule_scoid', XMLDB_KEY_FOREIGN, array('scoid'), 'scorm_scoes', array('id'));
179
180 /// Launch create table for scorm_seq_rolluprule
181 $result = $result && create_table($table);
182
183 /// Define table scorm_seq_rolluprulecond to be created
184 $table = new XMLDBTable('scorm_seq_rolluprulecond');
185
186 /// Adding fields to table scorm_seq_rolluprulecond
187 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, XMLDB_SEQUENCE, null, null, null);
188 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
189 $table->addFieldInfo('rollupruleid', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0');
190 $table->addFieldInfo('operator', XMLDB_TYPE_CHAR, '5', null, XMLDB_NOTNULL, null, null, null, 'noOp');
191 $table->addFieldInfo('cond', XMLDB_TYPE_CHAR, '25', null, XMLDB_NOTNULL, null, null, null, null);
192
193 /// Adding keys to table scorm_seq_rolluprulecond
194 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY, array('id'));
195 $table->addKeyInfo('scorm_rulluprulecond_uniq', XMLDB_KEY_UNIQUE, array('scoid', 'rollupruleid', 'id'));
196 $table->addKeyInfo('scorm_rolluprulecond_scoid', XMLDB_KEY_FOREIGN, array('scoid'), 'scorm_scoes', array('id'));
197 $table->addKeyInfo('scorm_rolluprulecond_rolluprule', XMLDB_KEY_FOREIGN, array('rollupruleid'), 'scorm_seq_rolluprule', array('id'));
198
199 /// Launch create table for scorm_seq_rolluprulecond
200 $result = $result && create_table($table);
201 }
202
aa7a1713 203 //Adding new field to table scorm
efe95fc4 204 if ($result && $oldversion < 2007011800) {
aa7a1713 205
206 /// Define field format to be added to data_comments
207 $table = new XMLDBTable('scorm');
208 $field = new XMLDBField('md5_result');
efe95fc4 209 $field->setAttributes(XMLDB_TYPE_CHAR, '32' , null, null, null, null, null, null, null);
aa7a1713 210
211 /// Launch add field format
212 $result = $result && add_field($table, $field);
213
efe95fc4 214 $field = new XMLDBField('external');
215 $field->setAttributes(XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, null, null, '0', null);
216 $result = $result && add_field($table, $field);
217
218
aa7a1713 219 }
0e1bf350 220
b8a342d7 221 return $result;
222}
223
224?>