2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
18 * Upgrade script for the scorm module.
22 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 * @global moodle_database $DB
29 * @param int $oldversion
32 function xmldb_scorm_upgrade($oldversion) {
35 $dbman = $DB->get_manager();
38 // Moodle v2.2.0 release upgrade line
39 // Put any upgrade step following this
41 if ($oldversion < 2012032100) {
42 unset_config('updatetime', 'scorm');
43 upgrade_mod_savepoint(true, 2012032100, 'scorm');
46 // Adding completion fields to scorm table
47 if ($oldversion < 2012032101) {
48 $table = new xmldb_table('scorm');
50 $field = new xmldb_field('completionstatusrequired', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, null, null, null, 'timemodified');
51 if (!$dbman->field_exists($table, $field)) {
52 $dbman->add_field($table, $field);
55 $field = new xmldb_field('completionscorerequired', XMLDB_TYPE_INTEGER, '2', XMLDB_UNSIGNED, null, null, null, 'completionstatusrequired');
56 if (!$dbman->field_exists($table, $field)) {
57 $dbman->add_field($table, $field);
60 upgrade_mod_savepoint(true, 2012032101, 'scorm');
63 // Moodle v2.3.0 release upgrade line
64 // Put any upgrade step following this
66 //rename config var from maxattempts to maxattempt
67 if ($oldversion < 2012061701) {
68 $maxattempts = get_config('scorm', 'maxattempts');
69 $maxattempts_adv = get_config('scorm', 'maxattempts_adv');
70 set_config('maxattempt', $maxattempts, 'scorm');
71 set_config('maxattempt_adv', $maxattempts_adv, 'scorm');
73 unset_config('maxattempts', 'scorm'); //remove old setting.
74 unset_config('maxattempts_adv', 'scorm'); //remove old setting.
75 upgrade_mod_savepoint(true, 2012061701, 'scorm');
79 // Moodle v2.4.0 release upgrade line
80 // Put any upgrade step following this.
82 // Moodle v2.5.0 release upgrade line.
83 // Put any upgrade step following this.
85 // Remove old imsrepository type - convert any existing records to external type to help prevent major errors.
86 if ($oldversion < 2013081301) {
87 $scorms = $DB->get_recordset('scorm', array('scormtype' => 'imsrepository'));
88 foreach ($scorms as $scorm) {
89 $scorm->scormtype = SCORM_TYPE_EXTERNAL;
90 if (!empty($CFG->repository)) { // Fix path to imsmanifest if $CFG->repository is set.
91 $scorm->reference = $CFG->repository.substr($scorm->reference, 1).'/imsmanifest.xml';
92 $scorm->sha1hash = sha1($scorm->reference);
95 $DB->update_record('scorm', $scorm);
97 upgrade_mod_savepoint(true, 2013081301, 'scorm');
100 // Fix AICC parent/child relationships (MDL-37394).
101 if ($oldversion < 2013081302) {
102 // Get all AICC packages.
103 $aiccpackages = $DB->get_recordset('scorm', array('version' => 'AICC'), '', 'id');
104 foreach ($aiccpackages as $aicc) {
105 $sql = "UPDATE {scorm_scoes}
106 SET parent = organization
108 AND " . $DB->sql_isempty('scorm_scoes', 'manifest', false, false) . "
109 AND " . $DB->sql_isnotempty('scorm_scoes', 'organization', false, false) . "
111 $DB->execute($sql, array($aicc->id));
113 $aiccpackages->close();
114 upgrade_mod_savepoint(true, 2013081302, 'scorm');
117 if ($oldversion < 2013081303) {
119 // Define field sortorder to be added to scorm_scoes.
120 $table = new xmldb_table('scorm_scoes');
121 $field = new xmldb_field('sortorder', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, '0', 'title');
123 // Conditionally launch add field sortorder.
124 if (!$dbman->field_exists($table, $field)) {
125 $dbman->add_field($table, $field);
128 // Scorm savepoint reached.
129 upgrade_mod_savepoint(true, 2013081303, 'scorm');
132 if ($oldversion < 2013090100) {
133 $table = new xmldb_table('scorm');
135 $field = new xmldb_field('nav', XMLDB_TYPE_INTEGER, '1', XMLDB_UNSIGNED, true, null, 1, 'hidetoc');
136 if (!$dbman->field_exists($table, $field)) {
137 $dbman->add_field($table, $field);
140 $field = new xmldb_field('navpositionleft', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, -100, 'nav');
141 if (!$dbman->field_exists($table, $field)) {
142 $dbman->add_field($table, $field);
145 $field = new xmldb_field('navpositiontop', XMLDB_TYPE_INTEGER, '10', XMLDB_UNSIGNED, null, null, -100, 'navpositionleft');
146 if (!$dbman->field_exists($table, $field)) {
147 $dbman->add_field($table, $field);
150 $field = new xmldb_field('hidenav');
151 if ($dbman->field_exists($table, $field)) {
152 // Update nav setting to show floating navigation buttons under TOC.
153 $DB->set_field('scorm', 'nav', 2, array('hidenav' => 0));
154 $DB->set_field('scorm', 'navpositionleft', 215, array('hidenav' => 2));
155 $DB->set_field('scorm', 'navpositiontop', 300, array('hidenav' => 2));
157 // Update nav setting to disable navigation buttons.
158 $DB->set_field('scorm', 'nav', 0, array('hidenav' => 1));
159 // Drop hidenav field.
160 $dbman->drop_field($table, $field);
163 $hide = get_config('hidenav', 'scorm');
164 unset_config('hidenav', 'mod_scorm');
166 set_config('nav', SCORM_NAV_DISABLED, 'mod_scorm');
169 $hideadv = get_config('hidenav_adv', 'scorm');
170 unset_config('hidenav_adv', 'mod_scorm');
171 set_config('nav_adv', $hideadv, 'mod_scorm');
173 upgrade_mod_savepoint(true, 2013090100, 'scorm');