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 if (version_compare(phpversion(), '5.6.5') < 0) {
34 $phpversion = phpversion();
35 // do NOT localise - lang strings would not work here and we CAN NOT move it to later place
36 echo "Moodle 3.2 or later requires at least PHP 5.6.5 (currently using version $phpversion).<br />";
37 echo "Please upgrade your server software or install older Moodle version.";
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
44 echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.';
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.';
55 // Make sure xml extension is available.
56 if (!extension_loaded('xml')) {
57 echo 'Moodle requires the xml PHP extension. Please install or enable the xml extension.';
61 define('NO_OUTPUT_BUFFERING', true);
63 if (isset($_POST['upgradekey'])) {
64 // Before you start reporting issues about the collision attacks against
65 // SHA-1, you should understand that we are not actually attempting to do
66 // any cryptography here. This is hashed purely so that the key is not
67 // that apparent in the address bar itself. Anyone who catches the HTTP
68 // traffic can immediately use it as a valid admin key.
69 header('Location: index.php?cache=0&upgradekeyhash='.sha1($_POST['upgradekey']));
73 if ((isset($_GET['cache']) and $_GET['cache'] === '0')
74 or (isset($_POST['cache']) and $_POST['cache'] === '0')
75 or (!isset($_POST['cache']) and !isset($_GET['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey']))) {
76 // Prevent caching at all cost when visiting this page directly,
77 // we redirect to self once we known no upgrades are necessary.
78 // Note: $_GET and $_POST are used here intentionally because our param cleaning is not loaded yet.
79 // Note2: the sesskey is present in all block editing hacks, we can not redirect there, so enable caching.
80 define('CACHE_DISABLE_ALL', true);
82 // Force OPcache reset if used, we do not want any stale caches
83 // when detecting if upgrade necessary or when running upgrade.
84 if (function_exists('opcache_reset')) {
93 require('../config.php');
95 // Invalidate the cache of version.php in any circumstances to help core_component
96 // detecting if the version has changed and component cache should be reset.
97 if (function_exists('opcache_invalidate')) {
98 opcache_invalidate($CFG->dirroot
. '/version.php', true);
100 // Make sure the component cache gets rebuilt if necessary, any method that
101 // indirectly calls the protected init() method is good here.
102 core_component
::get_core_subsystems();
104 require_once($CFG->libdir
.'/adminlib.php'); // various admin-only functions
105 require_once($CFG->libdir
.'/upgradelib.php'); // general upgrade/install related functions
107 $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL
); // Core upgrade confirmed?
108 $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL
); // Core release info and server checks confirmed?
109 $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL
); // Plugins check page confirmed?
110 $showallplugins = optional_param('showallplugins', 0, PARAM_BOOL
); // Show all plugins on the plugins check page?
111 $agreelicense = optional_param('agreelicense', 0, PARAM_BOOL
); // GPL license confirmed for installation?
112 $fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL
); // Should check for available updates?
113 $newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW
); // Plugin installation requested at moodle.org/plugins.
114 $upgradekeyhash = optional_param('upgradekeyhash', null, PARAM_ALPHANUM
); // Hash of provided upgrade key.
115 $installdep = optional_param('installdep', null, PARAM_COMPONENT
); // Install given missing dependency (required plugin).
116 $installdepx = optional_param('installdepx', false, PARAM_BOOL
); // Install all missing dependencies.
117 $confirminstalldep = optional_param('confirminstalldep', false, PARAM_BOOL
); // Installing dependencies confirmed.
118 $abortinstall = optional_param('abortinstall', null, PARAM_COMPONENT
); // Cancel installation of the given new plugin.
119 $abortinstallx = optional_param('abortinstallx', null, PARAM_BOOL
); // Cancel installation of all new plugins.
120 $confirmabortinstall = optional_param('confirmabortinstall', false, PARAM_BOOL
); // Installation cancel confirmed.
121 $abortupgrade = optional_param('abortupgrade', null, PARAM_COMPONENT
); // Cancel upgrade of the given existing plugin.
122 $abortupgradex = optional_param('abortupgradex', null, PARAM_BOOL
); // Cancel upgrade of all upgradable plugins.
123 $confirmabortupgrade = optional_param('confirmabortupgrade', false, PARAM_BOOL
); // Upgrade cancel confirmed.
124 $installupdate = optional_param('installupdate', null, PARAM_COMPONENT
); // Install given available update.
125 $installupdateversion = optional_param('installupdateversion', null, PARAM_INT
); // Version of the available update to install.
126 $installupdatex = optional_param('installupdatex', false, PARAM_BOOL
); // Install all available plugin updates.
127 $confirminstallupdate = optional_param('confirminstallupdate', false, PARAM_BOOL
); // Available update(s) install confirmed?
129 if (!empty($CFG->disableupdateautodeploy
)) {
130 // Invalidate all requests to install plugins via the admin UI.
133 $installdepx = false;
134 $abortupgrade = null;
135 $abortupgradex = null;
136 $installupdate = null;
137 $installupdateversion = null;
138 $installupdatex = false;
142 $url = new moodle_url('/admin/index.php');
143 $url->param('cache', $cache);
144 if (isset($upgradekeyhash)) {
145 $url->param('upgradekeyhash', $upgradekeyhash);
147 $PAGE->set_url($url);
150 // Are we returning from an add-on installation request at moodle.org/plugins?
151 if ($newaddonreq and !$cache and empty($CFG->disableupdateautodeploy
)) {
152 $target = new moodle_url('/admin/tool/installaddon/index.php', array(
153 'installaddonrequest' => $newaddonreq,
155 if (!isloggedin() or isguestuser()) {
156 // Login and go the the add-on tool page.
157 $SESSION->wantsurl
= $target->out();
158 redirect(get_login_url());
163 $PAGE->set_pagelayout('admin'); // Set a default pagelayout
165 $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>';
167 // Check some PHP server settings
169 if (ini_get_bool('session.auto_start')) {
170 print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink));
173 if (!ini_get_bool('file_uploads')) {
174 print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink));
177 if (is_float_problem()) {
178 print_error('phpfloatproblem', 'admin', '', $documentationlink);
181 // Set some necessary variables during set-up to avoid PHP warnings later on this page
182 if (!isset($CFG->release
)) {
185 if (!isset($CFG->version
)) {
188 if (!isset($CFG->branch
)) {
195 require("$CFG->dirroot/version.php"); // defines $version, $release, $branch and $maturity
196 $CFG->target_release
= $release; // used during installation and upgrades
198 if (!$version or !$release) {
199 print_error('withoutversion', 'debug'); // without version, stop
202 if (!core_tables_exist()) {
203 $PAGE->set_pagelayout('maintenance');
204 $PAGE->set_popup_notification_allowed(false);
206 // fake some settings
207 $CFG->docroot
= 'http://docs.moodle.org';
209 $strinstallation = get_string('installation', 'install');
211 // remove current session content completely
212 \core\session\manager
::terminate_current();
214 if (empty($agreelicense)) {
215 $strlicense = get_string('license');
217 $PAGE->navbar
->add($strlicense);
218 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release
);
219 $PAGE->set_heading($strinstallation);
220 $PAGE->set_cacheable(false);
222 $output = $PAGE->get_renderer('core', 'admin');
223 echo $output->install_licence_page();
226 if (empty($confirmrelease)) {
227 require_once($CFG->libdir
.'/environmentlib.php');
228 list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE
);
229 $strcurrentrelease = get_string('currentrelease');
231 $PAGE->navbar
->add($strcurrentrelease);
232 $PAGE->set_title($strinstallation);
233 $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release
);
234 $PAGE->set_cacheable(false);
236 $output = $PAGE->get_renderer('core', 'admin');
237 echo $output->install_environment_page($maturity, $envstatus, $environment_results, $release);
241 // check plugin dependencies
243 if (!core_plugin_manager
::instance()->all_plugins_ok($version, $failed)) {
244 $PAGE->navbar
->add(get_string('pluginscheck', 'admin'));
245 $PAGE->set_title($strinstallation);
246 $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release
);
248 $output = $PAGE->get_renderer('core', 'admin');
249 $url = new moodle_url($PAGE->url
, array('agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang
));
250 echo $output->unsatisfied_dependencies_page($version, $failed, $url);
255 //TODO: add a page with list of non-standard plugins here
257 $strdatabasesetup = get_string('databasesetup');
258 upgrade_init_javascript();
260 $PAGE->navbar
->add($strdatabasesetup);
261 $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release
);
262 $PAGE->set_heading($strinstallation);
263 $PAGE->set_cacheable(false);
265 $output = $PAGE->get_renderer('core', 'admin');
266 echo $output->header();
268 if (!$DB->setup_is_unicodedb()) {
269 if (!$DB->change_db_encoding()) {
270 // If could not convert successfully, throw error, and prevent installation
271 print_error('unicoderequired', 'admin');
275 install_core($version, true);
279 // Check version of Moodle code on disk compared with database
280 // and upgrade if possible.
283 // Do not try to do anything fancy in non-cached mode,
284 // this prevents themes from fetching data from non-existent tables.
285 $PAGE->set_pagelayout('maintenance');
286 $PAGE->set_popup_notification_allowed(false);
289 $stradministration = get_string('administration');
290 $PAGE->set_context(context_system
::instance());
292 if (empty($CFG->version
)) {
293 print_error('missingconfigversion', 'debug');
296 // Detect config cache inconsistency, this happens when you switch branches on dev servers.
297 if ($CFG->version
!= $DB->get_field('config', 'value', array('name'=>'version'))) {
299 redirect(new moodle_url($PAGE->url
), 'Config cache inconsistency detected, resetting caches...');
302 if (!$cache and $version > $CFG->version
) { // upgrade
304 $PAGE->set_url(new moodle_url($PAGE->url
, array(
305 'confirmupgrade' => $confirmupgrade,
306 'confirmrelease' => $confirmrelease,
307 'confirmplugincheck' => $confirmplugins,
310 check_upgrade_key($upgradekeyhash);
312 // Warning about upgrading a test site.
314 if (defined('BEHAT_SITE_RUNNING')) {
318 if (isset($CFG->themerev
)) {
319 // Store the themerev to restore after purging caches.
320 $themerev = $CFG->themerev
;
323 // We purge all of MUC's caches here.
324 // Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true.
325 // This ensures a real config object is loaded and the stores will be purged.
326 // This is the only way we can purge custom caches such as memcache or APC.
327 // Note: all other calls to caches will still used the disabled API.
328 cache_helper
::purge_all(true);
329 // We then purge the regular caches.
332 if (isset($themerev)) {
333 // Restore the themerev
334 set_config('themerev', $themerev);
337 $output = $PAGE->get_renderer('core', 'admin');
339 if (upgrade_stale_php_files_present()) {
340 $PAGE->set_title($stradministration);
341 $PAGE->set_cacheable(false);
343 echo $output->upgrade_stale_php_files_page();
347 if (empty($confirmupgrade)) {
349 $a->oldversion
= "$CFG->release (".sprintf('%.2f', $CFG->version
).")";
350 $a->newversion
= "$release (".sprintf('%.2f', $version).")";
351 $strdatabasechecking = get_string('databasechecking', '', $a);
353 $PAGE->set_title($stradministration);
354 $PAGE->set_heading($strdatabasechecking);
355 $PAGE->set_cacheable(false);
357 echo $output->upgrade_confirm_page($a->newversion
, $maturity, $testsite);
360 } else if (empty($confirmrelease)){
361 require_once($CFG->libdir
.'/environmentlib.php');
362 list($envstatus, $environment_results) = check_moodle_environment($release, ENV_SELECT_RELEASE
);
363 $strcurrentrelease = get_string('currentrelease');
365 $PAGE->navbar
->add($strcurrentrelease);
366 $PAGE->set_title($strcurrentrelease);
367 $PAGE->set_heading($strcurrentrelease);
368 $PAGE->set_cacheable(false);
370 echo $output->upgrade_environment_page($release, $envstatus, $environment_results);
373 } else if (empty($confirmplugins)) {
374 $strplugincheck = get_string('plugincheck');
376 $PAGE->navbar
->add($strplugincheck);
377 $PAGE->set_title($strplugincheck);
378 $PAGE->set_heading($strplugincheck);
379 $PAGE->set_cacheable(false);
381 $pluginman = core_plugin_manager
::instance();
383 // Check for available updates.
385 // No sesskey support guaranteed here, because sessions might not work yet.
386 $updateschecker = \core\update\checker
::instance();
387 if ($updateschecker->enabled()) {
388 $updateschecker->fetch();
390 redirect($PAGE->url
);
393 // Cancel all plugin installations.
394 if ($abortinstallx) {
395 // No sesskey support guaranteed here, because sessions might not work yet.
396 $abortables = $pluginman->list_cancellable_installations();
398 if ($confirmabortinstall) {
399 foreach ($abortables as $plugin) {
400 $pluginman->cancel_plugin_installation($plugin->component
);
402 redirect($PAGE->url
);
404 $continue = new moodle_url($PAGE->url
, array('abortinstallx' => $abortinstallx, 'confirmabortinstall' => 1));
405 echo $output->upgrade_confirm_abort_install_page($abortables, $continue);
409 redirect($PAGE->url
);
412 // Cancel single plugin installation.
414 // No sesskey support guaranteed here, because sessions might not work yet.
415 if ($confirmabortinstall) {
416 $pluginman->cancel_plugin_installation($abortinstall);
417 redirect($PAGE->url
);
419 $continue = new moodle_url($PAGE->url
, array('abortinstall' => $abortinstall, 'confirmabortinstall' => 1));
420 $abortable = $pluginman->get_plugin_info($abortinstall);
421 if ($pluginman->can_cancel_plugin_installation($abortable)) {
422 echo $output->upgrade_confirm_abort_install_page(array($abortable), $continue);
425 redirect($PAGE->url
);
429 // Cancel all plugins upgrades (that is, restore archived versions).
430 if ($abortupgradex) {
431 // No sesskey support guaranteed here, because sessions might not work yet.
432 $restorable = $pluginman->list_restorable_archives();
434 upgrade_install_plugins($restorable, $confirmabortupgrade,
435 get_string('cancelupgradehead', 'core_plugin'),
436 new moodle_url($PAGE->url
, array('abortupgradex' => 1, 'confirmabortupgrade' => 1))
439 redirect($PAGE->url
);
442 // Cancel single plugin upgrade (that is, install the archived version).
444 // No sesskey support guaranteed here, because sessions might not work yet.
445 $restorable = $pluginman->list_restorable_archives();
446 if (isset($restorable[$abortupgrade])) {
447 $restorable = array($restorable[$abortupgrade]);
448 upgrade_install_plugins($restorable, $confirmabortupgrade,
449 get_string('cancelupgradehead', 'core_plugin'),
450 new moodle_url($PAGE->url
, array('abortupgrade' => $abortupgrade, 'confirmabortupgrade' => 1))
453 redirect($PAGE->url
);
456 // Install all available missing dependencies.
458 // No sesskey support guaranteed here, because sessions might not work yet.
459 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
460 upgrade_install_plugins($installable, $confirminstalldep,
461 get_string('dependencyinstallhead', 'core_plugin'),
462 new moodle_url($PAGE->url
, array('installdepx' => 1, 'confirminstalldep' => 1))
466 // Install single available missing dependency.
468 // No sesskey support guaranteed here, because sessions might not work yet.
469 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
470 if (!empty($installable[$installdep])) {
471 $installable = array($installable[$installdep]);
472 upgrade_install_plugins($installable, $confirminstalldep,
473 get_string('dependencyinstallhead', 'core_plugin'),
474 new moodle_url($PAGE->url
, array('installdep' => $installdep, 'confirminstalldep' => 1))
479 // Install all available updates.
480 if ($installupdatex) {
481 // No sesskey support guaranteed here, because sessions might not work yet.
482 $installable = $pluginman->filter_installable($pluginman->available_updates());
483 upgrade_install_plugins($installable, $confirminstallupdate,
484 get_string('updateavailableinstallallhead', 'core_admin'),
485 new moodle_url($PAGE->url
, array('installupdatex' => 1, 'confirminstallupdate' => 1))
489 // Install single available update.
490 if ($installupdate and $installupdateversion) {
491 // No sesskey support guaranteed here, because sessions might not work yet.
492 if ($pluginman->is_remote_plugin_installable($installupdate, $installupdateversion)) {
493 $installable = array($pluginman->get_remote_plugin_info($installupdate, $installupdateversion, true));
494 upgrade_install_plugins($installable, $confirminstallupdate,
495 get_string('updateavailableinstallallhead', 'core_admin'),
496 new moodle_url($PAGE->url
, array('installupdate' => $installupdate,
497 'installupdateversion' => $installupdateversion, 'confirminstallupdate' => 1)
503 echo $output->upgrade_plugin_check_page(core_plugin_manager
::instance(), \core\update\checker
::instance(),
504 $version, $showallplugins, $PAGE->url
, new moodle_url($PAGE->url
, array('confirmplugincheck' => 1)));
508 // Always verify plugin dependencies!
510 if (!core_plugin_manager
::instance()->all_plugins_ok($version, $failed)) {
511 echo $output->unsatisfied_dependencies_page($version, $failed, $PAGE->url
);
516 // Launch main upgrade.
517 upgrade_core($version, true);
519 } else if ($version < $CFG->version
) {
520 // better stop here, we can not continue with plugin upgrades or anything else
521 throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/'));
524 // Updated human-readable release version if necessary
525 if (!$cache and $release <> $CFG->release
) { // Update the release version
526 set_config('release', $release);
529 if (!$cache and $branch <> $CFG->branch
) { // Update the branch
530 set_config('branch', $branch);
533 if (!$cache and moodle_needs_upgrading()) {
535 $PAGE->set_url(new moodle_url($PAGE->url
, array('confirmplugincheck' => $confirmplugins)));
537 check_upgrade_key($upgradekeyhash);
539 if (!$PAGE->headerprinted
) {
540 // means core upgrade or installation was not already done
542 $pluginman = core_plugin_manager
::instance();
543 $output = $PAGE->get_renderer('core', 'admin');
545 if (!$confirmplugins) {
546 $strplugincheck = get_string('plugincheck');
548 $PAGE->navbar
->add($strplugincheck);
549 $PAGE->set_title($strplugincheck);
550 $PAGE->set_heading($strplugincheck);
551 $PAGE->set_cacheable(false);
553 // Check for available updates.
556 $updateschecker = \core\update\checker
::instance();
557 if ($updateschecker->enabled()) {
558 $updateschecker->fetch();
560 redirect($PAGE->url
);
563 // Cancel all plugin installations.
564 if ($abortinstallx) {
566 $abortables = $pluginman->list_cancellable_installations();
568 if ($confirmabortinstall) {
569 foreach ($abortables as $plugin) {
570 $pluginman->cancel_plugin_installation($plugin->component
);
572 redirect($PAGE->url
);
574 $continue = new moodle_url($PAGE->url
, array('abortinstallx' => $abortinstallx,
575 'confirmabortinstall' => 1));
576 echo $output->upgrade_confirm_abort_install_page($abortables, $continue);
580 redirect($PAGE->url
);
583 // Cancel single plugin installation.
586 if ($confirmabortinstall) {
587 $pluginman->cancel_plugin_installation($abortinstall);
588 redirect($PAGE->url
);
590 $continue = new moodle_url($PAGE->url
, array('abortinstall' => $abortinstall, 'confirmabortinstall' => 1));
591 $abortable = $pluginman->get_plugin_info($abortinstall);
592 if ($pluginman->can_cancel_plugin_installation($abortable)) {
593 echo $output->upgrade_confirm_abort_install_page(array($abortable), $continue);
596 redirect($PAGE->url
);
600 // Cancel all plugins upgrades (that is, restore archived versions).
601 if ($abortupgradex) {
603 $restorable = $pluginman->list_restorable_archives();
605 upgrade_install_plugins($restorable, $confirmabortupgrade,
606 get_string('cancelupgradehead', 'core_plugin'),
607 new moodle_url($PAGE->url
, array('abortupgradex' => 1, 'confirmabortupgrade' => 1))
610 redirect($PAGE->url
);
613 // Cancel single plugin upgrade (that is, install the archived version).
616 $restorable = $pluginman->list_restorable_archives();
617 if (isset($restorable[$abortupgrade])) {
618 $restorable = array($restorable[$abortupgrade]);
619 upgrade_install_plugins($restorable, $confirmabortupgrade,
620 get_string('cancelupgradehead', 'core_plugin'),
621 new moodle_url($PAGE->url
, array('abortupgrade' => $abortupgrade, 'confirmabortupgrade' => 1))
624 redirect($PAGE->url
);
627 // Install all available missing dependencies.
630 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
631 upgrade_install_plugins($installable, $confirminstalldep,
632 get_string('dependencyinstallhead', 'core_plugin'),
633 new moodle_url($PAGE->url
, array('installdepx' => 1, 'confirminstalldep' => 1))
637 // Install single available missing dependency.
640 $installable = $pluginman->filter_installable($pluginman->missing_dependencies(true));
641 if (!empty($installable[$installdep])) {
642 $installable = array($installable[$installdep]);
643 upgrade_install_plugins($installable, $confirminstalldep,
644 get_string('dependencyinstallhead', 'core_plugin'),
645 new moodle_url($PAGE->url
, array('installdep' => $installdep, 'confirminstalldep' => 1))
650 // Install all available updates.
651 if ($installupdatex) {
653 $installable = $pluginman->filter_installable($pluginman->available_updates());
654 upgrade_install_plugins($installable, $confirminstallupdate,
655 get_string('updateavailableinstallallhead', 'core_admin'),
656 new moodle_url($PAGE->url
, array('installupdatex' => 1, 'confirminstallupdate' => 1))
660 // Install single available update.
661 if ($installupdate and $installupdateversion) {
663 if ($pluginman->is_remote_plugin_installable($installupdate, $installupdateversion)) {
664 $installable = array($pluginman->get_remote_plugin_info($installupdate, $installupdateversion, true));
665 upgrade_install_plugins($installable, $confirminstallupdate,
666 get_string('updateavailableinstallallhead', 'core_admin'),
667 new moodle_url($PAGE->url
, array('installupdate' => $installupdate,
668 'installupdateversion' => $installupdateversion, 'confirminstallupdate' => 1)
674 // Show plugins info.
675 echo $output->upgrade_plugin_check_page($pluginman, \core\update\checker
::instance(),
676 $version, $showallplugins,
677 new moodle_url($PAGE->url
),
678 new moodle_url($PAGE->url
, array('confirmplugincheck' => 1, 'cache' => 0)));
682 // Make sure plugin dependencies are always checked.
684 if (!$pluginman->all_plugins_ok($version, $failed)) {
685 $output = $PAGE->get_renderer('core', 'admin');
686 echo $output->unsatisfied_dependencies_page($version, $failed, $PAGE->url
);
692 // install/upgrade all plugins and other parts
693 upgrade_noncore(true);
696 // If this is the first install, indicate that this site is fully configured
697 // except the admin password
698 if (during_initial_install()) {
699 set_config('rolesactive', 1); // after this, during_initial_install will return false.
700 set_config('adminsetuppending', 1);
701 // we need this redirect to setup proper session
702 upgrade_finished("index.php?sessionstarted=1&lang=$CFG->lang");
705 // make sure admin user is created - this is the last step because we need
706 // session to be working properly in order to edit admin account
707 if (!empty($CFG->adminsetuppending
)) {
708 $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL
);
709 if (!$sessionstarted) {
710 redirect("index.php?sessionstarted=1&lang=$CFG->lang");
712 $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL
);
713 if (!$sessionverify) {
714 $SESSION->sessionverify
= 1;
715 redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang");
717 if (empty($SESSION->sessionverify
)) {
718 print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang");
720 unset($SESSION->sessionverify
);
724 // Cleanup SESSION to make sure other code does not complain in the future.
725 unset($SESSION->has_timed_out
);
726 unset($SESSION->wantsurl
);
728 // 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
729 $adminids = explode(',', $CFG->siteadmins
);
730 $adminuser = get_complete_user_data('id', reset($adminids));
732 if ($adminuser->password
=== 'adminsetuppending') {
733 // prevent installation hijacking
734 if ($adminuser->lastip
!== getremoteaddr()) {
735 print_error('installhijacked', 'admin');
737 // login user and let him set password and admin details
738 $adminuser->newadminuser
= 1;
739 complete_user_login($adminuser);
740 redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself
743 unset_config('adminsetuppending');
747 // just make sure upgrade logging is properly terminated
748 upgrade_finished('upgradesettings.php');
751 if (has_capability('moodle/site:config', context_system
::instance())) {
754 $updateschecker = \core\update\checker
::instance();
755 if ($updateschecker->enabled()) {
756 $updateschecker->fetch();
758 redirect(new moodle_url('/admin/index.php', array('cache' => 0)));
762 // Now we can be sure everything was upgraded and caches work fine,
763 // redirect if necessary to make sure caching is enabled.
765 redirect(new moodle_url('/admin/index.php', array('cache' => 1)));
768 // Check for valid admin user - no guest autologin
769 require_login(0, false);
771 // Login as real user!
772 $SESSION->wantsurl
= (string)new moodle_url('/admin/index.php');
773 redirect(get_login_url());
775 $context = context_system
::instance();
777 if (!has_capability('moodle/site:config', $context)) {
778 // Do not throw exception display an empty page with administration menu if visible for current user.
779 $PAGE->set_title($SITE->fullname
);
780 $PAGE->set_heading($SITE->fullname
);
781 echo $OUTPUT->header();
782 echo $OUTPUT->footer();
786 // check that site is properly customized
788 if (empty($site->shortname
)) {
789 // probably new installation - lets return to frontpage after this step
790 // remove settings that we want uninitialised
791 unset_config('registerauth');
792 unset_config('timezone'); // Force admin to select timezone!
793 redirect('upgradesettings.php?return=site');
796 // setup critical warnings before printing admin tree block
797 $insecuredataroot = is_dataroot_insecure(true);
798 $SESSION->admin_critical_warning
= ($insecuredataroot==INSECURE_DATAROOT_ERROR
);
800 $adminroot = admin_get_root();
802 // Check if there are any new admin settings which have still yet to be set
803 if (any_new_admin_settings($adminroot)){
804 redirect('upgradesettings.php');
807 // Return to original page that started the plugin uninstallation if necessary.
808 if (isset($SESSION->pluginuninstallreturn
)) {
809 $return = $SESSION->pluginuninstallreturn
;
810 unset($SESSION->pluginuninstallreturn
);
816 // Everything should now be set up, and the user is an admin
818 // Print default admin page with notifications.
819 $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED');
821 // We make the assumption that at least one schedule task should run once per day.
822 $lastcron = $DB->get_field_sql('SELECT MAX(lastruntime) FROM {task_scheduled}');
823 $cronoverdue = ($lastcron < time() - 3600 * 24);
824 $dbproblems = $DB->diagnose();
825 $maintenancemode = !empty($CFG->maintenance_enabled
);
827 // Available updates for Moodle core.
828 $updateschecker = \core\update\checker
::instance();
829 $availableupdates = array();
830 $availableupdatesfetch = null;
832 if ($updateschecker->enabled()) {
833 // Only compute the update information when it is going to be displayed to the user.
834 $availableupdates['core'] = $updateschecker->get_update_info('core',
835 array('minmaturity' => $CFG->updateminmaturity
, 'notifybuilds' => $CFG->updatenotifybuilds
));
837 // Available updates for contributed plugins
838 $pluginman = core_plugin_manager
::instance();
839 foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) {
840 foreach ($plugintypeinstances as $pluginname => $plugininfo) {
841 $pluginavailableupdates = $plugininfo->available_updates();
842 if (!empty($pluginavailableupdates)) {
843 foreach ($pluginavailableupdates as $pluginavailableupdate) {
844 if (!isset($availableupdates[$plugintype.'_'.$pluginname])) {
845 $availableupdates[$plugintype.'_'.$pluginname] = array();
847 $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate;
853 // The timestamp of the most recent check for available updates
854 $availableupdatesfetch = $updateschecker->get_last_timefetched();
857 $buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv
('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€');
858 //check if the site is registered on Moodle.org
859 $registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL
, 'confirmed' => 1));
860 // Check if there are any cache warnings.
861 $cachewarnings = cache_helper
::warnings();
862 // Check if there are events 1 API handlers.
863 $eventshandlers = $DB->get_records_sql('SELECT DISTINCT component FROM {events_handlers}');
864 $themedesignermode = !empty($CFG->themedesignermode
);
866 // Check if a directory with development libraries exists.
867 if (is_dir($CFG->dirroot
.'/vendor') ||
is_dir($CFG->dirroot
.'/node_modules')) {
873 admin_externalpage_setup('adminnotifications');
875 $output = $PAGE->get_renderer('core', 'admin');
877 echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems,
878 $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb,
879 $registered, $cachewarnings, $eventshandlers, $themedesignermode, $devlibdir);