MDL-62478 upgrade: add 3.5.0 separation line to all upgrade scripts
[moodle.git] / course / format / weeks / db / upgrade.php
blob893d716ce6dd7b7b864e382dcfd1bfab752ca546
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 * Upgrade scripts for course format "Weeks"
20 * @package format_weeks
21 * @copyright 2017 Marina Glancy
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 /**
28 * Upgrade script for format_weeks
30 * @param int $oldversion the version we are upgrading from
31 * @return bool result
33 function xmldb_format_weeks_upgrade($oldversion) {
34 global $CFG, $DB;
36 require_once($CFG->dirroot . '/course/format/weeks/lib.php');
37 require_once($CFG->dirroot . '/course/format/weeks/db/upgradelib.php');
39 if ($oldversion < 2017020200) {
41 // Remove 'numsections' option and hide or delete orphaned sections.
42 format_weeks_upgrade_remove_numsections();
44 upgrade_plugin_savepoint(true, 2017020200, 'format', 'weeks');
47 if ($oldversion < 2017050300) {
48 // Go through the existing courses using the weeks format with no value set for the 'automaticenddate'.
49 $sql = "SELECT c.id, c.enddate, cfo.id as cfoid
50 FROM {course} c
51 LEFT JOIN {course_format_options} cfo
52 ON cfo.courseid = c.id
53 AND cfo.format = c.format
54 AND cfo.name = :optionname
55 AND cfo.sectionid = 0
56 WHERE c.format = :format
57 AND cfo.id IS NULL";
58 $params = ['optionname' => 'automaticenddate', 'format' => 'weeks'];
59 $courses = $DB->get_recordset_sql($sql, $params);
60 foreach ($courses as $course) {
61 $option = new stdClass();
62 $option->courseid = $course->id;
63 $option->format = 'weeks';
64 $option->sectionid = 0;
65 $option->name = 'automaticenddate';
66 if (empty($course->enddate)) {
67 $option->value = 1;
68 $DB->insert_record('course_format_options', $option);
70 // Now, let's update the course end date.
71 format_weeks::update_end_date($course->id);
72 } else {
73 $option->value = 0;
74 $DB->insert_record('course_format_options', $option);
77 $courses->close();
79 upgrade_plugin_savepoint(true, 2017050300, 'format', 'weeks');
82 // Automatically generated Moodle v3.3.0 release upgrade line.
83 // Put any upgrade step following this.
85 // Automatically generated Moodle v3.4.0 release upgrade line.
86 // Put any upgrade step following this.
88 if ($oldversion < 2018030900) {
90 // During upgrade to Moodle 3.3 it could happen that general section (section 0) became 'invisible'.
91 // It should always be visible.
92 $DB->execute("UPDATE {course_sections} SET visible=1 WHERE visible=0 AND section=0 AND course IN
93 (SELECT id FROM {course} WHERE format=?)", ['weeks']);
95 upgrade_plugin_savepoint(true, 2018030900, 'format', 'weeks');
98 // Automatically generated Moodle v3.5.0 release upgrade line.
99 // Put any upgrade step following this.
101 return true;