Commit | Line | Data |
---|---|---|
8580535b | 1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * Main administration script. | |
20 | * | |
d078f6d3 | 21 | * @package core |
8580535b | 22 | * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
f9903ed0 | 25 | |
00be1916 | 26 | // Check that config.php exists, if not then call the install script |
27 | if (!file_exists('../config.php')) { | |
28 | header('Location: ../install.php'); | |
3ba28588 | 29 | die(); |
00be1916 | 30 | } |
31 | ||
32 | // Check that PHP is of a sufficient version as soon as possible | |
dbe0203b | 33 | if (version_compare(phpversion(), '5.4.4') < 0) { |
00be1916 | 34 | $phpversion = phpversion(); |
35 | // do NOT localise - lang strings would not work here and we CAN NOT move it to later place | |
dbe0203b | 36 | echo "Moodle 2.7 or later requires at least PHP 5.4.4 (currently using version $phpversion).<br />"; |
eab044a0 | 37 | echo "Please upgrade your server software or install older Moodle version."; |
3ba28588 | 38 | die(); |
00be1916 | 39 | } |
40 | ||
695940df PS |
41 | // make sure iconv is available and actually works |
42 | if (!function_exists('iconv')) { | |
43 | // this should not happen, this must be very borked install | |
7d85a4e2 | 44 | echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.'; |
695940df PS |
45 | die(); |
46 | } | |
695940df | 47 | |
3c9535dd JC |
48 | // Make sure php5-json is available. |
49 | if (!function_exists('json_encode') || !function_exists('json_decode')) { | |
50 | // This also shouldn't happen. | |
51 | echo 'Moodle requires the json PHP extension. Please install or enable the json extension.'; | |
52 | die(); | |
53 | } | |
54 | ||
cbad562e | 55 | define('NO_OUTPUT_BUFFERING', true); |
00be1916 | 56 | |
98b32c9e DM |
57 | if (isset($_POST['upgradekey'])) { |
58 | // Before you start reporting issues about the collision attacks against | |
59 | // SHA-1, you should understand that we are not actually attempting to do | |
60 | // any cryptography here. This is hashed purely so that the key is not | |
61 | // that apparent in the address bar itself. Anyone who catches the HTTP | |
62 | // traffic can immediately use it as a valid admin key. | |
63 | header('Location: index.php?cache=0&upgradekeyhash='.sha1($_POST['upgradekey'])); | |
64 | die(); | |
65 | } | |
66 | ||
fc281113 PS |
67 | if ((isset($_GET['cache']) and $_GET['cache'] === '0') |
68 | or (isset($_POST['cache']) and $_POST['cache'] === '0') | |
69 | or (!isset($_POST['cache']) and !isset($_GET['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey']))) { | |
e2e35e71 PS |
70 | // Prevent caching at all cost when visiting this page directly, |
71 | // we redirect to self once we known no upgrades are necessary. | |
72 | // Note: $_GET and $_POST are used here intentionally because our param cleaning is not loaded yet. | |
bf8c71b7 | 73 | // Note2: the sesskey is present in all block editing hacks, we can not redirect there, so enable caching. |
e2e35e71 | 74 | define('CACHE_DISABLE_ALL', true); |
c05a5099 PS |
75 | |
76 | // Force OPcache reset if used, we do not want any stale caches | |
77 | // when detecting if upgrade necessary or when running upgrade. | |
78 | if (function_exists('opcache_reset')) { | |
79 | opcache_reset(); | |
80 | } | |
82b1cf00 PS |
81 | $cache = 0; |
82 | ||
83 | } else { | |
84 | $cache = 1; | |
e2e35e71 PS |
85 | } |
86 | ||
00be1916 | 87 | require('../config.php'); |
3274c5db FM |
88 | |
89 | // Invalidate the cache of version.php in any circumstances to help core_component | |
90 | // detecting if the version has changed and component cache should be reset. | |
91 | if (function_exists('opcache_invalidate')) { | |
92 | opcache_invalidate($CFG->dirroot . '/version.php', true); | |
93 | } | |
94 | // Make sure the component cache gets rebuilt if necessary, any method that | |
95 | // indirectly calls the protected init() method is good here. | |
96 | core_component::get_core_subsystems(); | |
97 | ||
bc76b3c0 | 98 | require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions |
99 | require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions | |
00be1916 | 100 | |
531381f9 DM |
101 | $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL); // Core upgrade confirmed? |
102 | $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL); // Core release info and server checks confirmed? | |
103 | $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL); // Plugins check page confirmed? | |
104 | $showallplugins = optional_param('showallplugins', 0, PARAM_BOOL); // Show all plugins on the plugins check page? | |
105 | $agreelicense = optional_param('agreelicense', 0, PARAM_BOOL); // GPL license confirmed for installation? | |
106 | $fetchupdates = optional_param('fetchremote', 0, PARAM_BOOL); // Should check for available updates? | |
107 | $newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW); // Plugin installation requested at moodle.org/plugins. | |
108 | $upgradekeyhash = optional_param('upgradekeyhash', null, PARAM_ALPHANUM); // Hash of provided upgrade key. | |
109 | $installdep = optional_param('installdep', null, PARAM_COMPONENT); // Install given missing dependency (required plugin). | |
110 | $installdepx = optional_param('installdepx', false, PARAM_BOOL); // Install all missing dependencies. | |
111 | $confirminstalldep = optional_param('confirminstalldep', false, PARAM_BOOL); // Installing dependencies confirmed. | |
112 | $abortinstall = optional_param('abortinstall', null, PARAM_COMPONENT); // Cancel installation of the given new plugin. | |
113 | $abortinstallx = optional_param('abortinstallx', null, PARAM_BOOL); // Cancel installation of all new plugins. | |
114 | $confirmabortinstall = optional_param('confirmabortinstall', false, PARAM_BOOL); // Installation cancel confirmed. | |
115 | $installupdate = optional_param('installupdate', null, PARAM_COMPONENT); // Install given available update. | |
116 | $installupdateversion = optional_param('installupdateversion', null, PARAM_INT); // Version of the available update to install. | |
117 | $installupdatex = optional_param('installupdatex', false, PARAM_BOOL); // Install all available plugin updates. | |
118 | $confirminstallupdate = optional_param('confirminstallupdate', false, PARAM_BOOL); // Available update(s) install confirmed? | |
00be1916 | 119 | |
e2e35e71 PS |
120 | // Set up PAGE. |
121 | $url = new moodle_url('/admin/index.php'); | |
fc281113 | 122 | $url->param('cache', $cache); |
98b32c9e DM |
123 | if (isset($upgradekeyhash)) { |
124 | $url->param('upgradekeyhash', $upgradekeyhash); | |
125 | } | |
e2e35e71 PS |
126 | $PAGE->set_url($url); |
127 | unset($url); | |
128 | ||
82b1cf00 | 129 | // Are we returning from an add-on installation request at moodle.org/plugins? |
835f58eb | 130 | if ($newaddonreq and !$cache and empty($CFG->disableonclickaddoninstall)) { |
82b1cf00 PS |
131 | $target = new moodle_url('/admin/tool/installaddon/index.php', array( |
132 | 'installaddonrequest' => $newaddonreq, | |
133 | 'confirm' => 0)); | |
134 | if (!isloggedin() or isguestuser()) { | |
135 | // Login and go the the add-on tool page. | |
136 | $SESSION->wantsurl = $target->out(); | |
137 | redirect(get_login_url()); | |
138 | } | |
139 | redirect($target); | |
140 | } | |
141 | ||
6d80fad4 | 142 | $PAGE->set_pagelayout('admin'); // Set a default pagelayout |
ee73b1ff | 143 | |
00be1916 | 144 | $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>'; |
145 | ||
e2e35e71 PS |
146 | // Check some PHP server settings |
147 | ||
00be1916 | 148 | if (ini_get_bool('session.auto_start')) { |
149 | print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink)); | |
150 | } | |
151 | ||
00be1916 | 152 | if (!ini_get_bool('file_uploads')) { |
153 | print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink)); | |
154 | } | |
155 | ||
156 | if (is_float_problem()) { | |
157 | print_error('phpfloatproblem', 'admin', '', $documentationlink); | |
158 | } | |
159 | ||
00be1916 | 160 | // Set some necessary variables during set-up to avoid PHP warnings later on this page |
00be1916 | 161 | if (!isset($CFG->release)) { |
bc76b3c0 | 162 | $CFG->release = ''; |
00be1916 | 163 | } |
164 | if (!isset($CFG->version)) { | |
bc76b3c0 | 165 | $CFG->version = ''; |
00be1916 | 166 | } |
ad394588 AB |
167 | if (!isset($CFG->branch)) { |
168 | $CFG->branch = ''; | |
169 | } | |
00be1916 | 170 | |
171 | $version = null; | |
172 | $release = null; | |
ed01233a AB |
173 | $branch = null; |
174 | require("$CFG->dirroot/version.php"); // defines $version, $release, $branch and $maturity | |
00be1916 | 175 | $CFG->target_release = $release; // used during installation and upgrades |
176 | ||
177 | if (!$version or !$release) { | |
178 | print_error('withoutversion', 'debug'); // without version, stop | |
179 | } | |
180 | ||
3316fe24 | 181 | if (!core_tables_exist()) { |
78946b9b | 182 | $PAGE->set_pagelayout('maintenance'); |
d3875524 | 183 | $PAGE->set_popup_notification_allowed(false); |
00be1916 | 184 | |
185 | // fake some settings | |
186 | $CFG->docroot = 'http://docs.moodle.org'; | |
187 | ||
188 | $strinstallation = get_string('installation', 'install'); | |
189 | ||
190 | // remove current session content completely | |
d79d5ac2 | 191 | \core\session\manager::terminate_current(); |
00be1916 | 192 | |
193 | if (empty($agreelicense)) { | |
194 | $strlicense = get_string('license'); | |
cc359566 | 195 | |
69d77c23 | 196 | $PAGE->navbar->add($strlicense); |
197 | $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release); | |
198 | $PAGE->set_heading($strinstallation); | |
199 | $PAGE->set_cacheable(false); | |
cc359566 | 200 | |
82b1cf00 | 201 | /** @var core_admin_renderer $output */ |
da2fdc3f | 202 | $output = $PAGE->get_renderer('core', 'admin'); |
cc359566 | 203 | echo $output->install_licence_page(); |
3ba28588 | 204 | die(); |
249ab745 | 205 | } |
00be1916 | 206 | if (empty($confirmrelease)) { |
cc359566 TH |
207 | require_once($CFG->libdir.'/environmentlib.php'); |
208 | list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); | |
bc76b3c0 | 209 | $strcurrentrelease = get_string('currentrelease'); |
cc359566 | 210 | |
69d77c23 | 211 | $PAGE->navbar->add($strcurrentrelease); |
1a4d6a5b DM |
212 | $PAGE->set_title($strinstallation); |
213 | $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release); | |
69d77c23 | 214 | $PAGE->set_cacheable(false); |
249ab745 | 215 | |
82b1cf00 | 216 | /** @var core_admin_renderer $output */ |
cc359566 | 217 | $output = $PAGE->get_renderer('core', 'admin'); |
8d1da748 | 218 | echo $output->install_environment_page($maturity, $envstatus, $environment_results, $release); |
3ba28588 | 219 | die(); |
1dd24519 | 220 | } |
221 | ||
39f15cc7 DM |
222 | // check plugin dependencies |
223 | $failed = array(); | |
e87214bd | 224 | if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { |
39f15cc7 DM |
225 | $PAGE->navbar->add(get_string('pluginscheck', 'admin')); |
226 | $PAGE->set_title($strinstallation); | |
227 | $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release); | |
228 | ||
229 | $output = $PAGE->get_renderer('core', 'admin'); | |
98b32c9e | 230 | $url = new moodle_url($PAGE->url, array('agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)); |
39f15cc7 DM |
231 | echo $output->unsatisfied_dependencies_page($version, $failed, $url); |
232 | die(); | |
233 | } | |
234 | unset($failed); | |
235 | ||
8d1da748 PS |
236 | //TODO: add a page with list of non-standard plugins here |
237 | ||
bc76b3c0 | 238 | $strdatabasesetup = get_string('databasesetup'); |
543f54d3 | 239 | upgrade_init_javascript(); |
cc359566 | 240 | |
69d77c23 | 241 | $PAGE->navbar->add($strdatabasesetup); |
242 | $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release); | |
2ea05146 | 243 | $PAGE->set_heading($strinstallation); |
69d77c23 | 244 | $PAGE->set_cacheable(false); |
cc359566 | 245 | |
da2fdc3f TH |
246 | $output = $PAGE->get_renderer('core', 'admin'); |
247 | echo $output->header(); | |
d02bc6ce | 248 | |
00be1916 | 249 | if (!$DB->setup_is_unicodedb()) { |
250 | if (!$DB->change_db_encoding()) { | |
251 | // If could not convert successfully, throw error, and prevent installation | |
252 | print_error('unicoderequired', 'admin'); | |
db5af934 | 253 | } |
db5af934 | 254 | } |
90509582 | 255 | |
00be1916 | 256 | install_core($version, true); |
257 | } | |
db5af934 | 258 | |
db5af934 | 259 | |
00be1916 | 260 | // Check version of Moodle code on disk compared with database |
261 | // and upgrade if possible. | |
db5af934 | 262 | |
1a361486 PS |
263 | if (!$cache) { |
264 | // Do not try to do anything fancy in non-cached mode, | |
265 | // this prevents themes from fetching data from non-existent tables. | |
266 | $PAGE->set_pagelayout('maintenance'); | |
267 | $PAGE->set_popup_notification_allowed(false); | |
268 | } | |
269 | ||
00be1916 | 270 | $stradministration = get_string('administration'); |
bf006d2c | 271 | $PAGE->set_context(context_system::instance()); |
db5af934 | 272 | |
00be1916 | 273 | if (empty($CFG->version)) { |
274 | print_error('missingconfigversion', 'debug'); | |
275 | } | |
db5af934 | 276 | |
e2e35e71 | 277 | // Detect config cache inconsistency, this happens when you switch branches on dev servers. |
82b1cf00 PS |
278 | if ($CFG->version != $DB->get_field('config', 'value', array('name'=>'version'))) { |
279 | purge_all_caches(); | |
98b32c9e | 280 | redirect(new moodle_url($PAGE->url), 'Config cache inconsistency detected, resetting caches...'); |
e2e35e71 PS |
281 | } |
282 | ||
82b1cf00 | 283 | if (!$cache and $version > $CFG->version) { // upgrade |
6e09cf98 | 284 | |
2f29cf6e DM |
285 | $PAGE->set_url(new moodle_url($PAGE->url, array( |
286 | 'confirmupgrade' => $confirmupgrade, | |
287 | 'confirmrelease' => $confirmrelease, | |
288 | 'confirmplugincheck' => $confirmplugins, | |
289 | ))); | |
290 | ||
98b32c9e DM |
291 | check_upgrade_key($upgradekeyhash); |
292 | ||
6e09cf98 DM |
293 | // Warning about upgrading a test site. |
294 | $testsite = false; | |
295 | if (defined('BEHAT_SITE_RUNNING')) { | |
296 | $testsite = 'behat'; | |
297 | } | |
298 | ||
b0dd08dd SH |
299 | // We purge all of MUC's caches here. |
300 | // Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true. | |
301 | // This ensures a real config object is loaded and the stores will be purged. | |
302 | // This is the only way we can purge custom caches such as memcache or APC. | |
303 | // Note: all other calls to caches will still used the disabled API. | |
304 | cache_helper::purge_all(true); | |
305 | // We then purge the regular caches. | |
a95682b2 | 306 | purge_all_caches(); |
33082590 | 307 | |
fc281113 PS |
308 | /** @var core_admin_renderer $output */ |
309 | $output = $PAGE->get_renderer('core', 'admin'); | |
310 | ||
9008ec16 PS |
311 | if (upgrade_stale_php_files_present()) { |
312 | $PAGE->set_title($stradministration); | |
313 | $PAGE->set_cacheable(false); | |
314 | ||
9008ec16 PS |
315 | echo $output->upgrade_stale_php_files_page(); |
316 | die(); | |
317 | } | |
318 | ||
00be1916 | 319 | if (empty($confirmupgrade)) { |
17854cb9 | 320 | $a = new stdClass(); |
c22a579b RT |
321 | $a->oldversion = "$CFG->release (".sprintf('%.2f', $CFG->version).")"; |
322 | $a->newversion = "$release (".sprintf('%.2f', $version).")"; | |
cc359566 TH |
323 | $strdatabasechecking = get_string('databasechecking', '', $a); |
324 | ||
1a4d6a5b DM |
325 | $PAGE->set_title($stradministration); |
326 | $PAGE->set_heading($strdatabasechecking); | |
69d77c23 | 327 | $PAGE->set_cacheable(false); |
cc359566 | 328 | |
6e09cf98 | 329 | echo $output->upgrade_confirm_page($a->newversion, $maturity, $testsite); |
3ba28588 | 330 | die(); |
db5af934 | 331 | |
00be1916 | 332 | } else if (empty($confirmrelease)){ |
cc359566 TH |
333 | require_once($CFG->libdir.'/environmentlib.php'); |
334 | list($envstatus, $environment_results) = check_moodle_environment($release, ENV_SELECT_RELEASE); | |
bc76b3c0 | 335 | $strcurrentrelease = get_string('currentrelease'); |
cc359566 | 336 | |
69d77c23 | 337 | $PAGE->navbar->add($strcurrentrelease); |
338 | $PAGE->set_title($strcurrentrelease); | |
52273536 | 339 | $PAGE->set_heading($strcurrentrelease); |
69d77c23 | 340 | $PAGE->set_cacheable(false); |
db5af934 | 341 | |
faadd326 TH |
342 | echo $output->upgrade_environment_page($release, $envstatus, $environment_results); |
343 | die(); | |
db5af934 | 344 | |
cc359566 | 345 | } else if (empty($confirmplugins)) { |
00be1916 | 346 | $strplugincheck = get_string('plugincheck'); |
cc359566 | 347 | |
69d77c23 | 348 | $PAGE->navbar->add($strplugincheck); |
349 | $PAGE->set_title($strplugincheck); | |
52273536 | 350 | $PAGE->set_heading($strplugincheck); |
69d77c23 | 351 | $PAGE->set_cacheable(false); |
b9934a17 | 352 | |
2f29cf6e DM |
353 | $pluginman = core_plugin_manager::instance(); |
354 | ||
355 | if ($abortinstallx) { | |
531381f9 | 356 | // No sesskey support guaranteed here, because sessions might not work yet. |
2f29cf6e DM |
357 | $pluginman->cancel_all_plugin_installations(); |
358 | redirect($PAGE->url); | |
359 | } | |
360 | ||
361 | if ($abortinstall) { | |
531381f9 | 362 | // No sesskey support guaranteed here, because sessions might not work yet. |
2f29cf6e DM |
363 | $pluginman->cancel_plugin_installation($abortinstall); |
364 | redirect($PAGE->url); | |
365 | } | |
366 | ||
531381f9 DM |
367 | // Install all available missing dependencies. |
368 | if ($installdepx) { | |
369 | // No sesskey support guaranteed here, because sessions might not work yet. | |
370 | $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true)); | |
2d00be61 | 371 | upgrade_install_plugins($installable, $confirminstalldep, |
531381f9 DM |
372 | get_string('dependencyinstallhead', 'core_plugin'), |
373 | new moodle_url($PAGE->url, array('installdepx' => 1, 'confirminstalldep' => 1)) | |
374 | ); | |
375 | } | |
376 | ||
377 | // Install single available missing dependency. | |
378 | if ($installdep) { | |
379 | // No sesskey support guaranteed here, because sessions might not work yet. | |
380 | $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true)); | |
381 | if (!empty($installable[$installdep])) { | |
382 | $installable = array($installable[$installdep]); | |
2d00be61 | 383 | upgrade_install_plugins($installable, $confirminstalldep, |
531381f9 DM |
384 | get_string('dependencyinstallhead', 'core_plugin'), |
385 | new moodle_url($PAGE->url, array('installdep' => $installdep, 'confirminstalldep' => 1)) | |
386 | ); | |
387 | } | |
388 | } | |
389 | ||
390 | // Install all avilable updates. | |
391 | if ($installupdatex) { | |
392 | // No sesskey support guaranteed here, because sessions might not work yet. | |
393 | $installable = $pluginman->filter_installable($pluginman->available_updates()); | |
2d00be61 | 394 | upgrade_install_plugins($installable, $confirminstallupdate, |
531381f9 DM |
395 | get_string('updateavailableinstallallhead', 'core_admin'), |
396 | new moodle_url($PAGE->url, array('installupdatex' => 1, 'confirminstallupdate' => 1)) | |
397 | ); | |
398 | } | |
399 | ||
400 | // Install single available update. | |
401 | if ($installupdate and $installupdateversion) { | |
402 | // No sesskey support guaranteed here, because sessions might not work yet. | |
403 | if ($pluginman->is_remote_plugin_installable($installupdate, $installupdateversion)) { | |
404 | $installable = array($pluginman->get_remote_plugin_info($installupdate, $installupdateversion, true)); | |
2d00be61 | 405 | upgrade_install_plugins($installable, $confirminstallupdate, |
531381f9 DM |
406 | get_string('updateavailableinstallallhead', 'core_admin'), |
407 | new moodle_url($PAGE->url, array('installupdate' => $installupdate, | |
408 | 'installupdateversion' => $installupdateversion, 'confirminstallupdate' => 1) | |
409 | ) | |
410 | ); | |
411 | } | |
412 | } | |
ead8ba3b | 413 | |
96dd9237 | 414 | if ($fetchupdates) { |
531381f9 | 415 | // No sesskey support guaranteed here, because sessions might not work yet. |
fc281113 PS |
416 | $updateschecker = \core\update\checker::instance(); |
417 | if ($updateschecker->enabled()) { | |
418 | $updateschecker->fetch(); | |
4db58f5f | 419 | } |
2f29cf6e | 420 | redirect($PAGE->url); |
96dd9237 DM |
421 | } |
422 | ||
e87214bd | 423 | echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(), |
2f29cf6e | 424 | $version, $showallplugins, $PAGE->url, new moodle_url($PAGE->url, array('confirmplugincheck' => 1))); |
00be1916 | 425 | die(); |
db5af934 | 426 | |
00be1916 | 427 | } else { |
fc281113 PS |
428 | // Always verify plugin dependencies! |
429 | $failed = array(); | |
430 | if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { | |
2f29cf6e | 431 | echo $output->unsatisfied_dependencies_page($version, $failed, $PAGE->url); |
fc281113 PS |
432 | die(); |
433 | } | |
434 | unset($failed); | |
435 | ||
436 | // Launch main upgrade. | |
00be1916 | 437 | upgrade_core($version, true); |
88582df4 | 438 | } |
00be1916 | 439 | } else if ($version < $CFG->version) { |
80380bd7 PS |
440 | // better stop here, we can not continue with plugin upgrades or anything else |
441 | throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/')); | |
00be1916 | 442 | } |
443 | ||
444 | // Updated human-readable release version if necessary | |
82b1cf00 | 445 | if (!$cache and $release <> $CFG->release) { // Update the release version |
bc76b3c0 | 446 | set_config('release', $release); |
00be1916 | 447 | } |
448 | ||
82b1cf00 | 449 | if (!$cache and $branch <> $CFG->branch) { // Update the branch |
ed01233a AB |
450 | set_config('branch', $branch); |
451 | } | |
452 | ||
82b1cf00 | 453 | if (!$cache and moodle_needs_upgrading()) { |
98b32c9e | 454 | |
2f29cf6e DM |
455 | $PAGE->set_url(new moodle_url($PAGE->url, array('confirmplugincheck' => $confirmplugins))); |
456 | ||
98b32c9e DM |
457 | check_upgrade_key($upgradekeyhash); |
458 | ||
575f245f | 459 | if (!$PAGE->headerprinted) { |
2361b7dd | 460 | // means core upgrade or installation was not already done |
531381f9 | 461 | $pluginman = core_plugin_manager::instance(); |
fc281113 | 462 | |
575f245f | 463 | if (!$confirmplugins) { |
cc359566 TH |
464 | $strplugincheck = get_string('plugincheck'); |
465 | ||
575f245f PS |
466 | $PAGE->navbar->add($strplugincheck); |
467 | $PAGE->set_title($strplugincheck); | |
468 | $PAGE->set_heading($strplugincheck); | |
469 | $PAGE->set_cacheable(false); | |
b9934a17 | 470 | |
2f29cf6e DM |
471 | if ($abortinstallx) { |
472 | require_sesskey(); | |
473 | $pluginman->cancel_all_plugin_installations(); | |
474 | redirect($PAGE->url); | |
475 | } | |
476 | ||
477 | if ($abortinstall) { | |
478 | require_sesskey(); | |
479 | $pluginman->cancel_plugin_installation($abortinstall); | |
480 | redirect($PAGE->url); | |
481 | } | |
482 | ||
96dd9237 | 483 | if ($fetchupdates) { |
fc281113 PS |
484 | require_sesskey(); |
485 | $updateschecker = \core\update\checker::instance(); | |
486 | if ($updateschecker->enabled()) { | |
487 | $updateschecker->fetch(); | |
488 | } | |
96dd9237 DM |
489 | redirect($PAGE->url); |
490 | } | |
491 | ||
531381f9 DM |
492 | // Install all available missing dependencies. |
493 | if ($installdepx) { | |
494 | require_sesskey(); | |
495 | $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true)); | |
2d00be61 | 496 | upgrade_install_plugins($installable, $confirminstalldep, |
531381f9 DM |
497 | get_string('dependencyinstallhead', 'core_plugin'), |
498 | new moodle_url($PAGE->url, array('installdepx' => 1, 'confirminstalldep' => 1)) | |
499 | ); | |
500 | } | |
501 | ||
502 | // Install single available missing dependency. | |
503 | if ($installdep) { | |
504 | require_sesskey(); | |
505 | $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true)); | |
506 | if (!empty($installable[$installdep])) { | |
507 | $installable = array($installable[$installdep]); | |
2d00be61 | 508 | upgrade_install_plugins($installable, $confirminstalldep, |
531381f9 DM |
509 | get_string('dependencyinstallhead', 'core_plugin'), |
510 | new moodle_url($PAGE->url, array('installdep' => $installdep, 'confirminstalldep' => 1)) | |
511 | ); | |
512 | } | |
513 | } | |
12890c57 | 514 | |
531381f9 DM |
515 | // Install all available updates. |
516 | if ($installupdatex) { | |
517 | require_sesskey(); | |
518 | $installable = $pluginman->filter_installable($pluginman->available_updates()); | |
2d00be61 | 519 | upgrade_install_plugins($installable, $confirminstallupdate, |
531381f9 DM |
520 | get_string('updateavailableinstallallhead', 'core_admin'), |
521 | new moodle_url($PAGE->url, array('installupdatex' => 1, 'confirminstallupdate' => 1)) | |
522 | ); | |
523 | } | |
292dbeac | 524 | |
531381f9 DM |
525 | // Install single available update. |
526 | if ($installupdate and $installupdateversion) { | |
527 | require_sesskey(); | |
528 | if ($pluginman->is_remote_plugin_installable($installupdate, $installupdateversion)) { | |
529 | $installable = array($pluginman->get_remote_plugin_info($installupdate, $installupdateversion, true)); | |
2d00be61 | 530 | upgrade_install_plugins($installable, $confirminstallupdate, |
531381f9 DM |
531 | get_string('updateavailableinstallallhead', 'core_admin'), |
532 | new moodle_url($PAGE->url, array('installupdate' => $installupdate, | |
533 | 'installupdateversion' => $installupdateversion, 'confirminstallupdate' => 1) | |
534 | ) | |
535 | ); | |
292dbeac DM |
536 | } |
537 | } | |
538 | ||
531381f9 DM |
539 | /** @var core_admin_renderer $output */ |
540 | $output = $PAGE->get_renderer('core', 'admin'); | |
541 | ||
fc281113 | 542 | // Show plugins info. |
2f29cf6e | 543 | echo $output->upgrade_plugin_check_page($pluginman, \core\update\checker::instance(), |
96dd9237 DM |
544 | $version, $showallplugins, |
545 | new moodle_url($PAGE->url), | |
98b32c9e | 546 | new moodle_url($PAGE->url, array('confirmplugincheck' => 1, 'cache' => 0))); |
fc281113 PS |
547 | die(); |
548 | } | |
549 | ||
550 | // Make sure plugin dependencies are always checked. | |
551 | $failed = array(); | |
2f29cf6e | 552 | if (!$pluginman->all_plugins_ok($version, $failed)) { |
12890c57 SH |
553 | /** @var core_admin_renderer $output */ |
554 | $output = $PAGE->get_renderer('core', 'admin'); | |
2f29cf6e | 555 | echo $output->unsatisfied_dependencies_page($version, $failed, $PAGE->url); |
575f245f PS |
556 | die(); |
557 | } | |
fc281113 | 558 | unset($failed); |
575f245f | 559 | } |
fc281113 | 560 | |
575f245f PS |
561 | // install/upgrade all plugins and other parts |
562 | upgrade_noncore(true); | |
563 | } | |
00be1916 | 564 | |
31a99877 | 565 | // If this is the first install, indicate that this site is fully configured |
566 | // except the admin password | |
567 | if (during_initial_install()) { | |
568 | set_config('rolesactive', 1); // after this, during_initial_install will return false. | |
00be1916 | 569 | set_config('adminsetuppending', 1); |
c8ae55e9 | 570 | // we need this redirect to setup proper session |
00be1916 | 571 | upgrade_finished("index.php?sessionstarted=1&lang=$CFG->lang"); |
572 | } | |
573 | ||
574 | // make sure admin user is created - this is the last step because we need | |
575 | // session to be working properly in order to edit admin account | |
576 | if (!empty($CFG->adminsetuppending)) { | |
577 | $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL); | |
578 | if (!$sessionstarted) { | |
579 | redirect("index.php?sessionstarted=1&lang=$CFG->lang"); | |
580 | } else { | |
581 | $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL); | |
582 | if (!$sessionverify) { | |
583 | $SESSION->sessionverify = 1; | |
584 | redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang"); | |
88582df4 | 585 | } else { |
00be1916 | 586 | if (empty($SESSION->sessionverify)) { |
587 | print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang"); | |
88582df4 | 588 | } |
00be1916 | 589 | unset($SESSION->sessionverify); |
88582df4 | 590 | } |
00be1916 | 591 | } |
88582df4 | 592 | |
4f73591a PS |
593 | // Cleanup SESSION to make sure other code does not complain in the future. |
594 | unset($SESSION->has_timed_out); | |
595 | unset($SESSION->wantsurl); | |
596 | ||
a7c9609b | 597 | // at this stage there can be only one admin unless more were added by install - users may change username, so do not rely on that |
f20edd52 PS |
598 | $adminids = explode(',', $CFG->siteadmins); |
599 | $adminuser = get_complete_user_data('id', reset($adminids)); | |
88582df4 | 600 | |
00be1916 | 601 | if ($adminuser->password === 'adminsetuppending') { |
602 | // prevent installation hijacking | |
603 | if ($adminuser->lastip !== getremoteaddr()) { | |
604 | print_error('installhijacked', 'admin'); | |
35d6a2a4 | 605 | } |
00be1916 | 606 | // login user and let him set password and admin details |
607 | $adminuser->newadminuser = 1; | |
0342fc36 | 608 | complete_user_login($adminuser); |
00be1916 | 609 | redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself |
db5af934 | 610 | |
5c144d60 | 611 | } else { |
00be1916 | 612 | unset_config('adminsetuppending'); |
4da1a0a1 | 613 | } |
614 | ||
00be1916 | 615 | } else { |
616 | // just make sure upgrade logging is properly terminated | |
617 | upgrade_finished('upgradesettings.php'); | |
618 | } | |
b3732604 | 619 | |
fc281113 PS |
620 | if (has_capability('moodle/site:config', context_system::instance())) { |
621 | if ($fetchupdates) { | |
622 | require_sesskey(); | |
623 | $updateschecker = \core\update\checker::instance(); | |
624 | if ($updateschecker->enabled()) { | |
625 | $updateschecker->fetch(); | |
626 | } | |
627 | redirect(new moodle_url('/admin/index.php', array('cache' => 0))); | |
628 | } | |
629 | } | |
630 | ||
e2e35e71 PS |
631 | // Now we can be sure everything was upgraded and caches work fine, |
632 | // redirect if necessary to make sure caching is enabled. | |
82b1cf00 PS |
633 | if (!$cache) { |
634 | redirect(new moodle_url('/admin/index.php', array('cache' => 1))); | |
e2e35e71 PS |
635 | } |
636 | ||
00be1916 | 637 | // Check for valid admin user - no guest autologin |
638 | require_login(0, false); | |
fc1d0e82 PŠ |
639 | if (isguestuser()) { |
640 | // Login as real user! | |
641 | $SESSION->wantsurl = (string)new moodle_url('/admin/index.php'); | |
642 | redirect(get_login_url()); | |
643 | } | |
bf006d2c | 644 | $context = context_system::instance(); |
336a8433 MG |
645 | |
646 | if (!has_capability('moodle/site:config', $context)) { | |
647 | // Do not throw exception display an empty page with administration menu if visible for current user. | |
648 | $PAGE->set_title($SITE->fullname); | |
649 | $PAGE->set_heading($SITE->fullname); | |
650 | echo $OUTPUT->header(); | |
651 | echo $OUTPUT->footer(); | |
652 | exit; | |
653 | } | |
00be1916 | 654 | |
655 | // check that site is properly customized | |
656 | $site = get_site(); | |
657 | if (empty($site->shortname)) { | |
658 | // probably new installation - lets return to frontpage after this step | |
659 | // remove settings that we want uninitialised | |
660 | unset_config('registerauth'); | |
d6e7a63d | 661 | unset_config('timezone'); // Force admin to select timezone! |
00be1916 | 662 | redirect('upgradesettings.php?return=site'); |
663 | } | |
664 | ||
00be1916 | 665 | // setup critical warnings before printing admin tree block |
bc76b3c0 | 666 | $insecuredataroot = is_dataroot_insecure(true); |
00be1916 | 667 | $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR); |
668 | ||
669 | $adminroot = admin_get_root(); | |
670 | ||
671 | // Check if there are any new admin settings which have still yet to be set | |
672 | if (any_new_admin_settings($adminroot)){ | |
673 | redirect('upgradesettings.php'); | |
674 | } | |
675 | ||
e87214bd PS |
676 | // Return to original page that started the plugin uninstallation if necessary. |
677 | if (isset($SESSION->pluginuninstallreturn)) { | |
678 | $return = $SESSION->pluginuninstallreturn; | |
679 | unset($SESSION->pluginuninstallreturn); | |
680 | if ($return) { | |
681 | redirect($return); | |
682 | } | |
683 | } | |
684 | ||
00be1916 | 685 | // Everything should now be set up, and the user is an admin |
686 | ||
687 | // Print default admin page with notifications. | |
cc359566 | 688 | $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED'); |
a95682b2 | 689 | |
d5fcf4b4 DP |
690 | // We make the assumption that at least one schedule task should run once per day. |
691 | $lastcron = $DB->get_field_sql('SELECT MAX(lastruntime) FROM {task_scheduled}'); | |
cc359566 TH |
692 | $cronoverdue = ($lastcron < time() - 3600 * 24); |
693 | $dbproblems = $DB->diagnose(); | |
694 | $maintenancemode = !empty($CFG->maintenance_enabled); | |
74944b73 | 695 | |
ca6f3a8b | 696 | // Available updates for Moodle core. |
e87214bd | 697 | $updateschecker = \core\update\checker::instance(); |
966bd785 | 698 | $availableupdates = array(); |
ca6f3a8b FM |
699 | $availableupdatesfetch = null; |
700 | ||
e9d3c212 | 701 | if ($updateschecker->enabled()) { |
ca6f3a8b FM |
702 | // Only compute the update information when it is going to be displayed to the user. |
703 | $availableupdates['core'] = $updateschecker->get_update_info('core', | |
704 | array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds)); | |
705 | ||
706 | // Available updates for contributed plugins | |
707 | $pluginman = core_plugin_manager::instance(); | |
708 | foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) { | |
709 | foreach ($plugintypeinstances as $pluginname => $plugininfo) { | |
30d8bc5f DM |
710 | $pluginavailableupdates = $plugininfo->available_updates(); |
711 | if (!empty($pluginavailableupdates)) { | |
712 | foreach ($pluginavailableupdates as $pluginavailableupdate) { | |
713 | if (!isset($availableupdates[$plugintype.'_'.$pluginname])) { | |
714 | $availableupdates[$plugintype.'_'.$pluginname] = array(); | |
966bd785 | 715 | } |
30d8bc5f | 716 | $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate; |
966bd785 DM |
717 | } |
718 | } | |
719 | } | |
720 | } | |
966bd785 | 721 | |
ca6f3a8b FM |
722 | // The timestamp of the most recent check for available updates |
723 | $availableupdatesfetch = $updateschecker->get_last_timefetched(); | |
724 | } | |
55585f3a | 725 | |
0aff15c2 | 726 | $buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€'); |
b3245b75 DP |
727 | //check if the site is registered on Moodle.org |
728 | $registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL, 'confirmed' => 1)); | |
915140c9 SH |
729 | // Check if there are any cache warnings. |
730 | $cachewarnings = cache_helper::warnings(); | |
0aff15c2 | 731 | |
cc359566 | 732 | admin_externalpage_setup('adminnotifications'); |
55585f3a | 733 | |
915140c9 | 734 | /* @var core_admin_renderer $output */ |
cc359566 | 735 | $output = $PAGE->get_renderer('core', 'admin'); |
915140c9 SH |
736 | |
737 | echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems, | |
738 | $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, | |
739 | $registered, $cachewarnings); |