MDL-52138 core_grades: gradebook striped styling
[moodle.git] / admin / index.php
blobee3b2e3b85e778f2de5a175e51f285fb8c56849a
1 <?php
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.
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/>.
18 /**
19 * Main administration script.
21 * @package core
22 * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com)
23 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
26 // Check that config.php exists, if not then call the install script
27 if (!file_exists('../config.php')) {
28 header('Location: ../install.php');
29 die();
32 // Check that PHP is of a sufficient version as soon as possible.
33 require_once(__DIR__.'/../lib/phpminimumversionlib.php');
34 moodle_require_minimum_php_version();
36 // make sure iconv is available and actually works
37 if (!function_exists('iconv')) {
38 // this should not happen, this must be very borked install
39 echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.';
40 die();
43 // Make sure php5-json is available.
44 if (!function_exists('json_encode') || !function_exists('json_decode')) {
45 // This also shouldn't happen.
46 echo 'Moodle requires the json PHP extension. Please install or enable the json extension.';
47 die();
50 // Make sure xml extension is available.
51 if (!extension_loaded('xml')) {
52 echo 'Moodle requires the xml PHP extension. Please install or enable the xml extension.';
53 die();
56 define('NO_OUTPUT_BUFFERING', true);
58 if (isset($_POST['upgradekey'])) {
59 // Before you start reporting issues about the collision attacks against
60 // SHA-1, you should understand that we are not actually attempting to do
61 // any cryptography here. This is hashed purely so that the key is not
62 // that apparent in the address bar itself. Anyone who catches the HTTP
63 // traffic can immediately use it as a valid admin key.
64 header('Location: index.php?cache=0&upgradekeyhash='.sha1($_POST['upgradekey']));
65 die();
68 if ((isset($_GET['cache']) and $_GET['cache'] === '0')
69 or (isset($_POST['cache']) and $_POST['cache'] === '0')
70 or (!isset($_POST['cache']) and !isset($_GET['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey']))) {
71 // Prevent caching at all cost when visiting this page directly,
72 // we redirect to self once we known no upgrades are necessary.
73 // Note: $_GET and $_POST are used here intentionally because our param cleaning is not loaded yet.
74 // Note2: the sesskey is present in all block editing hacks, we can not redirect there, so enable caching.
75 define('CACHE_DISABLE_ALL', true);
77 // Force OPcache reset if used, we do not want any stale caches
78 // when detecting if upgrade necessary or when running upgrade.
79 if (function_exists('opcache_reset')) {
80 opcache_reset();
82 $cache = 0;
84 } else {
85 $cache = 1;
88 require('../config.php');
90 // Invalidate the cache of version.php in any circumstances to help core_component
91 // detecting if the version has changed and component cache should be reset.
92 if (function_exists('opcache_invalidate')) {
93 opcache_invalidate($CFG->dirroot . '/version.php', true);
95 // Make sure the component cache gets rebuilt if necessary, any method that
96 // indirectly calls the protected init() method is good here.
97 core_component::get_core_subsystems();
99 if (is_major_upgrade_required() && isloggedin()) {
100 // A major upgrade is required.
101 // Terminate the session and redirect back here before anything DB-related happens.
102 redirect_if_major_upgrade_required();
105 require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions
106 require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions
108 $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL); // Core upgrade confirmed?
109 $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL); // Core release info and server checks confirmed?
110 $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL); // Plugins check page confirmed?
111 $showallplugins = optional_param('showallplugins', 0, PARAM_BOOL); // Show all plugins on the plugins check page?
112 $agreelicense = optional_param('agreelicense', 0, PARAM_BOOL); // GPL license confirmed for installation?
113 $fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL); // Should check for available updates?
114 $newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW); // Plugin installation requested at moodle.org/plugins.
115 $upgradekeyhash = optional_param('upgradekeyhash', null, PARAM_ALPHANUM); // Hash of provided upgrade key.
116 $installdep = optional_param('installdep', null, PARAM_COMPONENT); // Install given missing dependency (required plugin).
117 $installdepx = optional_param('installdepx', false, PARAM_BOOL); // Install all missing dependencies.
118 $confirminstalldep = optional_param('confirminstalldep', false, PARAM_BOOL); // Installing dependencies confirmed.
119 $abortinstall = optional_param('abortinstall', null, PARAM_COMPONENT); // Cancel installation of the given new plugin.
120 $abortinstallx = optional_param('abortinstallx', null, PARAM_BOOL); // Cancel installation of all new plugins.
121 $confirmabortinstall = optional_param('confirmabortinstall', false, PARAM_BOOL); // Installation cancel confirmed.
122 $abortupgrade = optional_param('abortupgrade', null, PARAM_COMPONENT); // Cancel upgrade of the given existing plugin.
123 $abortupgradex = optional_param('abortupgradex', null, PARAM_BOOL); // Cancel upgrade of all upgradable plugins.
124 $confirmabortupgrade = optional_param('confirmabortupgrade', false, PARAM_BOOL); // Upgrade cancel confirmed.
125 $installupdate = optional_param('installupdate', null, PARAM_COMPONENT); // Install given available update.
126 $installupdateversion = optional_param('installupdateversion', null, PARAM_INT); // Version of the available update to install.
127 $installupdatex = optional_param('installupdatex', false, PARAM_BOOL); // Install all available plugin updates.
128 $confirminstallupdate = optional_param('confirminstallupdate', false, PARAM_BOOL); // Available update(s) install confirmed?
130 if (!empty($CFG->disableupdateautodeploy)) {
131 // Invalidate all requests to install plugins via the admin UI.
132 $newaddonreq = null;
133 $installdep = null;
134 $installdepx = false;
135 $abortupgrade = null;
136 $abortupgradex = null;
137 $installupdate = null;
138 $installupdateversion = null;
139 $installupdatex = false;
142 // Set up PAGE.
143 $url = new moodle_url('/admin/index.php');
144 $url->param('cache', $cache);
145 if (isset($upgradekeyhash)) {
146 $url->param('upgradekeyhash', $upgradekeyhash);
148 $PAGE->set_url($url);
149 unset($url);
151 // Are we returning from an add-on installation request at moodle.org/plugins?
152 if ($newaddonreq and !$cache and empty($CFG->disableupdateautodeploy)) {
153 $target = new moodle_url('/admin/tool/installaddon/index.php', array(
154 'installaddonrequest' => $newaddonreq,
155 'confirm' => 0));
156 if (!isloggedin() or isguestuser()) {
157 // Login and go the the add-on tool page.
158 $SESSION->wantsurl = $target->out();
159 redirect(get_login_url());
161 redirect($target);
164 $PAGE->set_pagelayout('admin'); // Set a default pagelayout
166 $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
168 // Check some PHP server settings
170 if (ini_get_bool('session.auto_start')) {
171 print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
174 if (!ini_get_bool('file_uploads')) {
175 print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink));
178 if (is_float_problem()) {
179 print_error('phpfloatproblem', 'admin', '', $documentationlink);
182 // Set some necessary variables during set-up to avoid PHP warnings later on this page
183 if (!isset($CFG->release)) {
184 $CFG->release = '';
186 if (!isset($CFG->version)) {
187 $CFG->version = '';
189 if (!isset($CFG->branch)) {
190 $CFG->branch = '';
193 $version = null;
194 $release = null;
195 $branch = null;
196 require("$CFG->dirroot/version.php"); // defines $version, $release, $branch and $maturity
197 $CFG->target_release = $release; // used during installation and upgrades
199 if (!$version or !$release) {
200 print_error('withoutversion', 'debug'); // without version, stop
203 if (!core_tables_exist()) {
204 $PAGE->set_pagelayout('maintenance');
205 $PAGE->set_popup_notification_allowed(false);
207 // fake some settings
208 $CFG->docroot = 'http://docs.moodle.org';
210 $strinstallation = get_string('installation', 'install');
212 // remove current session content completely
213 \core\session\manager::terminate_current();
215 if (empty($agreelicense)) {
216 $strlicense = get_string('license');
218 $PAGE->navbar->add($strlicense);
219 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
220 $PAGE->set_heading($strinstallation);
221 $PAGE->set_cacheable(false);
223 $output = $PAGE->get_renderer('core', 'admin');
224 echo $output->install_licence_page();
225 die();
227 if (empty($confirmrelease)) {
228 require_once($CFG->libdir.'/environmentlib.php');
229 list($envstatus, $environmentresults) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE);
230 $strcurrentrelease = get_string('currentrelease');
232 $PAGE->navbar->add($strcurrentrelease);
233 $PAGE->set_title($strinstallation);
234 $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release);
235 $PAGE->set_cacheable(false);
237 $output = $PAGE->get_renderer('core', 'admin');
238 echo $output->install_environment_page($maturity, $envstatus, $environmentresults, $release);
239 die();
242 // check plugin dependencies
243 $failed = array();
244 if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed, $CFG->branch)) {
245 $PAGE->navbar->add(get_string('pluginscheck', 'admin'));
246 $PAGE->set_title($strinstallation);
247 $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release);
249 $output = $PAGE->get_renderer('core', 'admin');
250 $url = new moodle_url($PAGE->url, array('agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang));
251 echo $output->unsatisfied_dependencies_page($version, $failed, $url);
252 die();
254 unset($failed);
256 //TODO: add a page with list of non-standard plugins here
258 $strdatabasesetup = get_string('databasesetup');
259 upgrade_init_javascript();
261 $PAGE->navbar->add($strdatabasesetup);
262 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release);
263 $PAGE->set_heading($strinstallation);
264 $PAGE->set_cacheable(false);
266 $output = $PAGE->get_renderer('core', 'admin');
267 echo $output->header();
269 if (!$DB->setup_is_unicodedb()) {
270 if (!$DB->change_db_encoding()) {
271 // If could not convert successfully, throw error, and prevent installation
272 print_error('unicoderequired', 'admin');
276 install_core($version, true);
280 // Check version of Moodle code on disk compared with database
281 // and upgrade if possible.
283 if (!$cache) {
284 // Do not try to do anything fancy in non-cached mode,
285 // this prevents themes from fetching data from non-existent tables.
286 $PAGE->set_pagelayout('maintenance');
287 $PAGE->set_popup_notification_allowed(false);
290 $stradministration = get_string('administration');
291 $PAGE->set_context(context_system::instance());
293 if (empty($CFG->version)) {
294 print_error('missingconfigversion', 'debug');
297 // Detect config cache inconsistency, this happens when you switch branches on dev servers.
298 if ($CFG->version != $DB->get_field('config', 'value', array('name'=>'version'))) {
299 purge_all_caches();
300 redirect(new moodle_url($PAGE->url), 'Config cache inconsistency detected, resetting caches...');
303 if (!$cache and $version > $CFG->version) { // upgrade
305 $PAGE->set_url(new moodle_url($PAGE->url, array(
306 'confirmupgrade' => $confirmupgrade,
307 'confirmrelease' => $confirmrelease,
308 'confirmplugincheck' => $confirmplugins,
309 )));
311 check_upgrade_key($upgradekeyhash);
313 // Warning about upgrading a test site.
314 $testsite = false;
315 if (defined('BEHAT_SITE_RUNNING')) {
316 $testsite = 'behat';
319 if (isset($CFG->themerev)) {
320 // Store the themerev to restore after purging caches.
321 $themerev = $CFG->themerev;
324 // We purge all of MUC's caches here.
325 // Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true.
326 // This ensures a real config object is loaded and the stores will be purged.
327 // This is the only way we can purge custom caches such as memcache or APC.
328 // Note: all other calls to caches will still used the disabled API.
329 cache_helper::purge_all(true);
330 // We then purge the regular caches.
331 purge_all_caches();
333 if (isset($themerev)) {
334 // Restore the themerev
335 set_config('themerev', $themerev);
338 $output = $PAGE->get_renderer('core', 'admin');
340 if (upgrade_stale_php_files_present()) {
341 $PAGE->set_title($stradministration);
342 $PAGE->set_cacheable(false);
344 echo $output->upgrade_stale_php_files_page();
345 die();
348 if (empty($confirmupgrade)) {
349 $a = new stdClass();
350 $a->oldversion = "$CFG->release (".sprintf('%.2f', $CFG->version).")";
351 $a->newversion = "$release (".sprintf('%.2f', $version).")";
352 $strdatabasechecking = get_string('databasechecking', '', $a);
354 $PAGE->set_title($stradministration);
355 $PAGE->set_heading($strdatabasechecking);
356 $PAGE->set_cacheable(false);
358 echo $output->upgrade_confirm_page($a->newversion, $maturity, $testsite);
359 die();
361 } else if (empty($confirmrelease)) {
362 require_once($CFG->libdir.'/environmentlib.php');
363 list($envstatus, $environmentresults) = check_moodle_environment($release, ENV_SELECT_RELEASE);
364 $strcurrentrelease = get_string('currentrelease');
366 $PAGE->navbar->add($strcurrentrelease);
367 $PAGE->set_title($strcurrentrelease);
368 $PAGE->set_heading($strcurrentrelease);
369 $PAGE->set_cacheable(false);
371 echo $output->upgrade_environment_page($release, $envstatus, $environmentresults);
372 die();
374 } else if (empty($confirmplugins)) {
375 $strplugincheck = get_string('plugincheck');
377 $PAGE->navbar->add($strplugincheck);
378 $PAGE->set_title($strplugincheck);
379 $PAGE->set_heading($strplugincheck);
380 $PAGE->set_cacheable(false);
382 $pluginman = core_plugin_manager::instance();
384 // Check for available updates.
385 if ($fetchupdates) {
386 // No sesskey support guaranteed here, because sessions might not work yet.
387 $updateschecker = \core\update\checker::instance();
388 if ($updateschecker->enabled()) {
389 $updateschecker->fetch();
391 redirect($PAGE->url);
394 // Cancel all plugin installations.
395 if ($abortinstallx) {
396 // No sesskey support guaranteed here, because sessions might not work yet.
397 $abortables = $pluginman->list_cancellable_installations();
398 if ($abortables) {
399 if ($confirmabortinstall) {
400 foreach ($abortables as $plugin) {
401 $pluginman->cancel_plugin_installation($plugin->component);
403 redirect($PAGE->url);
404 } else {
405 $continue = new moodle_url($PAGE->url, array('abortinstallx' => $abortinstallx, 'confirmabortinstall' => 1));
406 echo $output->upgrade_confirm_abort_install_page($abortables, $continue);
407 die();
410 redirect($PAGE->url);
413 // Cancel single plugin installation.
414 if ($abortinstall) {
415 // No sesskey support guaranteed here, because sessions might not work yet.
416 if ($confirmabortinstall) {
417 $pluginman->cancel_plugin_installation($abortinstall);
418 redirect($PAGE->url);
419 } else {
420 $continue = new moodle_url($PAGE->url, array('abortinstall' => $abortinstall, 'confirmabortinstall' => 1));
421 $abortable = $pluginman->get_plugin_info($abortinstall);
422 if ($pluginman->can_cancel_plugin_installation($abortable)) {
423 echo $output->upgrade_confirm_abort_install_page(array($abortable), $continue);
424 die();
426 redirect($PAGE->url);
430 // Cancel all plugins upgrades (that is, restore archived versions).
431 if ($abortupgradex) {
432 // No sesskey support guaranteed here, because sessions might not work yet.
433 $restorable = $pluginman->list_restorable_archives();
434 if ($restorable) {
435 upgrade_install_plugins($restorable, $confirmabortupgrade,
436 get_string('cancelupgradehead', 'core_plugin'),
437 new moodle_url($PAGE->url, array('abortupgradex' => 1, 'confirmabortupgrade' => 1))
440 redirect($PAGE->url);
443 // Cancel single plugin upgrade (that is, install the archived version).
444 if ($abortupgrade) {
445 // No sesskey support guaranteed here, because sessions might not work yet.
446 $restorable = $pluginman->list_restorable_archives();
447 if (isset($restorable[$abortupgrade])) {
448 $restorable = array($restorable[$abortupgrade]);
449 upgrade_install_plugins($restorable, $confirmabortupgrade,
450 get_string('cancelupgradehead', 'core_plugin'),
451 new moodle_url($PAGE->url, array('abortupgrade' => $abortupgrade, 'confirmabortupgrade' => 1))
454 redirect($PAGE->url);
457 // Install all available missing dependencies.
458 if ($installdepx) {
459 // No sesskey support guaranteed here, because sessions might not work yet.
460 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
461 upgrade_install_plugins($installable, $confirminstalldep,
462 get_string('dependencyinstallhead', 'core_plugin'),
463 new moodle_url($PAGE->url, array('installdepx' => 1, 'confirminstalldep' => 1))
467 // Install single available missing dependency.
468 if ($installdep) {
469 // No sesskey support guaranteed here, because sessions might not work yet.
470 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
471 if (!empty($installable[$installdep])) {
472 $installable = array($installable[$installdep]);
473 upgrade_install_plugins($installable, $confirminstalldep,
474 get_string('dependencyinstallhead', 'core_plugin'),
475 new moodle_url($PAGE->url, array('installdep' => $installdep, 'confirminstalldep' => 1))
480 // Install all available updates.
481 if ($installupdatex) {
482 // No sesskey support guaranteed here, because sessions might not work yet.
483 $installable = $pluginman->filter_installable($pluginman->available_updates());
484 upgrade_install_plugins($installable, $confirminstallupdate,
485 get_string('updateavailableinstallallhead', 'core_admin'),
486 new moodle_url($PAGE->url, array('installupdatex' => 1, 'confirminstallupdate' => 1))
490 // Install single available update.
491 if ($installupdate and $installupdateversion) {
492 // No sesskey support guaranteed here, because sessions might not work yet.
493 if ($pluginman->is_remote_plugin_installable($installupdate, $installupdateversion)) {
494 $installable = array($pluginman->get_remote_plugin_info($installupdate, $installupdateversion, true));
495 upgrade_install_plugins($installable, $confirminstallupdate,
496 get_string('updateavailableinstallallhead', 'core_admin'),
497 new moodle_url($PAGE->url, array('installupdate' => $installupdate,
498 'installupdateversion' => $installupdateversion, 'confirminstallupdate' => 1)
504 echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(),
505 $version, $showallplugins, $PAGE->url, new moodle_url($PAGE->url, array('confirmplugincheck' => 1)));
506 die();
508 } else {
509 // Always verify plugin dependencies!
510 $failed = array();
511 if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed, $CFG->branch)) {
512 echo $output->unsatisfied_dependencies_page($version, $failed, $PAGE->url);
513 die();
515 unset($failed);
517 // Launch main upgrade.
518 upgrade_core($version, true);
520 } else if ($version < $CFG->version) {
521 // better stop here, we can not continue with plugin upgrades or anything else
522 throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/'));
525 // Updated human-readable release version if necessary
526 if (!$cache and $release <> $CFG->release) { // Update the release version
527 set_config('release', $release);
530 if (!$cache and $branch <> $CFG->branch) { // Update the branch
531 set_config('branch', $branch);
534 if (!$cache and moodle_needs_upgrading()) {
536 $PAGE->set_url(new moodle_url($PAGE->url, array(
537 'confirmrelease' => $confirmrelease,
538 'confirmplugincheck' => $confirmplugins,
539 )));
541 check_upgrade_key($upgradekeyhash);
543 if (!$PAGE->headerprinted) {
544 // means core upgrade or installation was not already done
546 $pluginman = core_plugin_manager::instance();
547 $output = $PAGE->get_renderer('core', 'admin');
549 if (empty($confirmrelease)) {
550 require_once($CFG->libdir . '/environmentlib.php');
552 list($envstatus, $environmentresults) = check_moodle_environment($release, ENV_SELECT_RELEASE);
553 $strcurrentrelease = get_string('currentrelease');
555 $PAGE->navbar->add($strcurrentrelease);
556 $PAGE->set_title($strcurrentrelease);
557 $PAGE->set_heading($strcurrentrelease);
558 $PAGE->set_cacheable(false);
560 echo $output->upgrade_environment_page($release, $envstatus, $environmentresults);
561 die();
563 } else if (!$confirmplugins) {
564 $strplugincheck = get_string('plugincheck');
566 $PAGE->navbar->add($strplugincheck);
567 $PAGE->set_title($strplugincheck);
568 $PAGE->set_heading($strplugincheck);
569 $PAGE->set_cacheable(false);
571 // Check for available updates.
572 if ($fetchupdates) {
573 require_sesskey();
574 $updateschecker = \core\update\checker::instance();
575 if ($updateschecker->enabled()) {
576 $updateschecker->fetch();
578 redirect($PAGE->url);
581 // Cancel all plugin installations.
582 if ($abortinstallx) {
583 require_sesskey();
584 $abortables = $pluginman->list_cancellable_installations();
585 if ($abortables) {
586 if ($confirmabortinstall) {
587 foreach ($abortables as $plugin) {
588 $pluginman->cancel_plugin_installation($plugin->component);
590 redirect($PAGE->url);
591 } else {
592 $continue = new moodle_url($PAGE->url, array('abortinstallx' => $abortinstallx,
593 'confirmabortinstall' => 1));
594 echo $output->upgrade_confirm_abort_install_page($abortables, $continue);
595 die();
598 redirect($PAGE->url);
601 // Cancel single plugin installation.
602 if ($abortinstall) {
603 require_sesskey();
604 if ($confirmabortinstall) {
605 $pluginman->cancel_plugin_installation($abortinstall);
606 redirect($PAGE->url);
607 } else {
608 $continue = new moodle_url($PAGE->url, array('abortinstall' => $abortinstall, 'confirmabortinstall' => 1));
609 $abortable = $pluginman->get_plugin_info($abortinstall);
610 if ($pluginman->can_cancel_plugin_installation($abortable)) {
611 echo $output->upgrade_confirm_abort_install_page(array($abortable), $continue);
612 die();
614 redirect($PAGE->url);
618 // Cancel all plugins upgrades (that is, restore archived versions).
619 if ($abortupgradex) {
620 require_sesskey();
621 $restorable = $pluginman->list_restorable_archives();
622 if ($restorable) {
623 upgrade_install_plugins($restorable, $confirmabortupgrade,
624 get_string('cancelupgradehead', 'core_plugin'),
625 new moodle_url($PAGE->url, array('abortupgradex' => 1, 'confirmabortupgrade' => 1))
628 redirect($PAGE->url);
631 // Cancel single plugin upgrade (that is, install the archived version).
632 if ($abortupgrade) {
633 require_sesskey();
634 $restorable = $pluginman->list_restorable_archives();
635 if (isset($restorable[$abortupgrade])) {
636 $restorable = array($restorable[$abortupgrade]);
637 upgrade_install_plugins($restorable, $confirmabortupgrade,
638 get_string('cancelupgradehead', 'core_plugin'),
639 new moodle_url($PAGE->url, array('abortupgrade' => $abortupgrade, 'confirmabortupgrade' => 1))
642 redirect($PAGE->url);
645 // Install all available missing dependencies.
646 if ($installdepx) {
647 require_sesskey();
648 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
649 upgrade_install_plugins($installable, $confirminstalldep,
650 get_string('dependencyinstallhead', 'core_plugin'),
651 new moodle_url($PAGE->url, array('installdepx' => 1, 'confirminstalldep' => 1))
655 // Install single available missing dependency.
656 if ($installdep) {
657 require_sesskey();
658 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
659 if (!empty($installable[$installdep])) {
660 $installable = array($installable[$installdep]);
661 upgrade_install_plugins($installable, $confirminstalldep,
662 get_string('dependencyinstallhead', 'core_plugin'),
663 new moodle_url($PAGE->url, array('installdep' => $installdep, 'confirminstalldep' => 1))
668 // Install all available updates.
669 if ($installupdatex) {
670 require_sesskey();
671 $installable = $pluginman->filter_installable($pluginman->available_updates());
672 upgrade_install_plugins($installable, $confirminstallupdate,
673 get_string('updateavailableinstallallhead', 'core_admin'),
674 new moodle_url($PAGE->url, array('installupdatex' => 1, 'confirminstallupdate' => 1))
678 // Install single available update.
679 if ($installupdate and $installupdateversion) {
680 require_sesskey();
681 if ($pluginman->is_remote_plugin_installable($installupdate, $installupdateversion)) {
682 $installable = array($pluginman->get_remote_plugin_info($installupdate, $installupdateversion, true));
683 upgrade_install_plugins($installable, $confirminstallupdate,
684 get_string('updateavailableinstallallhead', 'core_admin'),
685 new moodle_url($PAGE->url, array('installupdate' => $installupdate,
686 'installupdateversion' => $installupdateversion, 'confirminstallupdate' => 1)
692 // Show plugins info.
693 echo $output->upgrade_plugin_check_page($pluginman, \core\update\checker::instance(),
694 $version, $showallplugins,
695 new moodle_url($PAGE->url),
696 new moodle_url($PAGE->url, array('confirmplugincheck' => 1, 'cache' => 0)));
697 die();
700 // Make sure plugin dependencies are always checked.
701 $failed = array();
702 if (!$pluginman->all_plugins_ok($version, $failed, $CFG->branch)) {
703 $output = $PAGE->get_renderer('core', 'admin');
704 echo $output->unsatisfied_dependencies_page($version, $failed, $PAGE->url);
705 die();
707 unset($failed);
710 // install/upgrade all plugins and other parts
711 upgrade_noncore(true);
714 // If this is the first install, indicate that this site is fully configured
715 // except the admin password
716 if (during_initial_install()) {
717 set_config('rolesactive', 1); // after this, during_initial_install will return false.
718 set_config('adminsetuppending', 1);
719 set_config('registrationpending', 1); // Remind to register site after all other setup is finished.
720 // we need this redirect to setup proper session
721 upgrade_finished("index.php?sessionstarted=1&amp;lang=$CFG->lang");
724 // make sure admin user is created - this is the last step because we need
725 // session to be working properly in order to edit admin account
726 if (!empty($CFG->adminsetuppending)) {
727 $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL);
728 if (!$sessionstarted) {
729 redirect("index.php?sessionstarted=1&lang=$CFG->lang");
730 } else {
731 $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL);
732 if (!$sessionverify) {
733 $SESSION->sessionverify = 1;
734 redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
735 } else {
736 if (empty($SESSION->sessionverify)) {
737 print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
739 unset($SESSION->sessionverify);
743 // Cleanup SESSION to make sure other code does not complain in the future.
744 unset($SESSION->has_timed_out);
745 unset($SESSION->wantsurl);
747 // 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
748 $adminids = explode(',', $CFG->siteadmins);
749 $adminuser = get_complete_user_data('id', reset($adminids));
751 if ($adminuser->password === 'adminsetuppending') {
752 // prevent installation hijacking
753 if ($adminuser->lastip !== getremoteaddr()) {
754 print_error('installhijacked', 'admin');
756 // login user and let him set password and admin details
757 $adminuser->newadminuser = 1;
758 complete_user_login($adminuser);
759 redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself
761 } else {
762 unset_config('adminsetuppending');
765 } else {
766 // just make sure upgrade logging is properly terminated
767 upgrade_finished('upgradesettings.php');
770 if (has_capability('moodle/site:config', context_system::instance())) {
771 if ($fetchupdates) {
772 require_sesskey();
773 $updateschecker = \core\update\checker::instance();
774 if ($updateschecker->enabled()) {
775 $updateschecker->fetch();
777 redirect(new moodle_url('/admin/index.php', array('cache' => 0)));
781 // Now we can be sure everything was upgraded and caches work fine,
782 // redirect if necessary to make sure caching is enabled.
783 if (!$cache) {
784 redirect(new moodle_url('/admin/index.php', array('cache' => 1)));
787 // Check for valid admin user - no guest autologin
788 require_login(0, false);
789 if (isguestuser()) {
790 // Login as real user!
791 $SESSION->wantsurl = (string)new moodle_url('/admin/index.php');
792 redirect(get_login_url());
794 $context = context_system::instance();
796 if (!has_capability('moodle/site:config', $context)) {
797 // Do not throw exception display an empty page with administration menu if visible for current user.
798 $PAGE->set_title($SITE->fullname);
799 $PAGE->set_heading($SITE->fullname);
800 echo $OUTPUT->header();
801 echo $OUTPUT->footer();
802 exit;
805 // check that site is properly customized
806 $site = get_site();
807 if (empty($site->shortname)) {
808 // probably new installation - lets return to frontpage after this step
809 // remove settings that we want uninitialised
810 unset_config('registerauth');
811 unset_config('timezone'); // Force admin to select timezone!
812 redirect('upgradesettings.php?return=site');
815 // setup critical warnings before printing admin tree block
816 $insecuredataroot = is_dataroot_insecure(true);
817 $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR);
819 $adminroot = admin_get_root();
821 // Check if there are any new admin settings which have still yet to be set
822 if (any_new_admin_settings($adminroot)) {
823 redirect('upgradesettings.php');
826 // Return to original page that started the plugin uninstallation if necessary.
827 if (isset($SESSION->pluginuninstallreturn)) {
828 $return = $SESSION->pluginuninstallreturn;
829 unset($SESSION->pluginuninstallreturn);
830 if ($return) {
831 redirect($return);
835 // If site registration needs updating, redirect.
836 \core\hub\registration::registration_reminder('/admin/index.php');
838 // Everything should now be set up, and the user is an admin
840 // Print default admin page with notifications.
841 $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED');
843 $lastcron = get_config('tool_task', 'lastcronstart');
844 $cronoverdue = ($lastcron < time() - 3600 * 24);
845 $lastcroninterval = get_config('tool_task', 'lastcroninterval');
847 $expectedfrequency = $CFG->expectedcronfrequency ?? MINSECS;
848 $croninfrequent = !$cronoverdue && ($lastcroninterval > ($expectedfrequency + MINSECS) || $lastcron < time() - $expectedfrequency);
849 $dbproblems = $DB->diagnose();
850 $maintenancemode = !empty($CFG->maintenance_enabled);
852 // Available updates for Moodle core.
853 $updateschecker = \core\update\checker::instance();
854 $availableupdates = array();
855 $availableupdatesfetch = null;
857 if ($updateschecker->enabled()) {
858 // Only compute the update information when it is going to be displayed to the user.
859 $availableupdates['core'] = $updateschecker->get_update_info('core',
860 array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds));
862 // Available updates for contributed plugins
863 $pluginman = core_plugin_manager::instance();
864 foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) {
865 foreach ($plugintypeinstances as $pluginname => $plugininfo) {
866 $pluginavailableupdates = $plugininfo->available_updates();
867 if (!empty($pluginavailableupdates)) {
868 foreach ($pluginavailableupdates as $pluginavailableupdate) {
869 if (!isset($availableupdates[$plugintype.'_'.$pluginname])) {
870 $availableupdates[$plugintype.'_'.$pluginname] = array();
872 $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate;
878 // The timestamp of the most recent check for available updates
879 $availableupdatesfetch = $updateschecker->get_last_timefetched();
882 $buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€');
883 //check if the site is registered on Moodle.org
884 $registered = \core\hub\registration::is_registered();
885 // Check if there are any cache warnings.
886 $cachewarnings = cache_helper::warnings();
887 // Check if there are events 1 API handlers.
888 $eventshandlers = $DB->get_records_sql('SELECT DISTINCT component FROM {events_handlers}');
889 $themedesignermode = !empty($CFG->themedesignermode);
890 $mobileconfigured = !empty($CFG->enablemobilewebservice);
891 $invalidforgottenpasswordurl = !empty($CFG->forgottenpasswordurl) && empty(clean_param($CFG->forgottenpasswordurl, PARAM_URL));
893 // Check if a directory with development libraries exists.
894 if (empty($CFG->disabledevlibdirscheck) && (is_dir($CFG->dirroot.'/vendor') || is_dir($CFG->dirroot.'/node_modules'))) {
895 $devlibdir = true;
896 } else {
897 $devlibdir = false;
899 // Check if the site is being foced onto ssl.
900 $overridetossl = !empty($CFG->overridetossl);
902 admin_externalpage_setup('adminnotifications');
904 $output = $PAGE->get_renderer('core', 'admin');
906 echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems,
907 $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb,
908 $registered, $cachewarnings, $eventshandlers, $themedesignermode, $devlibdir,
909 $mobileconfigured, $overridetossl, $invalidforgottenpasswordurl, $croninfrequent);