MDL-44712 scorm: make upgrade match install.xml defintion
[moodle.git] / mod / scorm / db / upgrade.php
CommitLineData
e5dd8e3b 1<?php
f7b5c6aa 2// This file is part of Moodle - http://moodle.org/
b8a342d7 3//
f7b5c6aa
DM
4// Moodle is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
b8a342d7 8//
f7b5c6aa
DM
9// Moodle is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
b8a342d7 13//
f7b5c6aa
DM
14// You should have received a copy of the GNU General Public License
15// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
16
17/**
18 * Upgrade script for the scorm module.
19 *
02bff1ad
DM
20 * @package mod_scorm
21 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
f7b5c6aa
DM
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
23 */
24
e8c82aac 25defined('MOODLE_INTERNAL') || die();
b8a342d7 26
b964171c
SH
27/**
28 * @global moodle_database $DB
29 * @param int $oldversion
30 * @return bool
31 */
775f811a 32function xmldb_scorm_upgrade($oldversion) {
33 global $CFG, $DB;
b8a342d7 34
c57ce9f2 35 $dbman = $DB->get_manager();
b8a342d7 36
6a6709ec
N
37 if ($oldversion < 2014072500) {
38
39 // Define field autocommit to be added to scorm.
40 $table = new xmldb_table('scorm');
41 $field = new xmldb_field('autocommit', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'displayactivityname');
42
43 // Conditionally launch add field autocommit.
44 if (!$dbman->field_exists($table, $field)) {
45 $dbman->add_field($table, $field);
46 }
47
48 // Scorm savepoint reached.
49 upgrade_mod_savepoint(true, 2014072500, 'scorm');
50 }
51
147bae8f
EL
52 // Moodle v2.8.0 release upgrade line.
53 // Put any upgrade step following this.
54
ef88aa29
DM
55 if ($oldversion < 2015031800) {
56
57 // Check to see if this site has any AICC packages - if so set the aiccuserid to pass the username
58 // so that the data remains consistent with existing packages.
59 $alreadyset = $DB->record_exists('config_plugins', array('plugin' => 'scorm', 'name' => 'aiccuserid'));
60 if (!$alreadyset) {
61 $hasaicc = $DB->record_exists('scorm', array('version' => 'AICC'));
62 if ($hasaicc) {
63 set_config('aiccuserid', 0, 'scorm');
64 } else {
65 // We set the config value to hide this from upgrades as most users will not know what AICC is anyway.
66 set_config('aiccuserid', 1, 'scorm');
67 }
68 }
69 // Scorm savepoint reached.
70 upgrade_mod_savepoint(true, 2015031800, 'scorm');
71 }
72
b758ab30
EL
73 // Moodle v2.9.0 release upgrade line.
74 // Put any upgrade step following this.
75
32c114ca
MS
76 if ($oldversion < 2015091400) {
77 $table = new xmldb_table('scorm');
78
79 // Changing the default of field forcecompleted on table scorm to 0.
80 $field = new xmldb_field('forcecompleted', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'maxattempt');
81 // Launch change of default for field forcecompleted.
82 $dbman->change_field_default($table, $field);
83
84 // Changing the default of field displaycoursestructure on table scorm to 0.
85 $field = new xmldb_field('displaycoursestructure', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '0', 'displayattemptstatus');
86 // Launch change of default for field displaycoursestructure.
87 $dbman->change_field_default($table, $field);
88
89 // Scorm savepoint reached.
90 upgrade_mod_savepoint(true, 2015091400, 'scorm');
91 }
92
6d29c4ac
EL
93 // Moodle v3.0.0 release upgrade line.
94 // Put any upgrade step following this.
95
3e283642
DM
96 // MDL-50620 Add mastery override option.
97 if ($oldversion < 2016021000) {
98 $table = new xmldb_table('scorm');
99
100 $field = new xmldb_field('masteryoverride', XMLDB_TYPE_INTEGER, '1', null, XMLDB_NOTNULL, null, '1', 'lastattemptlock');
101 if (!$dbman->field_exists($table, $field)) {
102 $dbman->add_field($table, $field);
103 }
104
105 upgrade_mod_savepoint(true, 2016021000, 'scorm');
106 }
107
4da854a6
EL
108 // Moodle v3.1.0 release upgrade line.
109 // Put any upgrade step following this.
110
b30a884b
DM
111 // MDL-44712 improve multi-sco activity completion.
112 if ($oldversion < 2016080900) {
113 $table = new xmldb_table('scorm');
114
6f9f149b 115 $field = new xmldb_field('completionstatusallscos', XMLDB_TYPE_INTEGER, '1', null, null, null, null, 'completionscorerequired');
b30a884b
DM
116 if (!$dbman->field_exists($table, $field)) {
117 $dbman->add_field($table, $field);
118 }
119
120 upgrade_mod_savepoint(true, 2016080900, 'scorm');
121 }
122
a4cdd6d2 123 return true;
b8a342d7 124}