mirrored from git://git.moodle.org/moodle.git
/
upgrade.php
172 lines (138 loc) · 6.71 KB
/
upgrade.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
<?php
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Moodle is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
/**
* MathJAX filter upgrade code.
*
* @package filter_mathjaxloader
* @copyright 2014 Damyon Wiese (damyon@moodle.com)
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
*/
defined('MOODLE_INTERNAL') || die();
/**
* @param int $oldversion the version we are upgrading from
* @return bool result
*/
function xmldb_filter_mathjaxloader_upgrade($oldversion) {
global $CFG, $DB;
require_once($CFG->dirroot . '/filter/mathjaxloader/db/upgradelib.php');
$dbman = $DB->get_manager();
if ($oldversion < 2014081100) {
$sslcdnurl = get_config('filter_mathjaxloader', 'httpsurl');
if ($sslcdnurl === "https://c328740.ssl.cf1.rackcdn.com/mathjax/2.3-latest/MathJax.js") {
set_config('httpsurl', 'https://cdn.mathjax.org/mathjax/2.3-latest/MathJax.js', 'filter_mathjaxloader');
}
upgrade_plugin_savepoint(true, 2014081100, 'filter', 'mathjaxloader');
}
// Moodle v2.8.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2015021200) {
$httpurl = get_config('filter_mathjaxloader', 'httpurl');
// Don't change the config if it has been manually changed to something besides the default setting value.
if ($httpurl === "http://cdn.mathjax.org/mathjax/2.3-latest/MathJax.js") {
set_config('httpurl', 'http://cdn.mathjax.org/mathjax/2.5-latest/MathJax.js', 'filter_mathjaxloader');
}
$httpsurl = get_config('filter_mathjaxloader', 'httpsurl');
// Don't change the config if it has been manually changed to something besides the default setting value.
if ($httpsurl === "https://cdn.mathjax.org/mathjax/2.3-latest/MathJax.js") {
set_config('httpsurl', 'https://cdn.mathjax.org/mathjax/2.5-latest/MathJax.js', 'filter_mathjaxloader');
}
upgrade_plugin_savepoint(true, 2015021200, 'filter', 'mathjaxloader');
}
if ($oldversion < 2015021700) {
$oldconfig = get_config('filter_mathjaxloader', 'mathjaxconfig');
$olddefault = 'MathJax.Hub.Config({
config: ["MMLorHTML.js", "Safe.js"],
jax: ["input/TeX","input/MathML","output/HTML-CSS","output/NativeMML"],
extensions: ["tex2jax.js","mml2jax.js","MathMenu.js","MathZoom.js"],
TeX: {
extensions: ["AMSmath.js","AMSsymbols.js","noErrors.js","noUndefined.js"]
},
menuSettings: {
zoom: "Double-Click",
mpContext: true,
mpMouse: true
},
errorSettings: { message: ["!"] },
skipStartupTypeset: true,
messageStyle: "none"
});
';
$newdefault = '
MathJax.Hub.Config({
config: ["Accessible.js", "Safe.js"],
errorSettings: { message: ["!"] },
skipStartupTypeset: true,
messageStyle: "none"
});
';
// Ignore white space changes.
$oldconfig = trim(preg_replace('/\s+/', ' ', $oldconfig));
$olddefault = trim(preg_replace('/\s+/', ' ', $olddefault));
// Update the default config for mathjax only if it has not been customised.
if ($oldconfig == $olddefault) {
set_config('mathjaxconfig', $newdefault, 'filter_mathjaxloader');
}
upgrade_plugin_savepoint(true, 2015021700, 'filter', 'mathjaxloader');
}
// Moodle v2.9.0 release upgrade line.
// Put any upgrade step following this.
// Moodle v3.0.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2016032200) {
$httpurl = get_config('filter_mathjaxloader', 'httpurl');
// Don't change the config if it has been manually changed to something besides the default setting value.
if ($httpurl === "http://cdn.mathjax.org/mathjax/2.5-latest/MathJax.js") {
set_config('httpurl', 'http://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js', 'filter_mathjaxloader');
}
$httpsurl = get_config('filter_mathjaxloader', 'httpsurl');
// Don't change the config if it has been manually changed to something besides the default setting value.
if ($httpsurl === "https://cdn.mathjax.org/mathjax/2.5-latest/MathJax.js") {
set_config('httpsurl', 'https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js', 'filter_mathjaxloader');
}
upgrade_plugin_savepoint(true, 2016032200, 'filter', 'mathjaxloader');
}
// Moodle v3.1.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2016080200) {
// We are consolodating the two settings for http and https url into only the https
// setting. Since it is preferably to always load the secure resource.
$httpurl = get_config('filter_mathjaxloader', 'httpurl');
if ($httpurl !== 'http://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js') {
// If the http setting has been changed, we make the admin choose the https setting because
// it indicates some sort of custom setup. This will be supported by the release notes.
unset_config('httpsurl', 'filter_mathjaxloader');
}
// The seperate http setting has been removed. We always use the secure resource.
unset_config('httpurl', 'filter_mathjaxloader');
upgrade_plugin_savepoint(true, 2016080200, 'filter', 'mathjaxloader');
}
if ($oldversion < 2016102500) {
$httpsurl = get_config('filter_mathjaxloader', 'httpsurl');
if ($httpsurl === "https://cdn.mathjax.org/mathjax/2.6-latest/MathJax.js") {
set_config('httpsurl', 'https://cdn.mathjax.org/mathjax/2.7-latest/MathJax.js', 'filter_mathjaxloader');
}
upgrade_plugin_savepoint(true, 2016102500, 'filter', 'mathjaxloader');
}
// Automatically generated Moodle v3.2.0 release upgrade line.
// Put any upgrade step following this.
if ($oldversion < 2017040300) {
$httpsurl = get_config('filter_mathjaxloader', 'httpsurl');
$newcdnurl = filter_mathjaxloader_upgrade_cdn_cloudflare($httpsurl, false);
set_config('httpsurl', $newcdnurl, 'filter_mathjaxloader');
upgrade_plugin_savepoint(true, 2017040300, 'filter', 'mathjaxloader');
}
return true;
}