Commit | Line | Data |
---|---|---|
8580535b | 1 | <?php |
2 | ||
3 | // This file is part of Moodle - http://moodle.org/ | |
4 | // | |
5 | // Moodle is free software: you can redistribute it and/or modify | |
6 | // it under the terms of the GNU General Public License as published by | |
7 | // the Free Software Foundation, either version 3 of the License, or | |
8 | // (at your option) any later version. | |
9 | // | |
10 | // Moodle is distributed in the hope that it will be useful, | |
11 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
13 | // GNU General Public License for more details. | |
14 | // | |
15 | // You should have received a copy of the GNU General Public License | |
16 | // along with Moodle. If not, see <http://www.gnu.org/licenses/>. | |
17 | ||
18 | /** | |
19 | * Main administration script. | |
20 | * | |
d078f6d3 | 21 | * @package core |
8580535b | 22 | * @copyright 1999 onwards Martin Dougiamas (http://dougiamas.com) |
23 | * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later | |
24 | */ | |
f9903ed0 | 25 | |
00be1916 | 26 | // Check that config.php exists, if not then call the install script |
27 | if (!file_exists('../config.php')) { | |
28 | header('Location: ../install.php'); | |
3ba28588 | 29 | die(); |
00be1916 | 30 | } |
31 | ||
32 | // Check that PHP is of a sufficient version as soon as possible | |
0fd23b76 | 33 | if (version_compare(phpversion(), '5.3.3') < 0) { |
00be1916 | 34 | $phpversion = phpversion(); |
35 | // do NOT localise - lang strings would not work here and we CAN NOT move it to later place | |
0fd23b76 | 36 | echo "Moodle 2.5 or later requires at least PHP 5.3.3 (currently using version $phpversion).<br />"; |
eab044a0 | 37 | echo "Please upgrade your server software or install older Moodle version."; |
3ba28588 | 38 | die(); |
00be1916 | 39 | } |
40 | ||
695940df PS |
41 | // make sure iconv is available and actually works |
42 | if (!function_exists('iconv')) { | |
43 | // this should not happen, this must be very borked install | |
7d85a4e2 | 44 | echo 'Moodle requires the iconv PHP extension. Please install or enable the iconv extension.'; |
695940df PS |
45 | die(); |
46 | } | |
695940df | 47 | |
cbad562e | 48 | define('NO_OUTPUT_BUFFERING', true); |
00be1916 | 49 | |
bf8c71b7 | 50 | if (empty($_GET['cache']) and empty($_POST['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey'])) { |
e2e35e71 PS |
51 | // Prevent caching at all cost when visiting this page directly, |
52 | // we redirect to self once we known no upgrades are necessary. | |
53 | // Note: $_GET and $_POST are used here intentionally because our param cleaning is not loaded yet. | |
bf8c71b7 | 54 | // Note2: the sesskey is present in all block editing hacks, we can not redirect there, so enable caching. |
e2e35e71 | 55 | define('CACHE_DISABLE_ALL', true); |
c05a5099 PS |
56 | |
57 | // Force OPcache reset if used, we do not want any stale caches | |
58 | // when detecting if upgrade necessary or when running upgrade. | |
59 | if (function_exists('opcache_reset')) { | |
60 | opcache_reset(); | |
61 | } | |
82b1cf00 PS |
62 | $cache = 0; |
63 | ||
64 | } else { | |
65 | $cache = 1; | |
e2e35e71 PS |
66 | } |
67 | ||
00be1916 | 68 | require('../config.php'); |
3274c5db FM |
69 | |
70 | // Invalidate the cache of version.php in any circumstances to help core_component | |
71 | // detecting if the version has changed and component cache should be reset. | |
72 | if (function_exists('opcache_invalidate')) { | |
73 | opcache_invalidate($CFG->dirroot . '/version.php', true); | |
74 | } | |
75 | // Make sure the component cache gets rebuilt if necessary, any method that | |
76 | // indirectly calls the protected init() method is good here. | |
77 | core_component::get_core_subsystems(); | |
78 | ||
bc76b3c0 | 79 | require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions |
80 | require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions | |
00be1916 | 81 | |
82 | $id = optional_param('id', '', PARAM_TEXT); | |
83 | $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL); | |
84 | $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL); | |
85 | $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL); | |
b9934a17 | 86 | $showallplugins = optional_param('showallplugins', 0, PARAM_BOOL); |
00be1916 | 87 | $agreelicense = optional_param('agreelicense', 0, PARAM_BOOL); |
55585f3a | 88 | $fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL); |
0a6a344d | 89 | $newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW); |
00be1916 | 90 | |
e2e35e71 PS |
91 | // Set up PAGE. |
92 | $url = new moodle_url('/admin/index.php'); | |
e2e35e71 | 93 | if ($cache) { |
82b1cf00 | 94 | $url->param('cache', 1); |
e2e35e71 PS |
95 | } |
96 | $PAGE->set_url($url); | |
97 | unset($url); | |
98 | ||
82b1cf00 | 99 | // Are we returning from an add-on installation request at moodle.org/plugins? |
835f58eb | 100 | if ($newaddonreq and !$cache and empty($CFG->disableonclickaddoninstall)) { |
82b1cf00 PS |
101 | $target = new moodle_url('/admin/tool/installaddon/index.php', array( |
102 | 'installaddonrequest' => $newaddonreq, | |
103 | 'confirm' => 0)); | |
104 | if (!isloggedin() or isguestuser()) { | |
105 | // Login and go the the add-on tool page. | |
106 | $SESSION->wantsurl = $target->out(); | |
107 | redirect(get_login_url()); | |
108 | } | |
109 | redirect($target); | |
110 | } | |
111 | ||
6d80fad4 | 112 | $PAGE->set_pagelayout('admin'); // Set a default pagelayout |
ee73b1ff | 113 | |
00be1916 | 114 | $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>'; |
115 | ||
e2e35e71 PS |
116 | // Check some PHP server settings |
117 | ||
00be1916 | 118 | if (ini_get_bool('session.auto_start')) { |
119 | print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink)); | |
120 | } | |
121 | ||
122 | if (ini_get_bool('magic_quotes_runtime')) { | |
123 | print_error('phpvaroff', 'debug', '', (object)array('name'=>'magic_quotes_runtime', 'link'=>$documentationlink)); | |
124 | } | |
125 | ||
126 | if (!ini_get_bool('file_uploads')) { | |
127 | print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink)); | |
128 | } | |
129 | ||
130 | if (is_float_problem()) { | |
131 | print_error('phpfloatproblem', 'admin', '', $documentationlink); | |
132 | } | |
133 | ||
00be1916 | 134 | // Set some necessary variables during set-up to avoid PHP warnings later on this page |
00be1916 | 135 | if (!isset($CFG->release)) { |
bc76b3c0 | 136 | $CFG->release = ''; |
00be1916 | 137 | } |
138 | if (!isset($CFG->version)) { | |
bc76b3c0 | 139 | $CFG->version = ''; |
00be1916 | 140 | } |
ad394588 AB |
141 | if (!isset($CFG->branch)) { |
142 | $CFG->branch = ''; | |
143 | } | |
00be1916 | 144 | |
145 | $version = null; | |
146 | $release = null; | |
ed01233a AB |
147 | $branch = null; |
148 | require("$CFG->dirroot/version.php"); // defines $version, $release, $branch and $maturity | |
00be1916 | 149 | $CFG->target_release = $release; // used during installation and upgrades |
150 | ||
151 | if (!$version or !$release) { | |
152 | print_error('withoutversion', 'debug'); // without version, stop | |
153 | } | |
154 | ||
3316fe24 | 155 | if (!core_tables_exist()) { |
78946b9b | 156 | $PAGE->set_pagelayout('maintenance'); |
d3875524 | 157 | $PAGE->set_popup_notification_allowed(false); |
00be1916 | 158 | |
159 | // fake some settings | |
160 | $CFG->docroot = 'http://docs.moodle.org'; | |
161 | ||
162 | $strinstallation = get_string('installation', 'install'); | |
163 | ||
164 | // remove current session content completely | |
d79d5ac2 | 165 | \core\session\manager::terminate_current(); |
00be1916 | 166 | |
167 | if (empty($agreelicense)) { | |
168 | $strlicense = get_string('license'); | |
cc359566 | 169 | |
69d77c23 | 170 | $PAGE->navbar->add($strlicense); |
171 | $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release); | |
172 | $PAGE->set_heading($strinstallation); | |
173 | $PAGE->set_cacheable(false); | |
cc359566 | 174 | |
82b1cf00 | 175 | /** @var core_admin_renderer $output */ |
da2fdc3f | 176 | $output = $PAGE->get_renderer('core', 'admin'); |
cc359566 | 177 | echo $output->install_licence_page(); |
3ba28588 | 178 | die(); |
249ab745 | 179 | } |
00be1916 | 180 | if (empty($confirmrelease)) { |
cc359566 TH |
181 | require_once($CFG->libdir.'/environmentlib.php'); |
182 | list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); | |
bc76b3c0 | 183 | $strcurrentrelease = get_string('currentrelease'); |
cc359566 | 184 | |
69d77c23 | 185 | $PAGE->navbar->add($strcurrentrelease); |
1a4d6a5b DM |
186 | $PAGE->set_title($strinstallation); |
187 | $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release); | |
69d77c23 | 188 | $PAGE->set_cacheable(false); |
249ab745 | 189 | |
82b1cf00 | 190 | /** @var core_admin_renderer $output */ |
cc359566 | 191 | $output = $PAGE->get_renderer('core', 'admin'); |
8d1da748 | 192 | echo $output->install_environment_page($maturity, $envstatus, $environment_results, $release); |
3ba28588 | 193 | die(); |
1dd24519 | 194 | } |
195 | ||
39f15cc7 DM |
196 | // check plugin dependencies |
197 | $failed = array(); | |
e87214bd | 198 | if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { |
39f15cc7 DM |
199 | $PAGE->navbar->add(get_string('pluginscheck', 'admin')); |
200 | $PAGE->set_title($strinstallation); | |
201 | $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release); | |
202 | ||
203 | $output = $PAGE->get_renderer('core', 'admin'); | |
204 | $url = new moodle_url('/admin/index.php', array('agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)); | |
205 | echo $output->unsatisfied_dependencies_page($version, $failed, $url); | |
206 | die(); | |
207 | } | |
208 | unset($failed); | |
209 | ||
8d1da748 PS |
210 | //TODO: add a page with list of non-standard plugins here |
211 | ||
bc76b3c0 | 212 | $strdatabasesetup = get_string('databasesetup'); |
543f54d3 | 213 | upgrade_init_javascript(); |
cc359566 | 214 | |
69d77c23 | 215 | $PAGE->navbar->add($strdatabasesetup); |
216 | $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release); | |
2ea05146 | 217 | $PAGE->set_heading($strinstallation); |
69d77c23 | 218 | $PAGE->set_cacheable(false); |
cc359566 | 219 | |
da2fdc3f TH |
220 | $output = $PAGE->get_renderer('core', 'admin'); |
221 | echo $output->header(); | |
d02bc6ce | 222 | |
00be1916 | 223 | if (!$DB->setup_is_unicodedb()) { |
224 | if (!$DB->change_db_encoding()) { | |
225 | // If could not convert successfully, throw error, and prevent installation | |
226 | print_error('unicoderequired', 'admin'); | |
db5af934 | 227 | } |
db5af934 | 228 | } |
90509582 | 229 | |
00be1916 | 230 | install_core($version, true); |
231 | } | |
db5af934 | 232 | |
db5af934 | 233 | |
00be1916 | 234 | // Check version of Moodle code on disk compared with database |
235 | // and upgrade if possible. | |
db5af934 | 236 | |
00be1916 | 237 | $stradministration = get_string('administration'); |
bf006d2c | 238 | $PAGE->set_context(context_system::instance()); |
db5af934 | 239 | |
00be1916 | 240 | if (empty($CFG->version)) { |
241 | print_error('missingconfigversion', 'debug'); | |
242 | } | |
db5af934 | 243 | |
e2e35e71 | 244 | // Detect config cache inconsistency, this happens when you switch branches on dev servers. |
82b1cf00 PS |
245 | if ($CFG->version != $DB->get_field('config', 'value', array('name'=>'version'))) { |
246 | purge_all_caches(); | |
247 | redirect(new moodle_url('/admin/index.php'), 'Config cache inconsistency detected, resetting caches...'); | |
e2e35e71 PS |
248 | } |
249 | ||
82b1cf00 | 250 | if (!$cache and $version > $CFG->version) { // upgrade |
6e09cf98 DM |
251 | |
252 | // Warning about upgrading a test site. | |
253 | $testsite = false; | |
254 | if (defined('BEHAT_SITE_RUNNING')) { | |
255 | $testsite = 'behat'; | |
256 | } | |
257 | ||
b0dd08dd SH |
258 | // We purge all of MUC's caches here. |
259 | // Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true. | |
260 | // This ensures a real config object is loaded and the stores will be purged. | |
261 | // This is the only way we can purge custom caches such as memcache or APC. | |
262 | // Note: all other calls to caches will still used the disabled API. | |
263 | cache_helper::purge_all(true); | |
264 | // We then purge the regular caches. | |
a95682b2 | 265 | purge_all_caches(); |
33082590 | 266 | |
78946b9b | 267 | $PAGE->set_pagelayout('maintenance'); |
d3875524 | 268 | $PAGE->set_popup_notification_allowed(false); |
d4a03c00 | 269 | |
9008ec16 PS |
270 | if (upgrade_stale_php_files_present()) { |
271 | $PAGE->set_title($stradministration); | |
272 | $PAGE->set_cacheable(false); | |
273 | ||
82b1cf00 | 274 | /** @var core_admin_renderer $output */ |
9008ec16 PS |
275 | $output = $PAGE->get_renderer('core', 'admin'); |
276 | echo $output->upgrade_stale_php_files_page(); | |
277 | die(); | |
278 | } | |
279 | ||
00be1916 | 280 | if (empty($confirmupgrade)) { |
17854cb9 | 281 | $a = new stdClass(); |
c22a579b RT |
282 | $a->oldversion = "$CFG->release (".sprintf('%.2f', $CFG->version).")"; |
283 | $a->newversion = "$release (".sprintf('%.2f', $version).")"; | |
cc359566 TH |
284 | $strdatabasechecking = get_string('databasechecking', '', $a); |
285 | ||
1a4d6a5b DM |
286 | $PAGE->set_title($stradministration); |
287 | $PAGE->set_heading($strdatabasechecking); | |
69d77c23 | 288 | $PAGE->set_cacheable(false); |
cc359566 | 289 | |
82b1cf00 | 290 | /** @var core_admin_renderer $output */ |
da2fdc3f | 291 | $output = $PAGE->get_renderer('core', 'admin'); |
6e09cf98 | 292 | echo $output->upgrade_confirm_page($a->newversion, $maturity, $testsite); |
3ba28588 | 293 | die(); |
db5af934 | 294 | |
00be1916 | 295 | } else if (empty($confirmrelease)){ |
cc359566 TH |
296 | require_once($CFG->libdir.'/environmentlib.php'); |
297 | list($envstatus, $environment_results) = check_moodle_environment($release, ENV_SELECT_RELEASE); | |
bc76b3c0 | 298 | $strcurrentrelease = get_string('currentrelease'); |
cc359566 | 299 | |
69d77c23 | 300 | $PAGE->navbar->add($strcurrentrelease); |
301 | $PAGE->set_title($strcurrentrelease); | |
52273536 | 302 | $PAGE->set_heading($strcurrentrelease); |
69d77c23 | 303 | $PAGE->set_cacheable(false); |
db5af934 | 304 | |
82b1cf00 | 305 | /** @var core_admin_renderer $output */ |
cc359566 | 306 | $output = $PAGE->get_renderer('core', 'admin'); |
faadd326 TH |
307 | echo $output->upgrade_environment_page($release, $envstatus, $environment_results); |
308 | die(); | |
db5af934 | 309 | |
cc359566 | 310 | } else if (empty($confirmplugins)) { |
00be1916 | 311 | $strplugincheck = get_string('plugincheck'); |
cc359566 | 312 | |
69d77c23 | 313 | $PAGE->navbar->add($strplugincheck); |
314 | $PAGE->set_title($strplugincheck); | |
52273536 | 315 | $PAGE->set_heading($strplugincheck); |
69d77c23 | 316 | $PAGE->set_cacheable(false); |
b9934a17 | 317 | |
96dd9237 DM |
318 | $reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)); |
319 | ||
82b1cf00 PS |
320 | /** @var core_admin_renderer $output */ |
321 | $output = $PAGE->get_renderer('core', 'admin'); | |
322 | ||
ead8ba3b DM |
323 | // check plugin dependencies first |
324 | $failed = array(); | |
e87214bd | 325 | if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { |
ead8ba3b DM |
326 | echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl); |
327 | die(); | |
328 | } | |
329 | unset($failed); | |
330 | ||
96dd9237 | 331 | if ($fetchupdates) { |
5a08e363 | 332 | // no sesskey support guaranteed here |
4db58f5f | 333 | if (empty($CFG->disableupdatenotifications)) { |
e87214bd | 334 | \core\update\checker::instance()->fetch(); |
4db58f5f | 335 | } |
96dd9237 DM |
336 | redirect($reloadurl); |
337 | } | |
338 | ||
e87214bd | 339 | $deployer = \core\update\deployer::instance(); |
bcc8397a DM |
340 | if ($deployer->enabled()) { |
341 | $deployer->initialize($reloadurl, $reloadurl); | |
342 | ||
343 | $deploydata = $deployer->submitted_data(); | |
344 | if (!empty($deploydata)) { | |
345 | echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata); | |
346 | die(); | |
347 | } | |
348 | } | |
349 | ||
e87214bd | 350 | echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(), |
96dd9237 | 351 | $version, $showallplugins, $reloadurl, |
cc359566 | 352 | new moodle_url('/admin/index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1))); |
00be1916 | 353 | die(); |
db5af934 | 354 | |
00be1916 | 355 | } else { |
356 | // Launch main upgrade | |
357 | upgrade_core($version, true); | |
88582df4 | 358 | } |
00be1916 | 359 | } else if ($version < $CFG->version) { |
80380bd7 PS |
360 | // better stop here, we can not continue with plugin upgrades or anything else |
361 | throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/')); | |
00be1916 | 362 | } |
363 | ||
364 | // Updated human-readable release version if necessary | |
82b1cf00 | 365 | if (!$cache and $release <> $CFG->release) { // Update the release version |
bc76b3c0 | 366 | set_config('release', $release); |
00be1916 | 367 | } |
368 | ||
82b1cf00 | 369 | if (!$cache and $branch <> $CFG->branch) { // Update the branch |
ed01233a AB |
370 | set_config('branch', $branch); |
371 | } | |
372 | ||
82b1cf00 | 373 | if (!$cache and moodle_needs_upgrading()) { |
575f245f | 374 | if (!$PAGE->headerprinted) { |
2361b7dd | 375 | // means core upgrade or installation was not already done |
575f245f | 376 | if (!$confirmplugins) { |
cc359566 TH |
377 | $strplugincheck = get_string('plugincheck'); |
378 | ||
2361b7dd | 379 | $PAGE->set_pagelayout('maintenance'); |
d3875524 | 380 | $PAGE->set_popup_notification_allowed(false); |
575f245f PS |
381 | $PAGE->navbar->add($strplugincheck); |
382 | $PAGE->set_title($strplugincheck); | |
383 | $PAGE->set_heading($strplugincheck); | |
384 | $PAGE->set_cacheable(false); | |
b9934a17 | 385 | |
96dd9237 | 386 | if ($fetchupdates) { |
5a08e363 | 387 | // no sesskey support guaranteed here |
e87214bd | 388 | \core\update\checker::instance()->fetch(); |
96dd9237 DM |
389 | redirect($PAGE->url); |
390 | } | |
391 | ||
cc359566 | 392 | $output = $PAGE->get_renderer('core', 'admin'); |
ead8ba3b | 393 | |
e87214bd | 394 | $deployer = \core\update\deployer::instance(); |
292dbeac DM |
395 | if ($deployer->enabled()) { |
396 | $deployer->initialize($PAGE->url, $PAGE->url); | |
397 | ||
398 | $deploydata = $deployer->submitted_data(); | |
399 | if (!empty($deploydata)) { | |
400 | echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata); | |
401 | die(); | |
402 | } | |
403 | } | |
404 | ||
ead8ba3b DM |
405 | // check plugin dependencies first |
406 | $failed = array(); | |
e87214bd | 407 | if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { |
ead8ba3b DM |
408 | echo $output->unsatisfied_dependencies_page($version, $failed, $PAGE->url); |
409 | die(); | |
410 | } | |
411 | unset($failed); | |
412 | ||
413 | // dependencies check passed, let's rock! | |
e87214bd | 414 | echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(), |
96dd9237 DM |
415 | $version, $showallplugins, |
416 | new moodle_url($PAGE->url), | |
cc359566 | 417 | new moodle_url('/admin/index.php', array('confirmplugincheck'=>1))); |
575f245f PS |
418 | die(); |
419 | } | |
420 | } | |
421 | // install/upgrade all plugins and other parts | |
422 | upgrade_noncore(true); | |
423 | } | |
00be1916 | 424 | |
31a99877 | 425 | // If this is the first install, indicate that this site is fully configured |
426 | // except the admin password | |
427 | if (during_initial_install()) { | |
428 | set_config('rolesactive', 1); // after this, during_initial_install will return false. | |
00be1916 | 429 | set_config('adminsetuppending', 1); |
c8ae55e9 | 430 | // we need this redirect to setup proper session |
00be1916 | 431 | upgrade_finished("index.php?sessionstarted=1&lang=$CFG->lang"); |
432 | } | |
433 | ||
434 | // make sure admin user is created - this is the last step because we need | |
435 | // session to be working properly in order to edit admin account | |
436 | if (!empty($CFG->adminsetuppending)) { | |
437 | $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL); | |
438 | if (!$sessionstarted) { | |
439 | redirect("index.php?sessionstarted=1&lang=$CFG->lang"); | |
440 | } else { | |
441 | $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL); | |
442 | if (!$sessionverify) { | |
443 | $SESSION->sessionverify = 1; | |
444 | redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang"); | |
88582df4 | 445 | } else { |
00be1916 | 446 | if (empty($SESSION->sessionverify)) { |
447 | print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang"); | |
88582df4 | 448 | } |
00be1916 | 449 | unset($SESSION->sessionverify); |
88582df4 | 450 | } |
00be1916 | 451 | } |
88582df4 | 452 | |
4f73591a PS |
453 | // Cleanup SESSION to make sure other code does not complain in the future. |
454 | unset($SESSION->has_timed_out); | |
455 | unset($SESSION->wantsurl); | |
456 | ||
a7c9609b | 457 | // at this stage there can be only one admin unless more were added by install - users may change username, so do not rely on that |
f20edd52 PS |
458 | $adminids = explode(',', $CFG->siteadmins); |
459 | $adminuser = get_complete_user_data('id', reset($adminids)); | |
88582df4 | 460 | |
00be1916 | 461 | if ($adminuser->password === 'adminsetuppending') { |
462 | // prevent installation hijacking | |
463 | if ($adminuser->lastip !== getremoteaddr()) { | |
464 | print_error('installhijacked', 'admin'); | |
35d6a2a4 | 465 | } |
00be1916 | 466 | // login user and let him set password and admin details |
467 | $adminuser->newadminuser = 1; | |
0342fc36 | 468 | complete_user_login($adminuser); |
00be1916 | 469 | redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself |
db5af934 | 470 | |
5c144d60 | 471 | } else { |
00be1916 | 472 | unset_config('adminsetuppending'); |
4da1a0a1 | 473 | } |
474 | ||
00be1916 | 475 | } else { |
476 | // just make sure upgrade logging is properly terminated | |
477 | upgrade_finished('upgradesettings.php'); | |
478 | } | |
b3732604 | 479 | |
e2e35e71 PS |
480 | // Now we can be sure everything was upgraded and caches work fine, |
481 | // redirect if necessary to make sure caching is enabled. | |
82b1cf00 PS |
482 | if (!$cache) { |
483 | redirect(new moodle_url('/admin/index.php', array('cache' => 1))); | |
e2e35e71 PS |
484 | } |
485 | ||
00be1916 | 486 | // Check for valid admin user - no guest autologin |
487 | require_login(0, false); | |
bf006d2c | 488 | $context = context_system::instance(); |
00be1916 | 489 | require_capability('moodle/site:config', $context); |
490 | ||
491 | // check that site is properly customized | |
492 | $site = get_site(); | |
493 | if (empty($site->shortname)) { | |
494 | // probably new installation - lets return to frontpage after this step | |
495 | // remove settings that we want uninitialised | |
496 | unset_config('registerauth'); | |
497 | redirect('upgradesettings.php?return=site'); | |
498 | } | |
499 | ||
500 | // Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders | |
501 | if (!empty($id) and $id == $CFG->siteidentifier) { | |
502 | set_config('registered', time()); | |
503 | } | |
504 | ||
505 | // setup critical warnings before printing admin tree block | |
bc76b3c0 | 506 | $insecuredataroot = is_dataroot_insecure(true); |
00be1916 | 507 | $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR); |
508 | ||
509 | $adminroot = admin_get_root(); | |
510 | ||
511 | // Check if there are any new admin settings which have still yet to be set | |
512 | if (any_new_admin_settings($adminroot)){ | |
513 | redirect('upgradesettings.php'); | |
514 | } | |
515 | ||
e87214bd PS |
516 | // Return to original page that started the plugin uninstallation if necessary. |
517 | if (isset($SESSION->pluginuninstallreturn)) { | |
518 | $return = $SESSION->pluginuninstallreturn; | |
519 | unset($SESSION->pluginuninstallreturn); | |
520 | if ($return) { | |
521 | redirect($return); | |
522 | } | |
523 | } | |
524 | ||
00be1916 | 525 | // Everything should now be set up, and the user is an admin |
526 | ||
527 | // Print default admin page with notifications. | |
cc359566 | 528 | $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED'); |
a95682b2 | 529 | |
00be1916 | 530 | $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}'); |
cc359566 TH |
531 | $cronoverdue = ($lastcron < time() - 3600 * 24); |
532 | $dbproblems = $DB->diagnose(); | |
533 | $maintenancemode = !empty($CFG->maintenance_enabled); | |
74944b73 | 534 | |
966bd785 | 535 | // Available updates for Moodle core |
e87214bd | 536 | $updateschecker = \core\update\checker::instance(); |
966bd785 DM |
537 | $availableupdates = array(); |
538 | $availableupdates['core'] = $updateschecker->get_update_info('core', | |
c6f008e7 | 539 | array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds)); |
966bd785 DM |
540 | |
541 | // Available updates for contributed plugins | |
e87214bd | 542 | $pluginman = core_plugin_manager::instance(); |
966bd785 DM |
543 | foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) { |
544 | foreach ($plugintypeinstances as $pluginname => $plugininfo) { | |
545 | if (!empty($plugininfo->availableupdates)) { | |
546 | foreach ($plugininfo->availableupdates as $pluginavailableupdate) { | |
547 | if ($pluginavailableupdate->version > $plugininfo->versiondisk) { | |
548 | if (!isset($availableupdates[$plugintype.'_'.$pluginname])) { | |
549 | $availableupdates[$plugintype.'_'.$pluginname] = array(); | |
550 | } | |
551 | $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate; | |
552 | } | |
553 | } | |
554 | } | |
555 | } | |
556 | } | |
557 | ||
558 | // The timestamp of the most recent check for available updates | |
55585f3a DM |
559 | $availableupdatesfetch = $updateschecker->get_last_timefetched(); |
560 | ||
0aff15c2 | 561 | $buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€'); |
b3245b75 DP |
562 | //check if the site is registered on Moodle.org |
563 | $registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL, 'confirmed' => 1)); | |
0aff15c2 | 564 | |
cc359566 | 565 | admin_externalpage_setup('adminnotifications'); |
55585f3a DM |
566 | |
567 | if ($fetchupdates) { | |
568 | require_sesskey(); | |
569 | $updateschecker->fetch(); | |
e2e35e71 | 570 | redirect(new moodle_url('/admin/index.php')); |
55585f3a DM |
571 | } |
572 | ||
cc359566 TH |
573 | $output = $PAGE->get_renderer('core', 'admin'); |
574 | echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, | |
b3245b75 DP |
575 | $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, |
576 | $registered); |