Merge branch 'MDL-61715-34' of https://github.com/lethevinh/moodle into MOODLE_34_STABLE
[moodle.git] / filter / mathjaxloader / db / upgrade.php
blob7edde8a46513092d99b7ca6b21a6f10a641adab6
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 * MathJAX filter upgrade code.
20 * @package filter_mathjaxloader
21 * @copyright 2014 Damyon Wiese (damyon@moodle.com)
22 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 defined('MOODLE_INTERNAL') || die();
27 /**
28 * @param int $oldversion the version we are upgrading from
29 * @return bool result
31 function xmldb_filter_mathjaxloader_upgrade($oldversion) {
32 global $CFG;
34 require_once($CFG->dirroot . '/filter/mathjaxloader/db/upgradelib.php');
36 if ($oldversion < 2016032200) {
38 $httpurl = get_config('filter_mathjaxloader', 'httpurl');
39 // Don't change the config if it has been manually changed to something besides the default setting value.
40 if ($httpurl === "http://cdn.mathjax.org/mathjax/2.5-latest/MathJax.js") {
41 set_config('httpurl', 'http://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js', 'filter_mathjaxloader');
44 $httpsurl = get_config('filter_mathjaxloader', 'httpsurl');
45 // Don't change the config if it has been manually changed to something besides the default setting value.
46 if ($httpsurl === "https://cdn.mathjax.org/mathjax/2.5-latest/MathJax.js") {
47 set_config('httpsurl', 'https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js', 'filter_mathjaxloader');
50 upgrade_plugin_savepoint(true, 2016032200, 'filter', 'mathjaxloader');
53 // Moodle v3.1.0 release upgrade line.
54 // Put any upgrade step following this.
56 if ($oldversion < 2016080200) {
57 // We are consolodating the two settings for http and https url into only the https
58 // setting. Since it is preferably to always load the secure resource.
60 $httpurl = get_config('filter_mathjaxloader', 'httpurl');
61 if ($httpurl !== 'http://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js' &&
62 $httpurl !== 'http://cdn.mathjax.org/mathjax/2.6.1/MathJax.js') {
63 // If the http setting has been changed, we make the admin choose the https setting because
64 // it indicates some sort of custom setup. This will be supported by the release notes.
65 unset_config('httpsurl', 'filter_mathjaxloader');
68 // The seperate http setting has been removed. We always use the secure resource.
69 unset_config('httpurl', 'filter_mathjaxloader');
71 upgrade_plugin_savepoint(true, 2016080200, 'filter', 'mathjaxloader');
74 if ($oldversion < 2016102500) {
75 $httpsurl = get_config('filter_mathjaxloader', 'httpsurl');
76 if ($httpsurl === "https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js") {
77 set_config('httpsurl', 'https://cdn.mathjax.org/mathjax/2.7-latest/MathJax.js', 'filter_mathjaxloader');
79 upgrade_plugin_savepoint(true, 2016102500, 'filter', 'mathjaxloader');
81 // Automatically generated Moodle v3.2.0 release upgrade line.
82 // Put any upgrade step following this.
83 if ($oldversion < 2017040300) {
85 $httpsurl = get_config('filter_mathjaxloader', 'httpsurl');
86 $newcdnurl = filter_mathjaxloader_upgrade_cdn_cloudflare($httpsurl, false);
88 set_config('httpsurl', $newcdnurl, 'filter_mathjaxloader');
90 $mathjaxconfig = get_config('filter_mathjaxloader', 'mathjaxconfig');
91 if (strpos($mathjaxconfig, 'MathJax.Ajax.config.path') === false) {
92 $newconfig = 'MathJax.Ajax.config.path["Contrib"] = "{wwwroot}/filter/mathjaxloader/contrib";' . "\n";
93 $newconfig .= $mathjaxconfig;
95 set_config('mathjaxconfig', $newconfig, 'filter_mathjaxloader');
98 upgrade_plugin_savepoint(true, 2017040300, 'filter', 'mathjaxloader');
100 if ($oldversion < 2017042602) {
102 $httpsurl = get_config('filter_mathjaxloader', 'httpsurl');
103 if ($httpsurl === "https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.0/MathJax.js") {
104 set_config('httpsurl', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js', 'filter_mathjaxloader');
107 $mathjaxconfig = get_config('filter_mathjaxloader', 'mathjaxconfig');
109 if (strpos($mathjaxconfig, 'MathJax.Ajax.config.path') !== false) {
110 // Now we need to remove this config again because mathjax 2.7.1 supports the extensions on the CDN.
111 $configtoremove = 'MathJax.Ajax.config.path["Contrib"] = "{wwwroot}/filter/mathjaxloader/contrib";';
113 $mathjaxconfig = str_replace($configtoremove, '', $mathjaxconfig);
115 set_config('mathjaxconfig', $mathjaxconfig, 'filter_mathjaxloader');
118 upgrade_plugin_savepoint(true, 2017042602, 'filter', 'mathjaxloader');
121 // Automatically generated Moodle v3.3.0 release upgrade line.
122 // Put any upgrade step following this.
124 if ($oldversion < 2017091900) {
126 $httpsurl = get_config('filter_mathjaxloader', 'httpsurl');
127 if (empty($httpsurl)) {
128 // URL is empty, most likely because of bad upgrade path. See MDL-59780.
129 set_config('httpsurl', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js', 'filter_mathjaxloader');
131 upgrade_plugin_savepoint(true, 2017091900, 'filter', 'mathjaxloader');
134 if ($oldversion < 2017100900) {
135 // Update the MathJax CDN URL to the new default if the site has been using default value.
136 $httpsurl = get_config('filter_mathjaxloader', 'httpsurl');
137 if ($httpsurl === 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js') {
138 set_config('httpsurl', 'https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.2/MathJax.js', 'filter_mathjaxloader');
140 upgrade_plugin_savepoint(true, 2017100900, 'filter', 'mathjaxloader');
143 if ($oldversion < 2017101200) {
144 // Update default MathJax configuration so that it does not use the Accessible.js config (causes JS errors due to upstream bug).
145 $previousdefault = '
146 MathJax.Hub.Config({
147 config: ["Accessible.js", "Safe.js"],
148 errorSettings: { message: ["!"] },
149 skipStartupTypeset: true,
150 messageStyle: "none"
154 $newdefault = '
155 MathJax.Hub.Config({
156 config: ["default.js", "MMLorHTML.js", "Safe.js"],
157 errorSettings: { message: ["!"] },
158 skipStartupTypeset: true,
159 messageStyle: "none"
163 $mathjaxconfig = get_config('filter_mathjaxloader', 'mathjaxconfig');
165 if (empty($mathjaxconfig) || filter_mathjaxloader_upgrade_mathjaxconfig_equal($mathjaxconfig, $previousdefault)) {
166 set_config('mathjaxconfig', $newdefault, 'filter_mathjaxloader');
169 upgrade_plugin_savepoint(true, 2017101200, 'filter', 'mathjaxloader');
172 if ($oldversion < 2017102000) {
173 // Re-add Accessible.js (we should not have removed it).
174 $previousdefault = '
175 MathJax.Hub.Config({
176 config: ["default.js", "MMLorHTML.js", "Safe.js"],
177 errorSettings: { message: ["!"] },
178 skipStartupTypeset: true,
179 messageStyle: "none"
182 $newdefault = '
183 MathJax.Hub.Config({
184 config: ["Accessible.js", "Safe.js"],
185 errorSettings: { message: ["!"] },
186 skipStartupTypeset: true,
187 messageStyle: "none"
191 $mathjaxconfig = get_config('filter_mathjaxloader', 'mathjaxconfig');
193 if (empty($mathjaxconfig) || filter_mathjaxloader_upgrade_mathjaxconfig_equal($mathjaxconfig, $previousdefault)) {
194 set_config('mathjaxconfig', $newdefault, 'filter_mathjaxloader');
197 upgrade_plugin_savepoint(true, 2017102000, 'filter', 'mathjaxloader');
200 // Automatically generated Moodle v3.4.0 release upgrade line.
201 // Put any upgrade step following this.
203 return true;