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 | } | |
e2e35e71 PS |
62 | } |
63 | ||
00be1916 | 64 | require('../config.php'); |
bc76b3c0 | 65 | require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions |
66 | require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions | |
55585f3a | 67 | require_once($CFG->libdir.'/pluginlib.php'); // available updates notifications |
00be1916 | 68 | |
69 | $id = optional_param('id', '', PARAM_TEXT); | |
70 | $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL); | |
71 | $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL); | |
72 | $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL); | |
b9934a17 | 73 | $showallplugins = optional_param('showallplugins', 0, PARAM_BOOL); |
00be1916 | 74 | $agreelicense = optional_param('agreelicense', 0, PARAM_BOOL); |
55585f3a | 75 | $fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL); |
0a6a344d | 76 | $newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW); |
e2e35e71 | 77 | $cache = optional_param('cache', 0, PARAM_BOOL); |
00be1916 | 78 | |
e2e35e71 PS |
79 | // Set up PAGE. |
80 | $url = new moodle_url('/admin/index.php'); | |
81 | if (!is_null($newaddonreq)) { | |
0a6a344d DM |
82 | // We need to set the eventual add-on installation request in the $PAGE's URL |
83 | // so that it is stored in $SESSION->wantsurl and the admin is redirected | |
84 | // correctly once they are logged-in. | |
e2e35e71 | 85 | $url->param('installaddonrequest', $newaddonreq); |
0a6a344d | 86 | } |
e2e35e71 PS |
87 | if ($cache) { |
88 | $url->param('cache', $cache); | |
89 | } | |
90 | $PAGE->set_url($url); | |
91 | unset($url); | |
92 | ||
6d80fad4 | 93 | $PAGE->set_pagelayout('admin'); // Set a default pagelayout |
ee73b1ff | 94 | |
00be1916 | 95 | $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>'; |
96 | ||
e2e35e71 PS |
97 | // Check some PHP server settings |
98 | ||
00be1916 | 99 | if (ini_get_bool('session.auto_start')) { |
100 | print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink)); | |
101 | } | |
102 | ||
103 | if (ini_get_bool('magic_quotes_runtime')) { | |
104 | print_error('phpvaroff', 'debug', '', (object)array('name'=>'magic_quotes_runtime', 'link'=>$documentationlink)); | |
105 | } | |
106 | ||
107 | if (!ini_get_bool('file_uploads')) { | |
108 | print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink)); | |
109 | } | |
110 | ||
111 | if (is_float_problem()) { | |
112 | print_error('phpfloatproblem', 'admin', '', $documentationlink); | |
113 | } | |
114 | ||
00be1916 | 115 | // Set some necessary variables during set-up to avoid PHP warnings later on this page |
00be1916 | 116 | if (!isset($CFG->release)) { |
bc76b3c0 | 117 | $CFG->release = ''; |
00be1916 | 118 | } |
119 | if (!isset($CFG->version)) { | |
bc76b3c0 | 120 | $CFG->version = ''; |
00be1916 | 121 | } |
ad394588 AB |
122 | if (!isset($CFG->branch)) { |
123 | $CFG->branch = ''; | |
124 | } | |
00be1916 | 125 | |
126 | $version = null; | |
127 | $release = null; | |
ed01233a AB |
128 | $branch = null; |
129 | require("$CFG->dirroot/version.php"); // defines $version, $release, $branch and $maturity | |
00be1916 | 130 | $CFG->target_release = $release; // used during installation and upgrades |
131 | ||
132 | if (!$version or !$release) { | |
133 | print_error('withoutversion', 'debug'); // without version, stop | |
134 | } | |
135 | ||
3316fe24 | 136 | if (!core_tables_exist()) { |
78946b9b | 137 | $PAGE->set_pagelayout('maintenance'); |
d3875524 | 138 | $PAGE->set_popup_notification_allowed(false); |
00be1916 | 139 | |
140 | // fake some settings | |
141 | $CFG->docroot = 'http://docs.moodle.org'; | |
142 | ||
143 | $strinstallation = get_string('installation', 'install'); | |
144 | ||
145 | // remove current session content completely | |
146 | session_get_instance()->terminate_current(); | |
147 | ||
148 | if (empty($agreelicense)) { | |
149 | $strlicense = get_string('license'); | |
cc359566 | 150 | |
69d77c23 | 151 | $PAGE->navbar->add($strlicense); |
152 | $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release); | |
153 | $PAGE->set_heading($strinstallation); | |
154 | $PAGE->set_cacheable(false); | |
cc359566 | 155 | |
da2fdc3f | 156 | $output = $PAGE->get_renderer('core', 'admin'); |
cc359566 | 157 | echo $output->install_licence_page(); |
3ba28588 | 158 | die(); |
249ab745 | 159 | } |
00be1916 | 160 | if (empty($confirmrelease)) { |
cc359566 TH |
161 | require_once($CFG->libdir.'/environmentlib.php'); |
162 | list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); | |
bc76b3c0 | 163 | $strcurrentrelease = get_string('currentrelease'); |
cc359566 | 164 | |
69d77c23 | 165 | $PAGE->navbar->add($strcurrentrelease); |
1a4d6a5b DM |
166 | $PAGE->set_title($strinstallation); |
167 | $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release); | |
69d77c23 | 168 | $PAGE->set_cacheable(false); |
249ab745 | 169 | |
cc359566 | 170 | $output = $PAGE->get_renderer('core', 'admin'); |
8d1da748 | 171 | echo $output->install_environment_page($maturity, $envstatus, $environment_results, $release); |
3ba28588 | 172 | die(); |
1dd24519 | 173 | } |
174 | ||
39f15cc7 DM |
175 | // check plugin dependencies |
176 | $failed = array(); | |
177 | if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) { | |
178 | $PAGE->navbar->add(get_string('pluginscheck', 'admin')); | |
179 | $PAGE->set_title($strinstallation); | |
180 | $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release); | |
181 | ||
182 | $output = $PAGE->get_renderer('core', 'admin'); | |
183 | $url = new moodle_url('/admin/index.php', array('agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)); | |
184 | echo $output->unsatisfied_dependencies_page($version, $failed, $url); | |
185 | die(); | |
186 | } | |
187 | unset($failed); | |
188 | ||
8d1da748 PS |
189 | //TODO: add a page with list of non-standard plugins here |
190 | ||
bc76b3c0 | 191 | $strdatabasesetup = get_string('databasesetup'); |
543f54d3 | 192 | upgrade_init_javascript(); |
cc359566 | 193 | |
69d77c23 | 194 | $PAGE->navbar->add($strdatabasesetup); |
195 | $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release); | |
2ea05146 | 196 | $PAGE->set_heading($strinstallation); |
69d77c23 | 197 | $PAGE->set_cacheable(false); |
cc359566 | 198 | |
da2fdc3f TH |
199 | $output = $PAGE->get_renderer('core', 'admin'); |
200 | echo $output->header(); | |
d02bc6ce | 201 | |
00be1916 | 202 | if (!$DB->setup_is_unicodedb()) { |
203 | if (!$DB->change_db_encoding()) { | |
204 | // If could not convert successfully, throw error, and prevent installation | |
205 | print_error('unicoderequired', 'admin'); | |
db5af934 | 206 | } |
db5af934 | 207 | } |
90509582 | 208 | |
00be1916 | 209 | install_core($version, true); |
210 | } | |
db5af934 | 211 | |
db5af934 | 212 | |
00be1916 | 213 | // Check version of Moodle code on disk compared with database |
214 | // and upgrade if possible. | |
db5af934 | 215 | |
00be1916 | 216 | $stradministration = get_string('administration'); |
bf006d2c | 217 | $PAGE->set_context(context_system::instance()); |
db5af934 | 218 | |
00be1916 | 219 | if (empty($CFG->version)) { |
220 | print_error('missingconfigversion', 'debug'); | |
221 | } | |
db5af934 | 222 | |
e2e35e71 PS |
223 | // Detect config cache inconsistency, this happens when you switch branches on dev servers. |
224 | if ($cache) { | |
225 | if ($CFG->version != $DB->get_field('config', 'value', array('name'=>'version'))) { | |
226 | purge_all_caches(); | |
227 | redirect(new moodle_url('/admin/index.php'), 'Config cache inconsistency detected, resetting caches...'); | |
228 | } | |
229 | } | |
230 | ||
00be1916 | 231 | if ($version > $CFG->version) { // upgrade |
b0dd08dd SH |
232 | // We purge all of MUC's caches here. |
233 | // Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true. | |
234 | // This ensures a real config object is loaded and the stores will be purged. | |
235 | // This is the only way we can purge custom caches such as memcache or APC. | |
236 | // Note: all other calls to caches will still used the disabled API. | |
237 | cache_helper::purge_all(true); | |
238 | // We then purge the regular caches. | |
a95682b2 | 239 | purge_all_caches(); |
33082590 | 240 | |
78946b9b | 241 | $PAGE->set_pagelayout('maintenance'); |
d3875524 | 242 | $PAGE->set_popup_notification_allowed(false); |
d4a03c00 | 243 | |
9008ec16 PS |
244 | if (upgrade_stale_php_files_present()) { |
245 | $PAGE->set_title($stradministration); | |
246 | $PAGE->set_cacheable(false); | |
247 | ||
248 | $output = $PAGE->get_renderer('core', 'admin'); | |
249 | echo $output->upgrade_stale_php_files_page(); | |
250 | die(); | |
251 | } | |
252 | ||
00be1916 | 253 | if (empty($confirmupgrade)) { |
17854cb9 | 254 | $a = new stdClass(); |
c22a579b RT |
255 | $a->oldversion = "$CFG->release (".sprintf('%.2f', $CFG->version).")"; |
256 | $a->newversion = "$release (".sprintf('%.2f', $version).")"; | |
cc359566 TH |
257 | $strdatabasechecking = get_string('databasechecking', '', $a); |
258 | ||
1a4d6a5b DM |
259 | $PAGE->set_title($stradministration); |
260 | $PAGE->set_heading($strdatabasechecking); | |
69d77c23 | 261 | $PAGE->set_cacheable(false); |
cc359566 | 262 | |
da2fdc3f | 263 | $output = $PAGE->get_renderer('core', 'admin'); |
cc359566 | 264 | echo $output->upgrade_confirm_page($a->newversion, $maturity); |
3ba28588 | 265 | die(); |
db5af934 | 266 | |
00be1916 | 267 | } else if (empty($confirmrelease)){ |
cc359566 TH |
268 | require_once($CFG->libdir.'/environmentlib.php'); |
269 | list($envstatus, $environment_results) = check_moodle_environment($release, ENV_SELECT_RELEASE); | |
bc76b3c0 | 270 | $strcurrentrelease = get_string('currentrelease'); |
cc359566 | 271 | |
69d77c23 | 272 | $PAGE->navbar->add($strcurrentrelease); |
273 | $PAGE->set_title($strcurrentrelease); | |
52273536 | 274 | $PAGE->set_heading($strcurrentrelease); |
69d77c23 | 275 | $PAGE->set_cacheable(false); |
db5af934 | 276 | |
cc359566 | 277 | $output = $PAGE->get_renderer('core', 'admin'); |
faadd326 TH |
278 | echo $output->upgrade_environment_page($release, $envstatus, $environment_results); |
279 | die(); | |
db5af934 | 280 | |
cc359566 | 281 | } else if (empty($confirmplugins)) { |
00be1916 | 282 | $strplugincheck = get_string('plugincheck'); |
cc359566 | 283 | |
69d77c23 | 284 | $PAGE->navbar->add($strplugincheck); |
285 | $PAGE->set_title($strplugincheck); | |
52273536 | 286 | $PAGE->set_heading($strplugincheck); |
69d77c23 | 287 | $PAGE->set_cacheable(false); |
b9934a17 | 288 | |
96dd9237 DM |
289 | $reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1)); |
290 | ||
ead8ba3b DM |
291 | // check plugin dependencies first |
292 | $failed = array(); | |
293 | if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) { | |
294 | $output = $PAGE->get_renderer('core', 'admin'); | |
295 | echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl); | |
296 | die(); | |
297 | } | |
298 | unset($failed); | |
299 | ||
96dd9237 | 300 | if ($fetchupdates) { |
5a08e363 | 301 | // no sesskey support guaranteed here |
4db58f5f DM |
302 | if (empty($CFG->disableupdatenotifications)) { |
303 | available_update_checker::instance()->fetch(); | |
304 | } | |
96dd9237 DM |
305 | redirect($reloadurl); |
306 | } | |
307 | ||
cc359566 | 308 | $output = $PAGE->get_renderer('core', 'admin'); |
bcc8397a DM |
309 | |
310 | $deployer = available_update_deployer::instance(); | |
311 | if ($deployer->enabled()) { | |
312 | $deployer->initialize($reloadurl, $reloadurl); | |
313 | ||
314 | $deploydata = $deployer->submitted_data(); | |
315 | if (!empty($deploydata)) { | |
316 | echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata); | |
317 | die(); | |
318 | } | |
319 | } | |
320 | ||
96dd9237 DM |
321 | echo $output->upgrade_plugin_check_page(plugin_manager::instance(), available_update_checker::instance(), |
322 | $version, $showallplugins, $reloadurl, | |
cc359566 | 323 | new moodle_url('/admin/index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1))); |
00be1916 | 324 | die(); |
db5af934 | 325 | |
00be1916 | 326 | } else { |
327 | // Launch main upgrade | |
328 | upgrade_core($version, true); | |
88582df4 | 329 | } |
00be1916 | 330 | } else if ($version < $CFG->version) { |
80380bd7 PS |
331 | // better stop here, we can not continue with plugin upgrades or anything else |
332 | throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/')); | |
00be1916 | 333 | } |
334 | ||
335 | // Updated human-readable release version if necessary | |
336 | if ($release <> $CFG->release) { // Update the release version | |
bc76b3c0 | 337 | set_config('release', $release); |
00be1916 | 338 | } |
339 | ||
ed01233a AB |
340 | if ($branch <> $CFG->branch) { // Update the branch |
341 | set_config('branch', $branch); | |
342 | } | |
343 | ||
575f245f PS |
344 | if (moodle_needs_upgrading()) { |
345 | if (!$PAGE->headerprinted) { | |
2361b7dd | 346 | // means core upgrade or installation was not already done |
575f245f | 347 | if (!$confirmplugins) { |
cc359566 TH |
348 | $strplugincheck = get_string('plugincheck'); |
349 | ||
2361b7dd | 350 | $PAGE->set_pagelayout('maintenance'); |
d3875524 | 351 | $PAGE->set_popup_notification_allowed(false); |
575f245f PS |
352 | $PAGE->navbar->add($strplugincheck); |
353 | $PAGE->set_title($strplugincheck); | |
354 | $PAGE->set_heading($strplugincheck); | |
355 | $PAGE->set_cacheable(false); | |
b9934a17 | 356 | |
96dd9237 | 357 | if ($fetchupdates) { |
5a08e363 | 358 | // no sesskey support guaranteed here |
96dd9237 DM |
359 | available_update_checker::instance()->fetch(); |
360 | redirect($PAGE->url); | |
361 | } | |
362 | ||
cc359566 | 363 | $output = $PAGE->get_renderer('core', 'admin'); |
ead8ba3b | 364 | |
292dbeac DM |
365 | $deployer = available_update_deployer::instance(); |
366 | if ($deployer->enabled()) { | |
367 | $deployer->initialize($PAGE->url, $PAGE->url); | |
368 | ||
369 | $deploydata = $deployer->submitted_data(); | |
370 | if (!empty($deploydata)) { | |
371 | echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata); | |
372 | die(); | |
373 | } | |
374 | } | |
375 | ||
ead8ba3b DM |
376 | // check plugin dependencies first |
377 | $failed = array(); | |
378 | if (!plugin_manager::instance()->all_plugins_ok($version, $failed)) { | |
379 | echo $output->unsatisfied_dependencies_page($version, $failed, $PAGE->url); | |
380 | die(); | |
381 | } | |
382 | unset($failed); | |
383 | ||
384 | // dependencies check passed, let's rock! | |
96dd9237 DM |
385 | echo $output->upgrade_plugin_check_page(plugin_manager::instance(), available_update_checker::instance(), |
386 | $version, $showallplugins, | |
387 | new moodle_url($PAGE->url), | |
cc359566 | 388 | new moodle_url('/admin/index.php', array('confirmplugincheck'=>1))); |
575f245f PS |
389 | die(); |
390 | } | |
391 | } | |
392 | // install/upgrade all plugins and other parts | |
393 | upgrade_noncore(true); | |
394 | } | |
00be1916 | 395 | |
31a99877 | 396 | // If this is the first install, indicate that this site is fully configured |
397 | // except the admin password | |
398 | if (during_initial_install()) { | |
399 | set_config('rolesactive', 1); // after this, during_initial_install will return false. | |
00be1916 | 400 | set_config('adminsetuppending', 1); |
c8ae55e9 | 401 | // we need this redirect to setup proper session |
00be1916 | 402 | upgrade_finished("index.php?sessionstarted=1&lang=$CFG->lang"); |
403 | } | |
404 | ||
405 | // make sure admin user is created - this is the last step because we need | |
406 | // session to be working properly in order to edit admin account | |
407 | if (!empty($CFG->adminsetuppending)) { | |
408 | $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL); | |
409 | if (!$sessionstarted) { | |
410 | redirect("index.php?sessionstarted=1&lang=$CFG->lang"); | |
411 | } else { | |
412 | $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL); | |
413 | if (!$sessionverify) { | |
414 | $SESSION->sessionverify = 1; | |
415 | redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang"); | |
88582df4 | 416 | } else { |
00be1916 | 417 | if (empty($SESSION->sessionverify)) { |
418 | print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang"); | |
88582df4 | 419 | } |
00be1916 | 420 | unset($SESSION->sessionverify); |
88582df4 | 421 | } |
00be1916 | 422 | } |
88582df4 | 423 | |
4f73591a PS |
424 | // Cleanup SESSION to make sure other code does not complain in the future. |
425 | unset($SESSION->has_timed_out); | |
426 | unset($SESSION->wantsurl); | |
427 | ||
a7c9609b | 428 | // 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 |
429 | $adminids = explode(',', $CFG->siteadmins); |
430 | $adminuser = get_complete_user_data('id', reset($adminids)); | |
88582df4 | 431 | |
00be1916 | 432 | if ($adminuser->password === 'adminsetuppending') { |
433 | // prevent installation hijacking | |
434 | if ($adminuser->lastip !== getremoteaddr()) { | |
435 | print_error('installhijacked', 'admin'); | |
35d6a2a4 | 436 | } |
00be1916 | 437 | // login user and let him set password and admin details |
438 | $adminuser->newadminuser = 1; | |
0342fc36 | 439 | complete_user_login($adminuser); |
00be1916 | 440 | redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself |
db5af934 | 441 | |
5c144d60 | 442 | } else { |
00be1916 | 443 | unset_config('adminsetuppending'); |
4da1a0a1 | 444 | } |
445 | ||
00be1916 | 446 | } else { |
447 | // just make sure upgrade logging is properly terminated | |
448 | upgrade_finished('upgradesettings.php'); | |
449 | } | |
b3732604 | 450 | |
e2e35e71 PS |
451 | // Now we can be sure everything was upgraded and caches work fine, |
452 | // redirect if necessary to make sure caching is enabled. | |
bf8c71b7 | 453 | if (!$cache and !optional_param('sesskey', '', PARAM_RAW)) { |
e2e35e71 PS |
454 | redirect(new moodle_url($PAGE->url, array('cache' => 1))); |
455 | } | |
456 | ||
00be1916 | 457 | // Check for valid admin user - no guest autologin |
458 | require_login(0, false); | |
bf006d2c | 459 | $context = context_system::instance(); |
00be1916 | 460 | require_capability('moodle/site:config', $context); |
461 | ||
462 | // check that site is properly customized | |
463 | $site = get_site(); | |
464 | if (empty($site->shortname)) { | |
465 | // probably new installation - lets return to frontpage after this step | |
466 | // remove settings that we want uninitialised | |
467 | unset_config('registerauth'); | |
468 | redirect('upgradesettings.php?return=site'); | |
469 | } | |
470 | ||
471 | // Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders | |
472 | if (!empty($id) and $id == $CFG->siteidentifier) { | |
473 | set_config('registered', time()); | |
474 | } | |
475 | ||
0a6a344d DM |
476 | // Check if we are returning from an add-on installation request at moodle.org/plugins |
477 | if (!is_null($newaddonreq)) { | |
478 | if (!empty($CFG->disableonclickaddoninstall)) { | |
479 | // The feature is disabled in config.php, ignore the request. | |
480 | } else { | |
481 | redirect(new moodle_url('/admin/tool/installaddon/index.php', array( | |
482 | 'installaddonrequest' => $newaddonreq, | |
483 | 'confirm' => 0))); | |
484 | } | |
485 | } | |
486 | ||
00be1916 | 487 | // setup critical warnings before printing admin tree block |
bc76b3c0 | 488 | $insecuredataroot = is_dataroot_insecure(true); |
00be1916 | 489 | $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR); |
490 | ||
491 | $adminroot = admin_get_root(); | |
492 | ||
493 | // Check if there are any new admin settings which have still yet to be set | |
494 | if (any_new_admin_settings($adminroot)){ | |
495 | redirect('upgradesettings.php'); | |
496 | } | |
497 | ||
498 | // Everything should now be set up, and the user is an admin | |
499 | ||
500 | // Print default admin page with notifications. | |
cc359566 | 501 | $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED'); |
a95682b2 | 502 | |
00be1916 | 503 | $lastcron = $DB->get_field_sql('SELECT MAX(lastcron) FROM {modules}'); |
cc359566 TH |
504 | $cronoverdue = ($lastcron < time() - 3600 * 24); |
505 | $dbproblems = $DB->diagnose(); | |
506 | $maintenancemode = !empty($CFG->maintenance_enabled); | |
74944b73 | 507 | |
966bd785 | 508 | // Available updates for Moodle core |
55585f3a | 509 | $updateschecker = available_update_checker::instance(); |
966bd785 DM |
510 | $availableupdates = array(); |
511 | $availableupdates['core'] = $updateschecker->get_update_info('core', | |
c6f008e7 | 512 | array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds)); |
966bd785 DM |
513 | |
514 | // Available updates for contributed plugins | |
515 | $pluginman = plugin_manager::instance(); | |
516 | foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) { | |
517 | foreach ($plugintypeinstances as $pluginname => $plugininfo) { | |
518 | if (!empty($plugininfo->availableupdates)) { | |
519 | foreach ($plugininfo->availableupdates as $pluginavailableupdate) { | |
520 | if ($pluginavailableupdate->version > $plugininfo->versiondisk) { | |
521 | if (!isset($availableupdates[$plugintype.'_'.$pluginname])) { | |
522 | $availableupdates[$plugintype.'_'.$pluginname] = array(); | |
523 | } | |
524 | $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate; | |
525 | } | |
526 | } | |
527 | } | |
528 | } | |
529 | } | |
530 | ||
531 | // The timestamp of the most recent check for available updates | |
55585f3a DM |
532 | $availableupdatesfetch = $updateschecker->get_last_timefetched(); |
533 | ||
0aff15c2 | 534 | $buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€'); |
b3245b75 DP |
535 | //check if the site is registered on Moodle.org |
536 | $registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL, 'confirmed' => 1)); | |
0aff15c2 | 537 | |
cc359566 | 538 | admin_externalpage_setup('adminnotifications'); |
55585f3a DM |
539 | |
540 | if ($fetchupdates) { | |
541 | require_sesskey(); | |
542 | $updateschecker->fetch(); | |
e2e35e71 | 543 | redirect(new moodle_url('/admin/index.php')); |
55585f3a DM |
544 | } |
545 | ||
cc359566 TH |
546 | $output = $PAGE->get_renderer('core', 'admin'); |
547 | echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, | |
b3245b75 DP |
548 | $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, |
549 | $registered); |