3 // This file keeps track of upgrades to
6 // Sometimes, changes between versions involve
7 // alterations to database structures and other
8 // major things that may break installations.
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.
14 // If there's something it cannot do itself, it
15 // will tell you what you need to do.
17 // The commands in here will all be database-neutral,
18 // using the functions defined in lib/ddllib.php
20 function xmldb_scorm_upgrade($oldversion=0) {
22 global $CFG, $THEME, $db;
26 if ($result && $oldversion < 2006103100) {
27 /// Create the new sco optionals data table
29 /// Define table scorm_scoes_data to be created
30 $table = new XMLDBTable('scorm_scoes_data');
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);
38 /// Adding keys to table scorm_scoes_data
39 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
41 /// Adding indexes to table scorm_scoes_data
42 $table->addIndexInfo('scoid', XMLDB_INDEX_NOTUNIQUE
, array('scoid'));
44 /// Launch create table for scorm_scoes_data
45 $result = $result && create_table($table);
47 /// The old fields used in scorm_scoes
48 $fields = array('parameters' => '',
49 'prerequisites' => '',
50 'maxtimeallowed' => '',
51 'timelimitaction' => '',
57 /// Retrieve old datas
58 if ($scorms = get_records('scorm')) {
59 foreach ($scorms as $scorm) {
60 if ($olddatas = get_records('scorm_scoes','scorm', $scorm->id
)) {
61 foreach ($olddatas as $olddata) {
62 $newdata = new stdClass();
63 $newdata->scoid
= $olddata->id
;
64 foreach ($fields as $field => $value) {
65 if ($olddata->$field != $value) {
66 $newdata->name
= addslashes($field);
67 $newdata->value
= addslashes($olddata->$field);
68 $id = insert_record('scorm_scoes_data', $newdata);
69 $result = $result && ($id != 0);
77 /// Remove no more used fields
78 $table = new XMLDBTable('scorm_scoes');
80 foreach ($fields as $field => $value) {
81 $field = new XMLDBField($field);
82 $result = $result && drop_field($table, $field);
86 if ($result && $oldversion < 2006120900) {
87 /// Define table scorm_seq_objective to be created
88 $table = new XMLDBTable('scorm_seq_objective');
90 /// Adding fields to table scorm_seq_objective
91 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
92 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
93 $table->addFieldInfo('primaryobj', XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '0');
94 $table->addFieldInfo('objectiveid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
95 $table->addFieldInfo('satisfiedbymeasure', XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '1');
96 $table->addFieldInfo('minnormalizedmeasure', XMLDB_TYPE_FLOAT
, '11, 4', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0.0000');
98 /// Adding keys to table scorm_seq_objective
99 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
100 $table->addKeyInfo('scorm_objective_uniq', XMLDB_KEY_UNIQUE
, array('scoid', 'id'));
101 $table->addKeyInfo('scorm_objective_scoid', XMLDB_KEY_FOREIGN
, array('scoid'), 'scorm_scoes', array('id'));
103 /// Launch create table for scorm_seq_objective
104 $result = $result && create_table($table);
106 /// Define table scorm_seq_mapinfo to be created
107 $table = new XMLDBTable('scorm_seq_mapinfo');
109 /// Adding fields to table scorm_seq_mapinfo
110 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
111 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
112 $table->addFieldInfo('objectiveid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
113 $table->addFieldInfo('targetobjectiveid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
114 $table->addFieldInfo('readsatisfiedstatus', XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '1');
115 $table->addFieldInfo('readnormalizedmeasure', XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '1');
116 $table->addFieldInfo('writesatisfiedstatus', XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '0');
117 $table->addFieldInfo('writenormalizedmeasure', XMLDB_TYPE_INTEGER
, '1', null, XMLDB_NOTNULL
, null, null, null, '0');
119 /// Adding keys to table scorm_seq_mapinfo
120 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
121 $table->addKeyInfo('scorm_mapinfo_uniq', XMLDB_KEY_UNIQUE
, array('scoid', 'id', 'objectiveid'));
122 $table->addKeyInfo('scorm_mapinfo_scoid', XMLDB_KEY_FOREIGN
, array('scoid'), 'scorm_scoes', array('id'));
123 $table->addKeyInfo('scorm_mapinfo_objectiveid', XMLDB_KEY_FOREIGN
, array('objectiveid'), 'scorm_seq_objective', array('id'));
125 /// Launch create table for scorm_seq_mapinfo
126 $result = $result && create_table($table);
128 /// Define table scorm_seq_ruleconds to be created
129 $table = new XMLDBTable('scorm_seq_ruleconds');
131 /// Adding fields to table scorm_seq_ruleconds
132 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
133 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
134 $table->addFieldInfo('conditioncombination', XMLDB_TYPE_CHAR
, '3', null, XMLDB_NOTNULL
, null, null, null, 'all');
135 $table->addFieldInfo('ruletype', XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
136 $table->addFieldInfo('action', XMLDB_TYPE_CHAR
, '25', null, XMLDB_NOTNULL
, null, null, null, null);
138 /// Adding keys to table scorm_seq_ruleconds
139 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
140 $table->addKeyInfo('scorm_ruleconds_un', XMLDB_KEY_UNIQUE
, array('scoid', 'id'));
141 $table->addKeyInfo('scorm_ruleconds_scoid', XMLDB_KEY_FOREIGN
, array('scoid'), 'scorm_scoes', array('id'));
143 /// Launch create table for scorm_seq_ruleconds
144 $result = $result && create_table($table);
146 /// Define table scorm_seq_rulecond to be created
147 $table = new XMLDBTable('scorm_seq_rulecond');
149 /// Adding fields to table scorm_seq_rulecond
150 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
151 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
152 $table->addFieldInfo('ruleconditionsid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
153 $table->addFieldInfo('refrencedobjective', XMLDB_TYPE_CHAR
, '255', null, XMLDB_NOTNULL
, null, null, null, null);
154 $table->addFieldInfo('measurethreshold', XMLDB_TYPE_FLOAT
, '11, 4', null, XMLDB_NOTNULL
, null, null, null, '0.0000');
155 $table->addFieldInfo('operator', XMLDB_TYPE_CHAR
, '5', null, XMLDB_NOTNULL
, null, null, null, 'noOp');
156 $table->addFieldInfo('cond', XMLDB_TYPE_CHAR
, '30', null, XMLDB_NOTNULL
, null, null, null, 'always');
158 /// Adding keys to table scorm_seq_rulecond
159 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
160 $table->addKeyInfo('scorm_rulecond_uniq', XMLDB_KEY_UNIQUE
, array('id', 'scoid', 'ruleconditionsid'));
161 $table->addKeyInfo('scorm_rulecond_scoid', XMLDB_KEY_FOREIGN
, array('scoid'), 'scorm_scoes', array('id'));
162 $table->addKeyInfo('scorm_rulecond_ruleconditionsid', XMLDB_KEY_FOREIGN
, array('ruleconditionsid'), 'scorm_seq_ruleconds', array('id'));
164 /// Launch create table for scorm_seq_rulecond
165 $result = $result && create_table($table);
167 /// Define table scorm_seq_rolluprule to be created
168 $table = new XMLDBTable('scorm_seq_rolluprule');
170 /// Adding fields to table scorm_seq_rolluprule
171 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
172 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
173 $table->addFieldInfo('childactivityset', XMLDB_TYPE_CHAR
, '15', null, XMLDB_NOTNULL
, null, null, null, null);
174 $table->addFieldInfo('minimumcount', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
175 $table->addFieldInfo('minimumpercent', XMLDB_TYPE_FLOAT
, '11, 4', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0.0000');
176 $table->addFieldInfo('conditioncombination', XMLDB_TYPE_CHAR
, '3', null, XMLDB_NOTNULL
, null, null, null, 'all');
177 $table->addFieldInfo('action', XMLDB_TYPE_CHAR
, '15', null, XMLDB_NOTNULL
, null, null, null, null);
179 /// Adding keys to table scorm_seq_rolluprule
180 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
181 $table->addKeyInfo('scorm_rolluprule_uniq', XMLDB_KEY_UNIQUE
, array('scoid', 'id'));
182 $table->addKeyInfo('scorm_rolluprule_scoid', XMLDB_KEY_FOREIGN
, array('scoid'), 'scorm_scoes', array('id'));
184 /// Launch create table for scorm_seq_rolluprule
185 $result = $result && create_table($table);
187 /// Define table scorm_seq_rolluprulecond to be created
188 $table = new XMLDBTable('scorm_seq_rolluprulecond');
190 /// Adding fields to table scorm_seq_rolluprulecond
191 $table->addFieldInfo('id', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, XMLDB_SEQUENCE
, null, null, null);
192 $table->addFieldInfo('scoid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
193 $table->addFieldInfo('rollupruleid', XMLDB_TYPE_INTEGER
, '10', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0');
194 $table->addFieldInfo('operator', XMLDB_TYPE_CHAR
, '5', null, XMLDB_NOTNULL
, null, null, null, 'noOp');
195 $table->addFieldInfo('cond', XMLDB_TYPE_CHAR
, '25', null, XMLDB_NOTNULL
, null, null, null, null);
197 /// Adding keys to table scorm_seq_rolluprulecond
198 $table->addKeyInfo('primary', XMLDB_KEY_PRIMARY
, array('id'));
199 $table->addKeyInfo('scorm_rulluprulecond_uniq', XMLDB_KEY_UNIQUE
, array('scoid', 'rollupruleid', 'id'));
200 $table->addKeyInfo('scorm_rolluprulecond_scoid', XMLDB_KEY_FOREIGN
, array('scoid'), 'scorm_scoes', array('id'));
201 $table->addKeyInfo('scorm_rolluprulecond_rolluprule', XMLDB_KEY_FOREIGN
, array('rollupruleid'), 'scorm_seq_rolluprule', array('id'));
203 /// Launch create table for scorm_seq_rolluprulecond
204 $result = $result && create_table($table);
207 //Adding new field to table scorm
208 if ($result && $oldversion < 2007011800) {
210 /// Define field format to be added to data_comments
211 $table = new XMLDBTable('scorm');
212 $field = new XMLDBField('md5_result');
213 $field->setAttributes(XMLDB_TYPE_CHAR
, '32' , null, null, null, null, null, null, null);
215 /// Launch add field format
216 $result = $result && add_field($table, $field);
218 $field = new XMLDBField('external');
219 $field->setAttributes(XMLDB_TYPE_INTEGER
, '2', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', null);
221 $result = $result && add_field($table, $field);
224 if ($result && $oldversion < 2007012400) {
226 /// Rename field external on table scorm to updatefreq
227 $table = new XMLDBTable('scorm');
228 $field = new XMLDBField('external');
230 if (field_exists($table, $field)) {
231 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'maxattempt');
233 /// Launch rename field updatefreq
234 $result = $result && rename_field($table, $field, 'updatefreq');
236 $field = new XMLDBField('updatefreq');
237 $field->setAttributes(XMLDB_TYPE_INTEGER
, '1', XMLDB_UNSIGNED
, XMLDB_NOTNULL
, null, null, null, '0', 'maxattempt');
239 $result = $result && add_field($table, $field);
242 /// Rename field md5_result on table scorm to md5hash
243 $field = new XMLDBField('md5_result');
244 if (field_exists($table, $field)) {
245 $field->setAttributes(XMLDB_TYPE_CHAR
, '32', null, XMLDB_NOTNULL
, null, null, null, null, 'updatefreq');
247 /// Launch rename field md5hash
248 $result = $result && rename_field($table, $field, 'md5hash');
250 $field = new XMLDBField('md5hash');
251 $field->setAttributes(XMLDB_TYPE_CHAR
, '32', null, XMLDB_NOTNULL
, null, null, null, '', 'updatefreq');
253 $result = $result && add_field($table, $field);
257 if ($result && $oldversion < 2007031300) {
258 if ($scorms = get_records('scorm')) {
259 foreach ($scorms as $scorm) {
260 if ($scoes = get_records('scorm_scoes','scorm',$scorm->id
)) {
261 foreach ($scoes as $sco) {
262 if ($tracks = get_records('scorm_scoes_track','scoid',$sco->id
)) {
263 foreach ($tracks as $track) {
264 $element = preg_replace('/\.N(\d+)\./',".\$1.",$track->element
);
265 if ($track->element
!= $element) {
266 $track->element
= $element;
267 update_record('scorm_scoes_track',$track);
277 if ($result && $oldversion < 2007081001) {
278 require_once($CFG->dirroot
.'/mod/scorm/lib.php');
279 // too much debug output
281 scorm_update_grades();