3 // This file is part of Moodle - http://moodle.org/
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.
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/>.
19 * Main administration script.
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');
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.';
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.';
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.';
56 // Make sure mbstring extension is available.
57 if (!extension_loaded('mbstring')) {
58 echo 'Moodle requires the mbstring PHP extension. Please install or enable the mbstring extension.';
62 define('NO_OUTPUT_BUFFERING', true);
64 if (isset($_POST['upgradekey'])) {
65 // Before you start reporting issues about the collision attacks against
66 // SHA-1, you should understand that we are not actually attempting to do
67 // any cryptography here. This is hashed purely so that the key is not
68 // that apparent in the address bar itself. Anyone who catches the HTTP
69 // traffic can immediately use it as a valid admin key.
70 header('Location: index.php?cache=0&upgradekeyhash='.sha1($_POST['upgradekey']));
74 if ((isset($_GET['cache']) and $_GET['cache'] === '0')
75 or (isset($_POST['cache']) and $_POST['cache'] === '0')
76 or (!isset($_POST['cache']) and !isset($_GET['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey']))) {
77 // Prevent caching at all cost when visiting this page directly,
78 // we redirect to self once we known no upgrades are necessary.
79 // Note: $_GET and $_POST are used here intentionally because our param cleaning is not loaded yet.
80 // Note2: the sesskey is present in all block editing hacks, we can not redirect there, so enable caching.
81 define('CACHE_DISABLE_ALL', true);
83 // Force OPcache reset if used, we do not want any stale caches
84 // when detecting if upgrade necessary or when running upgrade.
85 if (function_exists('opcache_reset')) {
94 require('../config.php');
96 // Invalidate the cache of version.php in any circumstances to help core_component
97 // detecting if the version has changed and component cache should be reset.
98 if (function_exists('opcache_invalidate')) {
99 opcache_invalidate($CFG->dirroot
. '/version.php', true);
101 // Make sure the component cache gets rebuilt if necessary, any method that
102 // indirectly calls the protected init() method is good here.
103 core_component
::get_core_subsystems();
105 if (is_major_upgrade_required() && isloggedin()) {
106 // A major upgrade is required.
107 // Terminate the session and redirect back here before anything DB-related happens.
108 redirect_if_major_upgrade_required();
111 require_once($CFG->libdir
.'/adminlib.php'); // various admin-only functions
112 require_once($CFG->libdir
.'/upgradelib.php'); // general upgrade/install related functions
114 $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL
); // Core upgrade confirmed?
115 $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL
); // Core release info and server checks confirmed?
116 $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL
); // Plugins check page confirmed?
117 $showallplugins = optional_param('showallplugins', 0, PARAM_BOOL
); // Show all plugins on the plugins check page?
118 $agreelicense = optional_param('agreelicense', 0, PARAM_BOOL
); // GPL license confirmed for installation?
119 $fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL
); // Should check for available updates?
120 $newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW
); // Plugin installation requested at moodle.org/plugins.
121 $upgradekeyhash = optional_param('upgradekeyhash', null, PARAM_ALPHANUM
); // Hash of provided upgrade key.
122 $installdep = optional_param('installdep', null, PARAM_COMPONENT
); // Install given missing dependency (required plugin).
123 $installdepx = optional_param('installdepx', false, PARAM_BOOL
); // Install all missing dependencies.
124 $confirminstalldep = optional_param('confirminstalldep', false, PARAM_BOOL
); // Installing dependencies confirmed.
125 $abortinstall = optional_param('abortinstall', null, PARAM_COMPONENT
); // Cancel installation of the given new plugin.
126 $abortinstallx = optional_param('abortinstallx', null, PARAM_BOOL
); // Cancel installation of all new plugins.
127 $confirmabortinstall = optional_param('confirmabortinstall', false, PARAM_BOOL
); // Installation cancel confirmed.
128 $abortupgrade = optional_param('abortupgrade', null, PARAM_COMPONENT
); // Cancel upgrade of the given existing plugin.
129 $abortupgradex = optional_param('abortupgradex', null, PARAM_BOOL
); // Cancel upgrade of all upgradable plugins.
130 $confirmabortupgrade = optional_param('confirmabortupgrade', false, PARAM_BOOL
); // Upgrade cancel confirmed.
131 $installupdate = optional_param('installupdate', null, PARAM_COMPONENT
); // Install given available update.
132 $installupdateversion = optional_param('installupdateversion', null, PARAM_INT
); // Version of the available update to install.
133 $installupdatex = optional_param('installupdatex', false, PARAM_BOOL
); // Install all available plugin updates.
134 $confirminstallupdate = optional_param('confirminstallupdate', false, PARAM_BOOL
); // Available update(s) install confirmed?
136 if (!empty($CFG->disableupdateautodeploy
)) {
137 // Invalidate all requests to install plugins via the admin UI.
140 $installdepx = false;
141 $abortupgrade = null;
142 $abortupgradex = null;
143 $installupdate = null;
144 $installupdateversion = null;
145 $installupdatex = false;
149 $url = new moodle_url('/admin/index.php');
150 $url->param('cache', $cache);
151 if (isset($upgradekeyhash)) {
152 $url->param('upgradekeyhash', $upgradekeyhash);
154 $PAGE->set_url($url);
157 // Are we returning from an add-on installation request at moodle.org/plugins?
158 if ($newaddonreq and !$cache and empty($CFG->disableupdateautodeploy
)) {
159 $target = new moodle_url('/admin/tool/installaddon/index.php', array(
160 'installaddonrequest' => $newaddonreq,
162 if (!isloggedin() or isguestuser()) {
163 // Login and go the the add-on tool page.
164 $SESSION->wantsurl
= $target->out();
165 redirect(get_login_url());
170 $PAGE->set_pagelayout('admin'); // Set a default pagelayout
172 $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
174 // Check some PHP server settings
176 if (ini_get_bool('session.auto_start')) {
177 throw new \
moodle_exception('phpvaroff', 'debug', '',
178 (object)array('name' => 'session.auto_start', 'link' => $documentationlink));
181 if (!ini_get_bool('file_uploads')) {
182 throw new \
moodle_exception('phpvaron', 'debug', '',
183 (object)array('name' => 'file_uploads', 'link' => $documentationlink));
186 if (is_float_problem()) {
187 throw new \
moodle_exception('phpfloatproblem', 'admin', '', $documentationlink);
190 // Set some necessary variables during set-up to avoid PHP warnings later on this page
191 if (!isset($CFG->release
)) {
194 if (!isset($CFG->version
)) {
197 if (!isset($CFG->branch
)) {
204 require("$CFG->dirroot/version.php"); // defines $version, $release, $branch and $maturity
205 $CFG->target_release
= $release; // used during installation and upgrades
207 if (!$version or !$release) {
208 throw new \
moodle_exception('withoutversion', 'debug'); // Without version, stop.
211 if (!core_tables_exist()) {
212 $PAGE->set_pagelayout('maintenance');
213 $PAGE->set_popup_notification_allowed(false);
215 // fake some settings
216 $CFG->docroot
= 'http://docs.moodle.org';
218 $strinstallation = get_string('installation', 'install');
220 // remove current session content completely
221 \core\session\manager
::terminate_current();
223 if (empty($agreelicense)) {
224 $strlicense = get_string('license');
226 $PAGE->navbar
->add($strlicense);
227 $PAGE->set_title($strinstallation . moodle_page
::TITLE_SEPARATOR
. 'Moodle ' . $CFG->target_release
, false);
228 $PAGE->set_heading($strinstallation);
229 $PAGE->set_cacheable(false);
231 $output = $PAGE->get_renderer('core', 'admin');
232 echo $output->install_licence_page();
235 if (empty($confirmrelease)) {
236 require_once($CFG->libdir
.'/environmentlib.php');
237 list($envstatus, $environmentresults) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE
);
238 $strcurrentrelease = get_string('currentrelease');
240 $PAGE->navbar
->add($strcurrentrelease);
241 $PAGE->set_title($strinstallation);
242 $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release
);
243 $PAGE->set_cacheable(false);
245 $output = $PAGE->get_renderer('core', 'admin');
246 echo $output->install_environment_page($maturity, $envstatus, $environmentresults, $release);
250 // check plugin dependencies
252 if (!core_plugin_manager
::instance()->all_plugins_ok($version, $failed, $CFG->branch
)) {
253 $PAGE->navbar
->add(get_string('pluginscheck', 'admin'));
254 $PAGE->set_title($strinstallation);
255 $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release
);
257 $output = $PAGE->get_renderer('core', 'admin');
258 $url = new moodle_url($PAGE->url
, array('agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang
));
259 echo $output->unsatisfied_dependencies_page($version, $failed, $url);
264 //TODO: add a page with list of non-standard plugins here
266 $strdatabasesetup = get_string('databasesetup');
267 upgrade_init_javascript();
269 $PAGE->navbar
->add($strdatabasesetup);
270 $PAGE->set_title($strinstallation . moodle_page
::TITLE_SEPARATOR
. $CFG->target_release
, false);
271 $PAGE->set_heading($strinstallation);
272 $PAGE->set_cacheable(false);
274 $output = $PAGE->get_renderer('core', 'admin');
275 echo $output->header();
277 if (!$DB->setup_is_unicodedb()) {
278 if (!$DB->change_db_encoding()) {
279 // If could not convert successfully, throw error, and prevent installation
280 throw new \
moodle_exception('unicoderequired', 'admin');
284 install_core($version, true);
288 // Check version of Moodle code on disk compared with database
289 // and upgrade if possible.
292 // Do not try to do anything fancy in non-cached mode,
293 // this prevents themes from fetching data from non-existent tables.
294 $PAGE->set_pagelayout('maintenance');
295 $PAGE->set_popup_notification_allowed(false);
298 $stradministration = get_string('administration');
299 $PAGE->set_context(context_system
::instance());
301 if (empty($CFG->version
)) {
302 throw new \
moodle_exception('missingconfigversion', 'debug');
305 // If an upgrade is running, an admin page starting a frontend upgrade could corrupt the
306 // DB if the upgrade collided with an already running upgrade process at the wrong time.
307 // Pull the value direct from the DB, this needs to *always* be correct.
308 $outagelessupgrade = !empty($DB->get_field('config', 'value', ['name' => 'outagelessupgrade']));
309 if (!$outagelessupgrade) {
310 // Detect config cache inconsistency, this happens when you switch branches on dev servers.
311 if ($CFG->version
!= $DB->get_field('config', 'value', array('name' => 'version'))) {
313 redirect(new moodle_url($PAGE->url
), 'Config cache inconsistency detected, resetting caches...');
316 if (!$cache && $version > $CFG->version
&& !$outagelessupgrade) { // Upgrade.
318 $PAGE->set_url(new moodle_url($PAGE->url
, array(
319 'confirmupgrade' => $confirmupgrade,
320 'confirmrelease' => $confirmrelease,
321 'confirmplugincheck' => $confirmplugins,
324 check_upgrade_key($upgradekeyhash);
326 // Warning about upgrading a test site.
328 if (defined('BEHAT_SITE_RUNNING')) {
332 if (isset($CFG->themerev
)) {
333 // Store the themerev to restore after purging caches.
334 $themerev = $CFG->themerev
;
337 // We purge all of MUC's caches here.
338 // Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true.
339 // This ensures a real config object is loaded and the stores will be purged.
340 // This is the only way we can purge custom caches such as memcache or APC.
341 // Note: all other calls to caches will still used the disabled API.
342 cache_helper
::purge_all(true);
343 // We then purge the regular caches.
346 if (isset($themerev)) {
347 // Restore the themerev.
348 set_config('themerev', $themerev);
351 $output = $PAGE->get_renderer('core', 'admin');
353 if (upgrade_stale_php_files_present()) {
354 $PAGE->set_title($stradministration);
355 $PAGE->set_cacheable(false);
357 echo $output->upgrade_stale_php_files_page();
361 if (empty($confirmupgrade)) {
363 $a->oldversion
= "$CFG->release (".sprintf('%.2f', $CFG->version
).")";
364 $a->newversion
= "$release (".sprintf('%.2f', $version).")";
365 $strdatabasechecking = get_string('databasechecking', '', $a);
367 $PAGE->set_title($stradministration);
368 $PAGE->set_heading($strdatabasechecking);
369 $PAGE->set_cacheable(false);
371 echo $output->upgrade_confirm_page($a->newversion
, $maturity, $testsite);
374 } else if (empty($confirmrelease)) {
375 require_once($CFG->libdir
.'/environmentlib.php');
376 list($envstatus, $environmentresults) = check_moodle_environment($release, ENV_SELECT_RELEASE
);
377 $strcurrentrelease = get_string('currentrelease');
379 $PAGE->navbar
->add($strcurrentrelease);
380 $PAGE->set_title($strcurrentrelease);
381 $PAGE->set_heading($strcurrentrelease);
382 $PAGE->set_cacheable(false);
384 echo $output->upgrade_environment_page($release, $envstatus, $environmentresults);
387 } else if (empty($confirmplugins)) {
388 $strplugincheck = get_string('plugincheck');
390 $PAGE->navbar
->add($strplugincheck);
391 $PAGE->set_title($strplugincheck);
392 $PAGE->set_heading($strplugincheck);
393 $PAGE->set_cacheable(false);
395 $pluginman = core_plugin_manager
::instance();
397 // Check for available updates.
399 // No sesskey support guaranteed here, because sessions might not work yet.
400 $updateschecker = \core\update\checker
::instance();
401 if ($updateschecker->enabled()) {
402 $updateschecker->fetch();
404 redirect($PAGE->url
);
407 // Cancel all plugin installations.
408 if ($abortinstallx) {
409 // No sesskey support guaranteed here, because sessions might not work yet.
410 $abortables = $pluginman->list_cancellable_installations();
412 if ($confirmabortinstall) {
413 foreach ($abortables as $plugin) {
414 $pluginman->cancel_plugin_installation($plugin->component
);
416 redirect($PAGE->url
);
418 $continue = new moodle_url($PAGE->url
, ['abortinstallx' => $abortinstallx, 'confirmabortinstall' => 1]);
419 echo $output->upgrade_confirm_abort_install_page($abortables, $continue);
423 redirect($PAGE->url
);
426 // Cancel single plugin installation.
428 // No sesskey support guaranteed here, because sessions might not work yet.
429 if ($confirmabortinstall) {
430 $pluginman->cancel_plugin_installation($abortinstall);
431 redirect($PAGE->url
);
433 $continue = new moodle_url($PAGE->url
, array('abortinstall' => $abortinstall, 'confirmabortinstall' => 1));
434 $abortable = $pluginman->get_plugin_info($abortinstall);
435 if ($pluginman->can_cancel_plugin_installation($abortable)) {
436 echo $output->upgrade_confirm_abort_install_page(array($abortable), $continue);
439 redirect($PAGE->url
);
443 // Cancel all plugins upgrades (that is, restore archived versions).
444 if ($abortupgradex) {
445 // No sesskey support guaranteed here, because sessions might not work yet.
446 $restorable = $pluginman->list_restorable_archives();
448 upgrade_install_plugins($restorable, $confirmabortupgrade,
449 get_string('cancelupgradehead', 'core_plugin'),
450 new moodle_url($PAGE->url
, array('abortupgradex' => 1, 'confirmabortupgrade' => 1))
453 redirect($PAGE->url
);
456 // Cancel single plugin upgrade (that is, install the archived version).
458 // No sesskey support guaranteed here, because sessions might not work yet.
459 $restorable = $pluginman->list_restorable_archives();
460 if (isset($restorable[$abortupgrade])) {
461 $restorable = array($restorable[$abortupgrade]);
462 upgrade_install_plugins($restorable, $confirmabortupgrade,
463 get_string('cancelupgradehead', 'core_plugin'),
464 new moodle_url($PAGE->url
, array('abortupgrade' => $abortupgrade, 'confirmabortupgrade' => 1))
467 redirect($PAGE->url
);
470 // Install all available missing dependencies.
472 // No sesskey support guaranteed here, because sessions might not work yet.
473 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
474 upgrade_install_plugins($installable, $confirminstalldep,
475 get_string('dependencyinstallhead', 'core_plugin'),
476 new moodle_url($PAGE->url
, array('installdepx' => 1, 'confirminstalldep' => 1))
480 // Install single available missing dependency.
482 // No sesskey support guaranteed here, because sessions might not work yet.
483 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
484 if (!empty($installable[$installdep])) {
485 $installable = array($installable[$installdep]);
486 upgrade_install_plugins($installable, $confirminstalldep,
487 get_string('dependencyinstallhead', 'core_plugin'),
488 new moodle_url($PAGE->url
, array('installdep' => $installdep, 'confirminstalldep' => 1))
493 // Install all available updates.
494 if ($installupdatex) {
495 // No sesskey support guaranteed here, because sessions might not work yet.
496 $installable = $pluginman->filter_installable($pluginman->available_updates());
497 upgrade_install_plugins($installable, $confirminstallupdate,
498 get_string('updateavailableinstallallhead', 'core_admin'),
499 new moodle_url($PAGE->url
, array('installupdatex' => 1, 'confirminstallupdate' => 1))
503 // Install single available update.
504 if ($installupdate and $installupdateversion) {
505 // No sesskey support guaranteed here, because sessions might not work yet.
506 if ($pluginman->is_remote_plugin_installable($installupdate, $installupdateversion)) {
507 $installable = array($pluginman->get_remote_plugin_info($installupdate, $installupdateversion, true));
508 upgrade_install_plugins($installable, $confirminstallupdate,
509 get_string('updateavailableinstallallhead', 'core_admin'),
510 new moodle_url($PAGE->url
, array('installupdate' => $installupdate,
511 'installupdateversion' => $installupdateversion, 'confirminstallupdate' => 1)
517 echo $output->upgrade_plugin_check_page(core_plugin_manager
::instance(), \core\update\checker
::instance(),
518 $version, $showallplugins, $PAGE->url
, new moodle_url($PAGE->url
, array('confirmplugincheck' => 1)));
522 // Always verify plugin dependencies!
524 if (!core_plugin_manager
::instance()->all_plugins_ok($version, $failed, $CFG->branch
)) {
525 echo $output->unsatisfied_dependencies_page($version, $failed, new moodle_url($PAGE->url
,
526 array('confirmplugincheck' => 0)));
531 // Launch main upgrade.
532 upgrade_core($version, true);
534 } else if ($version < $CFG->version
) {
535 // Better stop here, we can not continue with plugin upgrades or anything else.
536 throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/'));
539 // Updated human-readable release version if necessary.
540 if (!$cache && $release <> $CFG->release
) { // Update the release version.
541 set_config('release', $release);
544 if (!$cache && $branch <> $CFG->branch
) { // Update the branch.
545 set_config('branch', $branch);
548 if (!$cache && moodle_needs_upgrading()) {
550 $PAGE->set_url(new moodle_url($PAGE->url
, array(
551 'confirmrelease' => $confirmrelease,
552 'confirmplugincheck' => $confirmplugins,
555 check_upgrade_key($upgradekeyhash);
557 if (!$PAGE->headerprinted
) {
558 // Means core upgrade or installation was not already done.
560 $pluginman = core_plugin_manager
::instance();
561 $output = $PAGE->get_renderer('core', 'admin');
563 if (empty($confirmrelease)) {
564 require_once($CFG->libdir
. '/environmentlib.php');
566 list($envstatus, $environmentresults) = check_moodle_environment($release, ENV_SELECT_RELEASE
);
567 $strcurrentrelease = get_string('currentrelease');
569 $PAGE->navbar
->add($strcurrentrelease);
570 $PAGE->set_title($strcurrentrelease);
571 $PAGE->set_heading($strcurrentrelease);
572 $PAGE->set_cacheable(false);
574 echo $output->upgrade_environment_page($release, $envstatus, $environmentresults);
577 } else if (!$confirmplugins) {
578 $strplugincheck = get_string('plugincheck');
580 $PAGE->navbar
->add($strplugincheck);
581 $PAGE->set_title($strplugincheck);
582 $PAGE->set_heading($strplugincheck);
583 $PAGE->set_cacheable(false);
585 // Check for available updates.
588 $updateschecker = \core\update\checker
::instance();
589 if ($updateschecker->enabled()) {
590 $updateschecker->fetch();
592 redirect($PAGE->url
);
595 // Cancel all plugin installations.
596 if ($abortinstallx) {
598 $abortables = $pluginman->list_cancellable_installations();
600 if ($confirmabortinstall) {
601 foreach ($abortables as $plugin) {
602 $pluginman->cancel_plugin_installation($plugin->component
);
604 redirect($PAGE->url
);
606 $continue = new moodle_url($PAGE->url
, array('abortinstallx' => $abortinstallx,
607 'confirmabortinstall' => 1));
608 echo $output->upgrade_confirm_abort_install_page($abortables, $continue);
612 redirect($PAGE->url
);
615 // Cancel single plugin installation.
618 if ($confirmabortinstall) {
619 $pluginman->cancel_plugin_installation($abortinstall);
620 redirect($PAGE->url
);
622 $continue = new moodle_url($PAGE->url
, array('abortinstall' => $abortinstall, 'confirmabortinstall' => 1));
623 $abortable = $pluginman->get_plugin_info($abortinstall);
624 if ($pluginman->can_cancel_plugin_installation($abortable)) {
625 echo $output->upgrade_confirm_abort_install_page(array($abortable), $continue);
628 redirect($PAGE->url
);
632 // Cancel all plugins upgrades (that is, restore archived versions).
633 if ($abortupgradex) {
635 $restorable = $pluginman->list_restorable_archives();
637 upgrade_install_plugins($restorable, $confirmabortupgrade,
638 get_string('cancelupgradehead', 'core_plugin'),
639 new moodle_url($PAGE->url
, array('abortupgradex' => 1, 'confirmabortupgrade' => 1))
642 redirect($PAGE->url
);
645 // Cancel single plugin upgrade (that is, install the archived version).
648 $restorable = $pluginman->list_restorable_archives();
649 if (isset($restorable[$abortupgrade])) {
650 $restorable = array($restorable[$abortupgrade]);
651 upgrade_install_plugins($restorable, $confirmabortupgrade,
652 get_string('cancelupgradehead', 'core_plugin'),
653 new moodle_url($PAGE->url
, array('abortupgrade' => $abortupgrade, 'confirmabortupgrade' => 1))
656 redirect($PAGE->url
);
659 // Install all available missing dependencies.
662 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
663 upgrade_install_plugins($installable, $confirminstalldep,
664 get_string('dependencyinstallhead', 'core_plugin'),
665 new moodle_url($PAGE->url
, array('installdepx' => 1, 'confirminstalldep' => 1))
669 // Install single available missing dependency.
672 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
673 if (!empty($installable[$installdep])) {
674 $installable = array($installable[$installdep]);
675 upgrade_install_plugins($installable, $confirminstalldep,
676 get_string('dependencyinstallhead', 'core_plugin'),
677 new moodle_url($PAGE->url
, array('installdep' => $installdep, 'confirminstalldep' => 1))
682 // Install all available updates.
683 if ($installupdatex) {
685 $installable = $pluginman->filter_installable($pluginman->available_updates());
686 upgrade_install_plugins($installable, $confirminstallupdate,
687 get_string('updateavailableinstallallhead', 'core_admin'),
688 new moodle_url($PAGE->url
, array('installupdatex' => 1, 'confirminstallupdate' => 1))
692 // Install single available update.
693 if ($installupdate && $installupdateversion) {
695 if ($pluginman->is_remote_plugin_installable($installupdate, $installupdateversion)) {
696 $installable = array($pluginman->get_remote_plugin_info($installupdate, $installupdateversion, true));
697 upgrade_install_plugins($installable, $confirminstallupdate,
698 get_string('updateavailableinstallallhead', 'core_admin'),
699 new moodle_url($PAGE->url
, array('installupdate' => $installupdate,
700 'installupdateversion' => $installupdateversion, 'confirminstallupdate' => 1)
706 // Show plugins info.
707 echo $output->upgrade_plugin_check_page($pluginman, \core\update\checker
::instance(),
708 $version, $showallplugins,
709 new moodle_url($PAGE->url
),
710 new moodle_url($PAGE->url
, array('confirmplugincheck' => 1, 'cache' => 0)));
714 // Make sure plugin dependencies are always checked.
716 if (!$pluginman->all_plugins_ok($version, $failed, $CFG->branch
)) {
717 $output = $PAGE->get_renderer('core', 'admin');
718 echo $output->unsatisfied_dependencies_page($version, $failed, new moodle_url($PAGE->url
,
719 array('confirmplugincheck' => 0)));
725 // Install/upgrade all plugins and other parts.
726 upgrade_noncore(true);
729 // If this is the first install, indicate that this site is fully configured,
730 // Except the admin password.
731 if (during_initial_install()) {
732 set_config('rolesactive', 1); // After this, during_initial_install will return false.
733 set_config('adminsetuppending', 1);
734 set_config('registrationpending', 1); // Remind to register site after all other setup is finished.
736 // Apply default preset, if it is defined in $CFG and has a valid value.
737 if (!empty($CFG->setsitepresetduringinstall
)) {
738 \core_adminpresets\helper
::change_default_preset($CFG->setsitepresetduringinstall
);
741 // We need this redirect to setup proper session.
742 upgrade_finished("index.php?sessionstarted=1&lang=$CFG->lang");
745 // Make sure admin user is created - this is the last step,
746 // We need session to be working properly in order to edit admin account.
747 if (!empty($CFG->adminsetuppending
)) {
748 $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL
);
749 if (!$sessionstarted) {
750 redirect("index.php?sessionstarted=1&lang=$CFG->lang");
752 $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL
);
753 if (!$sessionverify) {
754 $SESSION->sessionverify
= 1;
755 redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
757 if (empty($SESSION->sessionverify
)) {
758 throw new \
moodle_exception('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
760 unset($SESSION->sessionverify
);
764 // Cleanup SESSION to make sure other code does not complain in the future.
765 unset($SESSION->has_timed_out
);
766 unset($SESSION->wantsurl
);
768 // At this stage there can be only one admin unless more were added by install,
769 // Users may change username, so do not rely on that.
770 $adminids = explode(',', $CFG->siteadmins
);
771 $adminuser = get_complete_user_data('id', reset($adminids));
773 if ($adminuser->password
=== 'adminsetuppending') {
774 // Prevent installation hijacking.
775 if ($adminuser->lastip
!== getremoteaddr()) {
776 throw new \
moodle_exception('installhijacked', 'admin');
778 // Login user and let him set password and admin details.
779 $adminuser->newadminuser
= 1;
780 complete_user_login($adminuser);
781 redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself.
784 unset_config('adminsetuppending');
788 // Just make sure upgrade logging is properly terminated.
789 upgrade_finished('upgradesettings.php');
793 if (has_capability('moodle/site:config', context_system
::instance())) {
796 $updateschecker = \core\update\checker
::instance();
797 if ($updateschecker->enabled()) {
798 $updateschecker->fetch();
800 redirect(new moodle_url('/admin/index.php', array('cache' => 0)));
804 // Now we can be sure everything was upgraded and caches work fine,
805 // redirect if necessary to make sure caching is enabled.
807 redirect(new moodle_url('/admin/index.php', array('cache' => 1)));
810 // Check for valid admin user - no guest autologin
811 require_login(0, false);
813 // Login as real user!
814 $SESSION->wantsurl
= (string)new moodle_url('/admin/index.php');
815 redirect(get_login_url());
817 $context = context_system
::instance();
819 if (!has_capability('moodle/site:config', $context)) {
820 // Do not throw exception display an empty page with administration menu if visible for current user.
821 $PAGE->set_title(get_string('home'));
822 $PAGE->set_heading($SITE->fullname
);
823 echo $OUTPUT->header();
824 echo $OUTPUT->footer();
828 // check that site is properly customized
830 if (empty($site->shortname
)) {
831 // probably new installation - lets return to frontpage after this step
832 // remove settings that we want uninitialised
833 unset_config('registerauth');
834 unset_config('timezone'); // Force admin to select timezone!
835 redirect('upgradesettings.php?return=site');
838 // setup critical warnings before printing admin tree block
839 $insecuredataroot = is_dataroot_insecure(true);
840 $SESSION->admin_critical_warning
= ($insecuredataroot==INSECURE_DATAROOT_ERROR
);
842 $adminroot = admin_get_root();
843 $PAGE->set_primary_active_tab('siteadminnode');
845 // Check if there are any new admin settings which have still yet to be set
846 if (any_new_admin_settings($adminroot)) {
847 redirect('upgradesettings.php');
850 // Return to original page that started the plugin uninstallation if necessary.
851 if (isset($SESSION->pluginuninstallreturn
)) {
852 $return = $SESSION->pluginuninstallreturn
;
853 unset($SESSION->pluginuninstallreturn
);
859 // If site registration needs updating, redirect.
860 \core\hub\registration
::registration_reminder('/admin/index.php');
862 // Everything should now be set up, and the user is an admin
864 // Print default admin page with notifications.
865 $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED');
867 $lastcron = get_config('tool_task', 'lastcronstart');
868 $cronoverdue = ($lastcron < time() - 3600 * 24);
869 $lastcroninterval = get_config('tool_task', 'lastcroninterval');
871 $expectedfrequency = $CFG->expectedcronfrequency ?? MINSECS
;
872 $croninfrequent = !$cronoverdue && ($lastcroninterval > ($expectedfrequency + MINSECS
) ||
$lastcron < time() - $expectedfrequency);
873 $dbproblems = $DB->diagnose();
874 $maintenancemode = !empty($CFG->maintenance_enabled
);
876 // Available updates for Moodle core.
877 $updateschecker = \core\update\checker
::instance();
878 $availableupdates = array();
879 $availableupdatesfetch = null;
881 if ($updateschecker->enabled()) {
882 // Only compute the update information when it is going to be displayed to the user.
883 $availableupdates['core'] = $updateschecker->get_update_info('core',
884 array('minmaturity' => $CFG->updateminmaturity
, 'notifybuilds' => $CFG->updatenotifybuilds
));
886 // Available updates for contributed plugins
887 $pluginman = core_plugin_manager
::instance();
888 foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) {
889 foreach ($plugintypeinstances as $pluginname => $plugininfo) {
890 $pluginavailableupdates = $plugininfo->available_updates();
891 if (!empty($pluginavailableupdates)) {
892 foreach ($pluginavailableupdates as $pluginavailableupdate) {
893 if (!isset($availableupdates[$plugintype.'_'.$pluginname])) {
894 $availableupdates[$plugintype.'_'.$pluginname] = array();
896 $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate;
902 // The timestamp of the most recent check for available updates
903 $availableupdatesfetch = $updateschecker->get_last_timefetched();
906 $buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv
('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€');
907 //check if the site is registered on Moodle.org
908 $registered = \core\hub\registration
::is_registered();
909 // Check if there are any cache warnings.
910 $cachewarnings = cache_helper
::warnings();
911 // Check if there are events 1 API handlers.
912 $eventshandlers = $DB->get_records_sql('SELECT DISTINCT component FROM {events_handlers}');
913 $themedesignermode = !empty($CFG->themedesignermode
);
914 $mobileconfigured = !empty($CFG->enablemobilewebservice
);
915 $invalidforgottenpasswordurl = !empty($CFG->forgottenpasswordurl
) && empty(clean_param($CFG->forgottenpasswordurl
, PARAM_URL
));
917 // Check if a directory with development libraries exists.
918 if (empty($CFG->disabledevlibdirscheck
) && (is_dir($CFG->dirroot
.'/vendor') ||
is_dir($CFG->dirroot
.'/node_modules'))) {
923 // Check if the site is being foced onto ssl.
924 $overridetossl = !empty($CFG->overridetossl
);
926 // Check if moodle campaign content setting is enabled or not.
927 $showcampaigncontent = !isset($CFG->showcampaigncontent
) ||
$CFG->showcampaigncontent
;
929 // Encourage admins to enable the user feedback feature if it is not enabled already.
930 $showfeedbackencouragement = empty($CFG->enableuserfeedback
);
932 // Check if the service and support content setting is enabled or not.
933 $servicesandsupportcontent = !isset($CFG->showservicesandsupportcontent
) ||
$CFG->showservicesandsupportcontent
;
935 // Check whether the XML-RPC protocol is enabled or not.
936 require_once($CFG->libdir
. '/environmentlib.php');
937 $result = new environment_results('custom_checks');
938 $result = check_xmlrpc_usage($result);
939 $xmlrpcwarning = !is_null($result) ?
get_string($result->getFeedbackStr(), 'admin') : '';
941 admin_externalpage_setup('adminnotifications');
943 $output = $PAGE->get_renderer('core', 'admin');
945 echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems,
946 $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb,
947 $registered, $cachewarnings, $eventshandlers, $themedesignermode, $devlibdir,
948 $mobileconfigured, $overridetossl, $invalidforgottenpasswordurl, $croninfrequent,
949 $showcampaigncontent, $showfeedbackencouragement, $servicesandsupportcontent,