MDL-62478 upgrade: add 3.5.0 separation line to all upgrade scripts
[moodle.git] / mod / lesson / db / upgrade.php
blob86afb899b8e59285eb97b5b633f1829e0fec63fd
1 <?php
2 // This file is part of Moodle - http://moodle.org/
3 //
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.
8 //
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/>.
17 /**
18 * This file keeps track of upgrades to
19 * the lesson module
21 * Sometimes, changes between versions involve
22 * alterations to database structures and other
23 * major things that may break installations.
25 * The upgrade function in this file will attempt
26 * to perform all the necessary actions to upgrade
27 * your older installation to the current version.
29 * If there's something it cannot do itself, it
30 * will tell you what you need to do.
32 * The commands in here will all be database-neutral,
33 * using the methods of database_manager class
35 * Please do not forget to use upgrade_set_timeout()
36 * before any action that may take longer time to finish.
38 * @package mod_lesson
39 * @copyright 1999 onwards Martin Dougiamas {@link http://moodle.com}
40 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 o
43 defined('MOODLE_INTERNAL') || die();
45 /**
47 * @global stdClass $CFG
48 * @global moodle_database $DB
49 * @param int $oldversion
50 * @return bool
52 function xmldb_lesson_upgrade($oldversion) {
53 global $CFG, $DB;
55 $dbman = $DB->get_manager();
57 // Automatically generated Moodle v3.2.0 release upgrade line.
58 // Put any upgrade step following this.
60 if ($oldversion < 2016120515) {
61 // Define new fields to be added to lesson.
62 $table = new xmldb_table('lesson');
63 $field = new xmldb_field('allowofflineattempts', XMLDB_TYPE_INTEGER, '1', null, null, null, 0, 'completiontimespent');
64 // Conditionally launch add field allowofflineattempts.
65 if (!$dbman->field_exists($table, $field)) {
66 $dbman->add_field($table, $field);
68 // Lesson savepoint reached.
69 upgrade_mod_savepoint(true, 2016120515, 'lesson');
71 if ($oldversion < 2016120516) {
72 // New field for lesson_timer.
73 $table = new xmldb_table('lesson_timer');
74 $field = new xmldb_field('timemodifiedoffline', XMLDB_TYPE_INTEGER, '10', null, XMLDB_NOTNULL, null, 0, 'completed');
75 // Conditionally launch add field timemodifiedoffline.
76 if (!$dbman->field_exists($table, $field)) {
77 $dbman->add_field($table, $field);
79 // Lesson savepoint reached.
80 upgrade_mod_savepoint(true, 2016120516, 'lesson');
83 // Automatically generated Moodle v3.3.0 release upgrade line.
84 // Put any upgrade step following this.
86 if ($oldversion < 2017051501) {
88 // Delete orphaned lesson answer and response files.
89 $sql = "SELECT DISTINCT f.contextid, f.component, f.filearea, f.itemid
90 FROM {files} f
91 LEFT JOIN {lesson_answers} la ON f.itemid = la.id
92 WHERE component = :component
93 AND (filearea = :fileareaanswer OR filearea = :filearearesponse)
94 AND la.id IS NULL";
96 $orphanedfiles = $DB->get_recordset_sql($sql, array('component' => 'mod_lesson', 'fileareaanswer' => 'page_answers',
97 'filearearesponse' => 'page_responses'));
98 $fs = get_file_storage();
99 foreach ($orphanedfiles as $file) {
100 $fs->delete_area_files($file->contextid, $file->component, $file->filearea, $file->itemid);
102 $orphanedfiles->close();
104 upgrade_mod_savepoint(true, 2017051501, 'lesson');
107 // Automatically generated Moodle v3.4.0 release upgrade line.
108 // Put any upgrade step following this.
110 // Automatically generated Moodle v3.5.0 release upgrade line.
111 // Put any upgrade step following this.
113 return true;