Merge branch 'MDL-26440_uid' of git://github.com/andyjdavis/moodle
[moodle.git] / mod / scorm / db / upgrade.php
CommitLineData
e5dd8e3b 1<?php
b8a342d7 2
9528568b 3// This file keeps track of upgrades to
b8a342d7 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
2e0406a5 12// your older installation to the current version.
b8a342d7 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,
b1f93b15 18// using the methods of database_manager class
775f811a 19//
20// Please do not forget to use upgrade_set_timeout()
21// before any action that may take longer time to finish.
b8a342d7 22
b964171c
SH
23/**
24 * @global moodle_database $DB
25 * @param int $oldversion
26 * @return bool
27 */
775f811a 28function xmldb_scorm_upgrade($oldversion) {
29 global $CFG, $DB;
b8a342d7 30
c57ce9f2 31 $dbman = $DB->get_manager();
b8a342d7 32
219f652b 33//===== 1.9.0 upgrade line ======//
9858605e 34
c57ce9f2 35 // Adding missing 'whatgrade' field to table scorm
a4cdd6d2 36 if ($oldversion < 2008073000) {
c57ce9f2 37 $table = new xmldb_table('scorm');
38 $field = new xmldb_field('whatgrade');
2a88f626 39 $field->set_attributes(XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'grademethod');
9528568b 40
c57ce9f2 41 /// Launch add field whatgrade
775f811a 42 if (!$dbman->field_exists($table,$field)) {
c57ce9f2 43 $dbman->add_field($table, $field);
d682eadf 44 $whatgradefixed = get_config('scorm', 'whatgradefixed');
b326c85a
DM
45 if (empty($whatgradefixed)) {
46 /// fix bad usage of whatgrade/grading method.
47 $scorms = $DB->get_records('scorm');
0744fded
PS
48 foreach ($scorms as $scorm) {
49 $scorm->whatgrade = $scorm->grademethod/10;
50 $DB->update_record('scorm', $scorm);
b326c85a 51 }
07b21d04 52 }
b326c85a
DM
53 } else {
54 //dump this config var as it isn't needed anymore.
55 unset_config('whatgradefixed', 'scorm');
c57ce9f2 56 }
9528568b 57
a4cdd6d2 58 upgrade_mod_savepoint(true, 2008073000, 'scorm');
c57ce9f2 59 }
9528568b 60
a4cdd6d2 61 if ($oldversion < 2008082500) {
9528568b 62
63 /// Define field scormtype to be added to scorm
64 $table = new xmldb_table('scorm');
2a88f626 65 $field = new xmldb_field('scormtype', XMLDB_TYPE_CHAR, '50', null, XMLDB_NOTNULL, null, 'local', 'name');
9528568b 66
67 /// Launch add field scormtype
68 $dbman->add_field($table, $field);
69
70 /// scorm savepoint reached
a4cdd6d2 71 upgrade_mod_savepoint(true, 2008082500, 'scorm');
9528568b 72 }
73
a4cdd6d2 74 if ($oldversion < 2008090300) {
9528568b 75
76 /// Define field sha1hash to be added to scorm
77 $table = new xmldb_table('scorm');
2a88f626 78 $field = new xmldb_field('sha1hash', XMLDB_TYPE_CHAR, '40', null, null, null, null, 'updatefreq');
9528568b 79
80 /// Launch add field sha1hash
81 $dbman->add_field($table, $field);
82
83 /// scorm savepoint reached
a4cdd6d2 84 upgrade_mod_savepoint(true, 2008090300, 'scorm');
9528568b 85 }
86
a4cdd6d2 87 if ($oldversion < 2008090301) {
9528568b 88
89 /// Define field revision to be added to scorm
90 $table = new xmldb_table('scorm');
2a88f626 91 $field = new xmldb_field('revision', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'md5hash');
9528568b 92
93 /// Launch add field revision
94 $dbman->add_field($table, $field);
95
96 /// scorm savepoint reached
a4cdd6d2 97 upgrade_mod_savepoint(true, 2008090301, 'scorm');
9528568b 98 }
99
a4cdd6d2 100 if ($oldversion < 2008090302) {
9528568b 101 $sql = "UPDATE {scorm}
102 SET scormtype = 'external'
103 WHERE reference LIKE ? OR reference LIKE ? OR reference LIKE ?";
104 $DB->execute($sql, array('http://%imsmanifest.xml', 'https://%imsmanifest.xml', 'www.%imsmanifest.xml'));
105
106 $sql = "UPDATE {scorm}
107 SET scormtype = 'localsync'
108 WHERE reference LIKE ? OR reference LIKE ? OR reference LIKE ?
109 OR reference LIKE ? OR reference LIKE ? OR reference LIKE ?";
110 $DB->execute($sql, array('http://%.zip', 'https://%.zip', 'www.%.zip', 'http://%.pif', 'https://%.pif', 'www.%.pif'));
111
112 $sql = "UPDATE {scorm} SET scormtype = 'imsrepository' WHERE reference LIKE ?";
113 $DB->execute($sql, array('#%'));
114
115 /// scorm savepoint reached
a4cdd6d2 116 upgrade_mod_savepoint(true, 2008090302, 'scorm');
9528568b 117 }
118
a4cdd6d2 119 if ($oldversion < 2008090303) {
9528568b 120 //remove obsoleted config settings
121 unset_config('scorm_advancedsettings');
122 unset_config('scorm_windowsettings');
123
124 /// scorm savepoint reached
a4cdd6d2 125 upgrade_mod_savepoint(true, 2008090303, 'scorm');
9528568b 126 }
127
a4cdd6d2 128 if ($oldversion < 2008090304) {
9528568b 129 /////////////////////////////////////
130 /// new file storage upgrade code ///
131 /////////////////////////////////////
132
80cfa453 133 require_once("$CFG->dirroot/mod/scorm/db/upgradelib.php");
9528568b 134
135 $fs = get_file_storage();
136
137 $sqlfrom = "FROM {scorm} s
138 JOIN {modules} m ON m.name = 'scorm'
139 JOIN {course_modules} cm ON (cm.module = m.id AND cm.instance = s.id)";
140
141 $count = $DB->count_records_sql("SELECT COUNT('x') $sqlfrom");
142
676874df
EL
143 $rs = $DB->get_recordset_sql("SELECT s.id, s.scormtype, s.reference, s.course, cm.id AS cmid $sqlfrom ORDER BY s.course, s.id");
144 if ($rs->valid()) {
9528568b 145
146 $pbar = new progress_bar('migratescormfiles', 500, true);
147
9528568b 148 $i = 0;
149 foreach ($rs as $scorm) {
150 $i++;
151 upgrade_set_timeout(180); // set up timeout, may also abort execution
152 $pbar->update($i, $count, "Migrating scorm files - $i/$count.");
153
154 $context = get_context_instance(CONTEXT_MODULE, $scorm->cmid);
155 $coursecontext = get_context_instance(CONTEXT_COURSE, $scorm->course);
156
9528568b 157 if ($scorm->scormtype === 'local' and preg_match('/.*(\.zip|\.pif)$/i', $scorm->reference)) {
80cfa453 158 // first copy local packages if found - do not delete in case they are shared ;-)
64f93798
PS
159 $packagefile = clean_param($scorm->reference, PARAM_PATH);
160 $pathnamehash = sha1("/$coursecontext->id/course/legacy/0/$packagefile");
9528568b 161 if ($file = $fs->get_file_by_hash($pathnamehash)) {
80cfa453 162 $file_record = array('contextid'=>$context->id, 'component'=>'mod_scorm', 'filearea'=>'package',
9528568b 163 'itemid'=>0, 'filepath'=>'/');
84683aba
DM
164 try {
165 $fs->create_file_from_storedfile($file_record, $file);
166 } catch (Exception $x) {
80cfa453 167 // ignore any errors, we can not do much anyway
84683aba
DM
168 }
169 $scorm->reference = $file->get_filepath().$file->get_filename();
170
9528568b 171 } else {
172 $scorm->reference = '';
173 }
174 $DB->update_record('scorm', $scorm);
80cfa453
PS
175 // the package should be already extracted, we need to move the files there
176 // just in case somebody modified it directly there
177 scorm_migrate_moddata_files($scorm, $context);
9528568b 178
80cfa453
PS
179 } else if ($scorm->scormtype === 'local' and preg_match('/.*\/imsmanifest\.xml$/i', $scorm->reference)) {
180 // ignore imsmanifest in course root because we would be duplicating all course files which is not acceptable
181 // moddata dir is not used at all, ignore any rubbish there
182 $manifest = clean_param($scorm->reference, PARAM_PATH);
9528568b 183
80cfa453
PS
184 $pathnamehash = sha1("/$coursecontext->id/course/legacy/0/$manifest");
185 if ($file = $fs->get_file_by_hash($pathnamehash)) {
186 $scorm->reference = $file->get_filepath().$file->get_filename();
187
188 $manifestdir = '/'.str_ireplace('/imsmanifest.xml', '', $manifest).'/';
189 $pregmanifestdir = preg_quote($manifestdir, '/');
190 $file_record = array('contextid'=>$context->id, 'component'=>'mod_scorm', 'filearea'=>'content', 'itemid'=>0);
191 if ($files = $fs->get_directory_files($coursecontext->id, 'course', 'legacy', 0, $manifestdir, true)) {
192 foreach ($files as $file) {
193 $file_record['filepath'] = preg_replace("/^$pregmanifestdir/", '/', $file->get_filepath());
194 try {
195 $fs->create_file_from_storedfile($file_record, $file);
196 } catch (Exception $x) {
197 // ignore any errors, we can not do much anyway
198 }
199 }
200 }
201
202 } else {
203 $scorm->reference = '';
204 }
205 $DB->update_record('scorm', $scorm);
206
207 } else {
208 // just try to migrate anything from moddata
209 scorm_migrate_moddata_files($scorm, $context);
210 }
9528568b 211
212 // remove dirs if empty
213 @rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/scorm/$scorm->id/");
214 @rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/scorm/");
215 @rmdir("$CFG->dataroot/$scorm->course/$CFG->moddata/");
216 }
9528568b 217 }
676874df 218 $rs->close();
9528568b 219
220 /// scorm savepoint reached
a4cdd6d2 221 upgrade_mod_savepoint(true, 2008090304, 'scorm');
9528568b 222 }
223
6381fa56 224
a4cdd6d2 225 if ($oldversion < 2008090305) {
6381fa56 226
227 /// Define new fields forcecompleted, forcenewattempt, displayattemptstatus, and displaycoursestructure to be added to scorm
228 $table = new xmldb_table('scorm');
631cefc3 229 $field = new xmldb_field('forcecompleted', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'maxattempt');
6381fa56 230 if (!$dbman->field_exists($table,$field)) {
231 $dbman->add_field($table, $field);
232 }
b964171c 233 $field = new xmldb_field('forcenewattempt', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcecompleted');
6381fa56 234 if (!$dbman->field_exists($table,$field)) {
235 $dbman->add_field($table, $field);
236 }
b964171c 237 $field = new xmldb_field('lastattemptlock', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcenewattempt');
6381fa56 238 if (!$dbman->field_exists($table,$field)) {
239 $dbman->add_field($table, $field);
240 }
b964171c 241 $field = new xmldb_field('displayattemptstatus', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'lastattemptlock');
6381fa56 242 if (!$dbman->field_exists($table,$field)) {
243 $dbman->add_field($table, $field);
244 }
b964171c 245 $field = new xmldb_field('displaycoursestructure', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'displayattemptstatus');
6381fa56 246 if (!$dbman->field_exists($table,$field)) {
247 $dbman->add_field($table, $field);
248 }
65478eea 249
6381fa56 250 /// scorm savepoint reached
a4cdd6d2 251 upgrade_mod_savepoint(true, 2008090305, 'scorm');
6381fa56 252 }
65478eea 253
30fc6e2d 254
255 // remove redundant config values
a4cdd6d2 256 if ($oldversion < 2008090306) {
65478eea 257 /*
258 * comment this out as it is handled by the update mark 2008090310 below
259 * left for historical documentation as some early adopters may have done
260 * this already.
30fc6e2d 261 $redundant_config = array(
262 'scorm_allowapidebug',
263 'scorm_allowtypeexternal',
264 'scorm_allowtypeimsrepository',
65478eea 265 'scorm_allowtypelocalsync',
266 'scorm_apidebugmask',
267 'scorm_frameheight',
30fc6e2d 268 'scorm_framewidth',
269 'scorm_maxattempts',
270 'scorm_updatetime');
271 foreach ($redundant_config as $rcfg) {
272 if (isset($CFG->$rcfg)) {
273 unset_config($rcfg);
274 }
275 }
65478eea 276 */
1adc77e6 277 /// scorm savepoint reached
a4cdd6d2 278 upgrade_mod_savepoint(true, 2008090306, 'scorm');
1adc77e6 279 }
65478eea 280
281
1adc77e6 282
283 // remove redundant config values
a4cdd6d2 284 if ($oldversion < 2008090307) {
65478eea 285 /*
286 * comment this out as it is handled by the update mark 2008090310 below
287 * left for historical documentation as some early adopters may have done
288 * this already.
1adc77e6 289 $redundant_config = array(
290 'scorm_allowapidebug',
291 'scorm_allowtypeexternal',
292 'scorm_allowtypeimsrepository',
65478eea 293 'scorm_allowtypelocalsync',
294 'scorm_apidebugmask',
295 'scorm_frameheight',
1adc77e6 296 'scorm_framewidth',
297 'scorm_maxattempts',
298 'scorm_updatetime',
65478eea 299 'scorm_resizable',
300 'scorm_scrollbars',
301 'scorm_directories',
1adc77e6 302 'scorm_location',
65478eea 303 'scorm_menubar',
304 'scorm_toolbar',
1adc77e6 305 'scorm_status',
306 'scorm_grademethod',
307 'scorm_maxgrade',
308 'scorm_whatgrade',
309 'scorm_popup',
310 'scorm_skipview',
311 'scorm_hidebrowse',
312 'scorm_hidetoc',
313 'scorm_hidenav',
314 'scorm_auto',
315 'scorm_updatefreq'
316 );
317 foreach ($redundant_config as $rcfg) {
318 if (isset($CFG->$rcfg)) {
319 unset_config($rcfg);
30fc6e2d 320 }
321 }
65478eea 322 */
323
30fc6e2d 324 /// scorm savepoint reached
a4cdd6d2 325 upgrade_mod_savepoint(true, 2008090307, 'scorm');
30fc6e2d 326 }
65478eea 327
a4cdd6d2 328 if ($oldversion < 2008090308) {
d54e2145 329 $table = new xmldb_table('scorm');
2a88f626 330 $field = new xmldb_field('timeopen', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'height');
d54e2145 331 if (!$dbman->field_exists($table,$field)) {
332 $dbman->add_field($table, $field);
333 }
2a88f626 334 $field = new xmldb_field('timeclose', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'timeopen');
d54e2145 335 if (!$dbman->field_exists($table,$field)) {
336 $dbman->add_field($table, $field);
337 }
65478eea 338
d54e2145 339 /// scorm savepoint reached
a4cdd6d2 340 upgrade_mod_savepoint(true, 2008090308, 'scorm');
d54e2145 341 }
65478eea 342
343
a4cdd6d2 344 if ($oldversion < 2008090310) {
65478eea 345 // take above blocks that delete config and move the values in to config_plugins
346
347 $redundant_config = array(
348 'scorm_allowapidebug',
349 'scorm_allowtypeexternal',
350 'scorm_allowtypeimsrepository',
351 'scorm_allowtypelocalsync',
352 'scorm_apidebugmask',
353 'scorm_frameheight',
354 'scorm_framewidth',
355 'scorm_maxattempts',
356 'scorm_updatetime',
357 'scorm_resizable',
358 'scorm_scrollbars',
359 'scorm_directories',
360 'scorm_location',
361 'scorm_menubar',
362 'scorm_toolbar',
363 'scorm_status',
364 'scorm_grademethod',
365 'scorm_maxgrade',
366 'scorm_whatgrade',
367 'scorm_popup',
368 'scorm_skipview',
369 'scorm_hidebrowse',
370 'scorm_hidetoc',
371 'scorm_hidenav',
372 'scorm_auto',
373 'scorm_updatefreq',
374 'scorm_displayattemptstatus',
375 'scorm_displaycoursestructure',
376 'scorm_forcecompleted',
377 'scorm_forcenewattempt',
378 'scorm_lastattemptlock'
379 );
380
381 foreach ($redundant_config as $rcfg) {
382 if (isset($CFG->$rcfg)) {
383 $shortname = substr($rcfg, 6);
a4cdd6d2
PS
384 set_config($shortname, $CFG->$rcfg, 'scorm');
385 unset_config($rcfg);
65478eea 386 }
387 }
388
389 /// scorm savepoint reached
a4cdd6d2 390 upgrade_mod_savepoint(true, 2008090310, 'scorm');
65478eea 391 }
392
a4cdd6d2 393 if ($oldversion < 2009042000) {
d0bcf735 394
395 /// Rename field summary on table scorm to intro
396 $table = new xmldb_table('scorm');
2a88f626 397 $field = new xmldb_field('summary', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null, 'reference');
d0bcf735 398
399 /// Launch rename field summary
400 $dbman->rename_field($table, $field, 'intro');
401
402 /// scorm savepoint reached
a4cdd6d2 403 upgrade_mod_savepoint(true, 2009042000, 'scorm');
d0bcf735 404 }
405
a4cdd6d2 406 if ($oldversion < 2009042001) {
d0bcf735 407
408 /// Define field introformat to be added to scorm
409 $table = new xmldb_table('scorm');
2a88f626 410 $field = new xmldb_field('introformat', XMLDB_TYPE_INTEGER, '4', XMLDB_UNSIGNED, XMLDB_NOTNULL, null, '0', 'intro');
d0bcf735 411
412 /// Launch add field introformat
d682eadf
PS
413 if (!$dbman->field_exists($table, $field)) {
414 $dbman->add_field($table, $field);
415 }
416
417 // conditionally migrate to html format in intro
418 if ($CFG->texteditors !== 'textarea') {
39ac3f6e 419 $rs = $DB->get_recordset('scorm', array('introformat'=>FORMAT_MOODLE), '', 'id,intro,introformat');
d682eadf
PS
420 foreach ($rs as $s) {
421 $s->intro = text_to_html($s->intro, false, false, true);
422 $s->introformat = FORMAT_HTML;
39ac3f6e 423 $DB->update_record('scorm', $s);
d682eadf
PS
424 upgrade_set_timeout();
425 }
426 $rs->close();
427 }
d0bcf735 428
429 /// scorm savepoint reached
a4cdd6d2 430 upgrade_mod_savepoint(true, 2009042001, 'scorm');
d0bcf735 431 }
432
a4cdd6d2 433 if ($oldversion < 2009042002) {
1bd51a6c
DM
434
435 /// Define field introformat to be added to scorm
436 $table = new xmldb_table('scorm_scoes');
437 $field = new xmldb_field('launch', XMLDB_TYPE_TEXT, 'small', null, XMLDB_NOTNULL, null, null);
438
439 /// Launch add field introformat
440 $dbman->change_field_type($table, $field);
441
442 /// scorm savepoint reached
a4cdd6d2 443 upgrade_mod_savepoint(true, 2009042002, 'scorm');
1bd51a6c 444 }
03751efe 445 if ($oldversion < 2010070800) {
b326c85a
DM
446 //check to see if this has already been tidied up by a 1.9 upgrade.
447 $grademethodfixed = get_config('scorm', 'grademethodfixed');
448 if (empty($grademethodfixed)) {
449 /// fix bad usage of whatgrade/grading method.
07b21d04 450 $scorms = $DB->get_records('scorm');
9d49a142
DM
451 if (!empty($scorm)) {
452 foreach ($scorms as $scorm) {
453 $scorm->grademethod = $scorm->grademethod%10;
454 $DB->update_record('scorm', $scorm);
455 }
07b21d04 456 }
b326c85a
DM
457 } else {
458 //dump this config var as it isn't needed anymore.
459 unset_config('grademethodfixed', 'scorm');
460 }
d682eadf 461
03751efe
DM
462 /// scorm savepoint reached
463 upgrade_mod_savepoint(true, 2010070800, 'scorm');
464 }
bea5ad66
DM
465 if ($oldversion < 2010092400) {
466 $count = $DB->count_records('scorm', array('scormtype'=>'external'));
467 if (!empty($count)) {
468 set_config('allowtypeexternal', '1', 'scorm');
469 }
470 $count = $DB->count_records('scorm', array('scormtype'=>'localsync'));
471 if (!empty($count)) {
472 set_config('allowtypelocalsync', '1', 'scorm');
473 }
474 $count = $DB->count_records('scorm', array('scormtype'=>'imsrepository'));
475 if (!empty($count)) {
476 set_config('allowtypeimsrepository', '1', 'scorm');
477 }
478 /// scorm savepoint reached
479 upgrade_mod_savepoint(true, 2010092400, 'scorm');
480 }
3b3e2cec 481
631cefc3 482 if ($oldversion < 2011011400) {
b964171c
SH
483 // Fix scorm in the post table after upgrade from 1.9
484 $table = new xmldb_table('scorm');
485 $columns = $DB->get_columns('scorm');
486
3b3e2cec
EL
487 // forcecompleted should be int(1) not null default 1
488 // Changing to NOT NULL, let's fill the current nulls with default 1
489 $DB->set_field('scorm', 'forcecompleted', 1, array('forcecompleted' => null));
631cefc3
SH
490 $field = new xmldb_field('forcecompleted', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'maxattempt');
491 if ($dbman->field_exists($table, $field)) {
492 $dbman->change_field_precision($table, $field);
b964171c
SH
493 }
494
495 if (array_key_exists('forcenewattempt', $columns) && empty($columns['forcenewattempt']->not_null)) {
3b3e2cec
EL
496 // forcenewattempt should be int(1) not null default 0
497 // Changing to NOT NULL, let's fill the current nulls with default 0
498 $DB->set_field('scorm', 'forcenewattempt', 0, array('forcenewattempt' => null));
b964171c
SH
499 $field = new xmldb_field('forcenewattempt', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcecompleted');
500 if ($dbman->field_exists($table, $field)) {
501 $dbman->change_field_notnull($table, $field);
502 }
503 }
504
505 if (array_key_exists('lastattemptlock', $columns) && empty($columns['lastattemptlock']->not_null)) {
3b3e2cec
EL
506 // lastattemptlock should be int(1) not null default 0
507 // Changing to NOT NULL, let's fill the current nulls with default 0
508 $DB->set_field('scorm', 'lastattemptlock', 0, array('lastattemptlock' => null));
b964171c
SH
509 $field = new xmldb_field('lastattemptlock', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 0, 'forcenewattempt');
510 if ($dbman->field_exists($table, $field)) {
511 $dbman->change_field_notnull($table, $field);
512 }
513 }
514
515 if (array_key_exists('displayattemptstatus', $columns) && empty($columns['displayattemptstatus']->not_null)) {
3b3e2cec
EL
516 // displayattemptstatus should be int(1) not null default 1
517 // Changing to NOT NULL, let's fill the current nulls with default 1
518 $DB->set_field('scorm', 'displayattemptstatus', 1, array('displayattemptstatus' => null));
b964171c
SH
519 $field = new xmldb_field('displayattemptstatus', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'lastattemptlock');
520 if ($dbman->field_exists($table, $field)) {
521 $dbman->change_field_notnull($table, $field);
522 }
523 }
524
525 if (array_key_exists('displaycoursestructure', $columns) && empty($columns['displaycoursestructure']->not_null)) {
3b3e2cec
EL
526 // displaycoursestructure should be int(1) not null default 1
527 // Changing to NOT NULL, let's fill the current nulls with default 1
528 $DB->set_field('scorm', 'displaycoursestructure', 1, array('displaycoursestructure' => null));
b964171c
SH
529 $field = new xmldb_field('displaycoursestructure', XMLDB_TYPE_INTEGER, 1, null, XMLDB_NOTNULL, null, 1, 'displayattemptstatus');
530 if ($dbman->field_exists($table, $field)) {
531 $dbman->change_field_notnull($table, $field);
532 }
533 }
534
631cefc3 535 upgrade_mod_savepoint(true, 2011011400, 'scorm');
b964171c 536 }
631cefc3 537
a4cdd6d2 538 return true;
b8a342d7 539}
540
e5dd8e3b 541