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');