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 | |
dbe0203b | 33 | if (version_compare(phpversion(), '5.4.4') < 0) { |
00be1916 | 34 | $phpversion = phpversion(); |
35 | // do NOT localise - lang strings would not work here and we CAN NOT move it to later place | |
dbe0203b | 36 | echo "Moodle 2.7 or later requires at least PHP 5.4.4 (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 | |
3c9535dd JC |
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.'; | |
52 | die(); | |
53 | } | |
54 | ||
cbad562e | 55 | define('NO_OUTPUT_BUFFERING', true); |
00be1916 | 56 | |
98b32c9e DM |
57 | if (isset($_POST['upgradekey'])) { |
58 | // Before you start reporting issues about the collision attacks against | |
59 | // SHA-1, you should understand that we are not actually attempting to do | |
60 | // any cryptography here. This is hashed purely so that the key is not | |
61 | // that apparent in the address bar itself. Anyone who catches the HTTP | |
62 | // traffic can immediately use it as a valid admin key. | |
63 | header('Location: index.php?cache=0&upgradekeyhash='.sha1($_POST['upgradekey'])); | |
64 | die(); | |
65 | } | |
66 | ||
fc281113 PS |
67 | if ((isset($_GET['cache']) and $_GET['cache'] === '0') |
68 | or (isset($_POST['cache']) and $_POST['cache'] === '0') | |
69 | or (!isset($_POST['cache']) and !isset($_GET['cache']) and empty($_GET['sesskey']) and empty($_POST['sesskey']))) { | |
e2e35e71 PS |
70 | // Prevent caching at all cost when visiting this page directly, |
71 | // we redirect to self once we known no upgrades are necessary. | |
72 | // Note: $_GET and $_POST are used here intentionally because our param cleaning is not loaded yet. | |
bf8c71b7 | 73 | // Note2: the sesskey is present in all block editing hacks, we can not redirect there, so enable caching. |
e2e35e71 | 74 | define('CACHE_DISABLE_ALL', true); |
c05a5099 PS |
75 | |
76 | // Force OPcache reset if used, we do not want any stale caches | |
77 | // when detecting if upgrade necessary or when running upgrade. | |
78 | if (function_exists('opcache_reset')) { | |
79 | opcache_reset(); | |
80 | } | |
82b1cf00 PS |
81 | $cache = 0; |
82 | ||
83 | } else { | |
84 | $cache = 1; | |
e2e35e71 PS |
85 | } |
86 | ||
00be1916 | 87 | require('../config.php'); |
3274c5db FM |
88 | |
89 | // Invalidate the cache of version.php in any circumstances to help core_component | |
90 | // detecting if the version has changed and component cache should be reset. | |
91 | if (function_exists('opcache_invalidate')) { | |
92 | opcache_invalidate($CFG->dirroot . '/version.php', true); | |
93 | } | |
94 | // Make sure the component cache gets rebuilt if necessary, any method that | |
95 | // indirectly calls the protected init() method is good here. | |
96 | core_component::get_core_subsystems(); | |
97 | ||
bc76b3c0 | 98 | require_once($CFG->libdir.'/adminlib.php'); // various admin-only functions |
99 | require_once($CFG->libdir.'/upgradelib.php'); // general upgrade/install related functions | |
00be1916 | 100 | |
00be1916 | 101 | $confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL); |
102 | $confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL); | |
103 | $confirmplugins = optional_param('confirmplugincheck', 0, PARAM_BOOL); | |
b9934a17 | 104 | $showallplugins = optional_param('showallplugins', 0, PARAM_BOOL); |
00be1916 | 105 | $agreelicense = optional_param('agreelicense', 0, PARAM_BOOL); |
55585f3a | 106 | $fetchupdates = optional_param('fetchupdates', 0, PARAM_BOOL); |
0a6a344d | 107 | $newaddonreq = optional_param('installaddonrequest', null, PARAM_RAW); |
98b32c9e | 108 | $upgradekeyhash = optional_param('upgradekeyhash', null, PARAM_ALPHANUM); |
00be1916 | 109 | |
e2e35e71 PS |
110 | // Set up PAGE. |
111 | $url = new moodle_url('/admin/index.php'); | |
fc281113 | 112 | $url->param('cache', $cache); |
98b32c9e DM |
113 | if (isset($upgradekeyhash)) { |
114 | $url->param('upgradekeyhash', $upgradekeyhash); | |
115 | } | |
e2e35e71 PS |
116 | $PAGE->set_url($url); |
117 | unset($url); | |
118 | ||
82b1cf00 | 119 | // Are we returning from an add-on installation request at moodle.org/plugins? |
835f58eb | 120 | if ($newaddonreq and !$cache and empty($CFG->disableonclickaddoninstall)) { |
82b1cf00 PS |
121 | $target = new moodle_url('/admin/tool/installaddon/index.php', array( |
122 | 'installaddonrequest' => $newaddonreq, | |
123 | 'confirm' => 0)); | |
124 | if (!isloggedin() or isguestuser()) { | |
125 | // Login and go the the add-on tool page. | |
126 | $SESSION->wantsurl = $target->out(); | |
127 | redirect(get_login_url()); | |
128 | } | |
129 | redirect($target); | |
130 | } | |
131 | ||
6d80fad4 | 132 | $PAGE->set_pagelayout('admin'); // Set a default pagelayout |
ee73b1ff | 133 | |
00be1916 | 134 | $documentationlink = '<a href="http://docs.moodle.org/en/Installation">Installation docs</a>'; |
135 | ||
e2e35e71 PS |
136 | // Check some PHP server settings |
137 | ||
00be1916 | 138 | if (ini_get_bool('session.auto_start')) { |
139 | print_error('phpvaroff', 'debug', '', (object)array('name'=>'session.auto_start', 'link'=>$documentationlink)); | |
140 | } | |
141 | ||
00be1916 | 142 | if (!ini_get_bool('file_uploads')) { |
143 | print_error('phpvaron', 'debug', '', (object)array('name'=>'file_uploads', 'link'=>$documentationlink)); | |
144 | } | |
145 | ||
146 | if (is_float_problem()) { | |
147 | print_error('phpfloatproblem', 'admin', '', $documentationlink); | |
148 | } | |
149 | ||
00be1916 | 150 | // Set some necessary variables during set-up to avoid PHP warnings later on this page |
00be1916 | 151 | if (!isset($CFG->release)) { |
bc76b3c0 | 152 | $CFG->release = ''; |
00be1916 | 153 | } |
154 | if (!isset($CFG->version)) { | |
bc76b3c0 | 155 | $CFG->version = ''; |
00be1916 | 156 | } |
ad394588 AB |
157 | if (!isset($CFG->branch)) { |
158 | $CFG->branch = ''; | |
159 | } | |
00be1916 | 160 | |
161 | $version = null; | |
162 | $release = null; | |
ed01233a AB |
163 | $branch = null; |
164 | require("$CFG->dirroot/version.php"); // defines $version, $release, $branch and $maturity | |
00be1916 | 165 | $CFG->target_release = $release; // used during installation and upgrades |
166 | ||
167 | if (!$version or !$release) { | |
168 | print_error('withoutversion', 'debug'); // without version, stop | |
169 | } | |
170 | ||
3316fe24 | 171 | if (!core_tables_exist()) { |
78946b9b | 172 | $PAGE->set_pagelayout('maintenance'); |
d3875524 | 173 | $PAGE->set_popup_notification_allowed(false); |
00be1916 | 174 | |
175 | // fake some settings | |
176 | $CFG->docroot = 'http://docs.moodle.org'; | |
177 | ||
178 | $strinstallation = get_string('installation', 'install'); | |
179 | ||
180 | // remove current session content completely | |
d79d5ac2 | 181 | \core\session\manager::terminate_current(); |
00be1916 | 182 | |
183 | if (empty($agreelicense)) { | |
184 | $strlicense = get_string('license'); | |
cc359566 | 185 | |
69d77c23 | 186 | $PAGE->navbar->add($strlicense); |
187 | $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release); | |
188 | $PAGE->set_heading($strinstallation); | |
189 | $PAGE->set_cacheable(false); | |
cc359566 | 190 | |
82b1cf00 | 191 | /** @var core_admin_renderer $output */ |
da2fdc3f | 192 | $output = $PAGE->get_renderer('core', 'admin'); |
cc359566 | 193 | echo $output->install_licence_page(); |
3ba28588 | 194 | die(); |
249ab745 | 195 | } |
00be1916 | 196 | if (empty($confirmrelease)) { |
cc359566 TH |
197 | require_once($CFG->libdir.'/environmentlib.php'); |
198 | list($envstatus, $environment_results) = check_moodle_environment(normalize_version($release), ENV_SELECT_RELEASE); | |
bc76b3c0 | 199 | $strcurrentrelease = get_string('currentrelease'); |
cc359566 | 200 | |
69d77c23 | 201 | $PAGE->navbar->add($strcurrentrelease); |
1a4d6a5b DM |
202 | $PAGE->set_title($strinstallation); |
203 | $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release); | |
69d77c23 | 204 | $PAGE->set_cacheable(false); |
249ab745 | 205 | |
82b1cf00 | 206 | /** @var core_admin_renderer $output */ |
cc359566 | 207 | $output = $PAGE->get_renderer('core', 'admin'); |
8d1da748 | 208 | echo $output->install_environment_page($maturity, $envstatus, $environment_results, $release); |
3ba28588 | 209 | die(); |
1dd24519 | 210 | } |
211 | ||
39f15cc7 DM |
212 | // check plugin dependencies |
213 | $failed = array(); | |
e87214bd | 214 | if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { |
39f15cc7 DM |
215 | $PAGE->navbar->add(get_string('pluginscheck', 'admin')); |
216 | $PAGE->set_title($strinstallation); | |
217 | $PAGE->set_heading($strinstallation . ' - Moodle ' . $CFG->target_release); | |
218 | ||
219 | $output = $PAGE->get_renderer('core', 'admin'); | |
98b32c9e | 220 | $url = new moodle_url($PAGE->url, array('agreelicense' => 1, 'confirmrelease' => 1, 'lang' => $CFG->lang)); |
39f15cc7 DM |
221 | echo $output->unsatisfied_dependencies_page($version, $failed, $url); |
222 | die(); | |
223 | } | |
224 | unset($failed); | |
225 | ||
8d1da748 PS |
226 | //TODO: add a page with list of non-standard plugins here |
227 | ||
bc76b3c0 | 228 | $strdatabasesetup = get_string('databasesetup'); |
543f54d3 | 229 | upgrade_init_javascript(); |
cc359566 | 230 | |
69d77c23 | 231 | $PAGE->navbar->add($strdatabasesetup); |
232 | $PAGE->set_title($strinstallation.' - Moodle '.$CFG->target_release); | |
2ea05146 | 233 | $PAGE->set_heading($strinstallation); |
69d77c23 | 234 | $PAGE->set_cacheable(false); |
cc359566 | 235 | |
da2fdc3f TH |
236 | $output = $PAGE->get_renderer('core', 'admin'); |
237 | echo $output->header(); | |
d02bc6ce | 238 | |
00be1916 | 239 | if (!$DB->setup_is_unicodedb()) { |
240 | if (!$DB->change_db_encoding()) { | |
241 | // If could not convert successfully, throw error, and prevent installation | |
242 | print_error('unicoderequired', 'admin'); | |
db5af934 | 243 | } |
db5af934 | 244 | } |
90509582 | 245 | |
00be1916 | 246 | install_core($version, true); |
247 | } | |
db5af934 | 248 | |
db5af934 | 249 | |
00be1916 | 250 | // Check version of Moodle code on disk compared with database |
251 | // and upgrade if possible. | |
db5af934 | 252 | |
1a361486 PS |
253 | if (!$cache) { |
254 | // Do not try to do anything fancy in non-cached mode, | |
255 | // this prevents themes from fetching data from non-existent tables. | |
256 | $PAGE->set_pagelayout('maintenance'); | |
257 | $PAGE->set_popup_notification_allowed(false); | |
258 | } | |
259 | ||
00be1916 | 260 | $stradministration = get_string('administration'); |
bf006d2c | 261 | $PAGE->set_context(context_system::instance()); |
db5af934 | 262 | |
00be1916 | 263 | if (empty($CFG->version)) { |
264 | print_error('missingconfigversion', 'debug'); | |
265 | } | |
db5af934 | 266 | |
e2e35e71 | 267 | // Detect config cache inconsistency, this happens when you switch branches on dev servers. |
82b1cf00 PS |
268 | if ($CFG->version != $DB->get_field('config', 'value', array('name'=>'version'))) { |
269 | purge_all_caches(); | |
98b32c9e | 270 | redirect(new moodle_url($PAGE->url), 'Config cache inconsistency detected, resetting caches...'); |
e2e35e71 PS |
271 | } |
272 | ||
82b1cf00 | 273 | if (!$cache and $version > $CFG->version) { // upgrade |
6e09cf98 | 274 | |
98b32c9e DM |
275 | check_upgrade_key($upgradekeyhash); |
276 | ||
6e09cf98 DM |
277 | // Warning about upgrading a test site. |
278 | $testsite = false; | |
279 | if (defined('BEHAT_SITE_RUNNING')) { | |
280 | $testsite = 'behat'; | |
281 | } | |
282 | ||
b0dd08dd SH |
283 | // We purge all of MUC's caches here. |
284 | // Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true. | |
285 | // This ensures a real config object is loaded and the stores will be purged. | |
286 | // This is the only way we can purge custom caches such as memcache or APC. | |
287 | // Note: all other calls to caches will still used the disabled API. | |
288 | cache_helper::purge_all(true); | |
289 | // We then purge the regular caches. | |
a95682b2 | 290 | purge_all_caches(); |
33082590 | 291 | |
fc281113 PS |
292 | /** @var core_admin_renderer $output */ |
293 | $output = $PAGE->get_renderer('core', 'admin'); | |
294 | ||
9008ec16 PS |
295 | if (upgrade_stale_php_files_present()) { |
296 | $PAGE->set_title($stradministration); | |
297 | $PAGE->set_cacheable(false); | |
298 | ||
9008ec16 PS |
299 | echo $output->upgrade_stale_php_files_page(); |
300 | die(); | |
301 | } | |
302 | ||
00be1916 | 303 | if (empty($confirmupgrade)) { |
17854cb9 | 304 | $a = new stdClass(); |
c22a579b RT |
305 | $a->oldversion = "$CFG->release (".sprintf('%.2f', $CFG->version).")"; |
306 | $a->newversion = "$release (".sprintf('%.2f', $version).")"; | |
cc359566 TH |
307 | $strdatabasechecking = get_string('databasechecking', '', $a); |
308 | ||
1a4d6a5b DM |
309 | $PAGE->set_title($stradministration); |
310 | $PAGE->set_heading($strdatabasechecking); | |
69d77c23 | 311 | $PAGE->set_cacheable(false); |
cc359566 | 312 | |
6e09cf98 | 313 | echo $output->upgrade_confirm_page($a->newversion, $maturity, $testsite); |
3ba28588 | 314 | die(); |
db5af934 | 315 | |
00be1916 | 316 | } else if (empty($confirmrelease)){ |
cc359566 TH |
317 | require_once($CFG->libdir.'/environmentlib.php'); |
318 | list($envstatus, $environment_results) = check_moodle_environment($release, ENV_SELECT_RELEASE); | |
bc76b3c0 | 319 | $strcurrentrelease = get_string('currentrelease'); |
cc359566 | 320 | |
69d77c23 | 321 | $PAGE->navbar->add($strcurrentrelease); |
322 | $PAGE->set_title($strcurrentrelease); | |
52273536 | 323 | $PAGE->set_heading($strcurrentrelease); |
69d77c23 | 324 | $PAGE->set_cacheable(false); |
db5af934 | 325 | |
faadd326 TH |
326 | echo $output->upgrade_environment_page($release, $envstatus, $environment_results); |
327 | die(); | |
db5af934 | 328 | |
cc359566 | 329 | } else if (empty($confirmplugins)) { |
00be1916 | 330 | $strplugincheck = get_string('plugincheck'); |
cc359566 | 331 | |
69d77c23 | 332 | $PAGE->navbar->add($strplugincheck); |
333 | $PAGE->set_title($strplugincheck); | |
52273536 | 334 | $PAGE->set_heading($strplugincheck); |
69d77c23 | 335 | $PAGE->set_cacheable(false); |
b9934a17 | 336 | |
98b32c9e | 337 | $reloadurl = new moodle_url($PAGE->url, array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)); |
ead8ba3b | 338 | |
96dd9237 | 339 | if ($fetchupdates) { |
fc281113 PS |
340 | // No sesskey support guaranteed here, because sessions might not work yet. |
341 | $updateschecker = \core\update\checker::instance(); | |
342 | if ($updateschecker->enabled()) { | |
343 | $updateschecker->fetch(); | |
4db58f5f | 344 | } |
96dd9237 DM |
345 | redirect($reloadurl); |
346 | } | |
347 | ||
e87214bd | 348 | $deployer = \core\update\deployer::instance(); |
bcc8397a DM |
349 | if ($deployer->enabled()) { |
350 | $deployer->initialize($reloadurl, $reloadurl); | |
351 | ||
352 | $deploydata = $deployer->submitted_data(); | |
353 | if (!empty($deploydata)) { | |
fc281113 | 354 | // No sesskey support guaranteed here, because sessions might not work yet. |
bcc8397a DM |
355 | echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata); |
356 | die(); | |
357 | } | |
358 | } | |
359 | ||
e87214bd | 360 | echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(), |
98b32c9e DM |
361 | $version, $showallplugins, $reloadurl, new moodle_url($PAGE->url, array( |
362 | 'confirmupgrade' => 1, 'confirmrelease' => 1, 'confirmplugincheck' => 1, 'cache' => 0))); | |
00be1916 | 363 | die(); |
db5af934 | 364 | |
00be1916 | 365 | } else { |
fc281113 PS |
366 | // Always verify plugin dependencies! |
367 | $failed = array(); | |
368 | if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { | |
98b32c9e | 369 | $reloadurl = new moodle_url($PAGE->url, array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)); |
fc281113 PS |
370 | echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl); |
371 | die(); | |
372 | } | |
373 | unset($failed); | |
374 | ||
375 | // Launch main upgrade. | |
00be1916 | 376 | upgrade_core($version, true); |
88582df4 | 377 | } |
00be1916 | 378 | } else if ($version < $CFG->version) { |
80380bd7 PS |
379 | // better stop here, we can not continue with plugin upgrades or anything else |
380 | throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/')); | |
00be1916 | 381 | } |
382 | ||
383 | // Updated human-readable release version if necessary | |
82b1cf00 | 384 | if (!$cache and $release <> $CFG->release) { // Update the release version |
bc76b3c0 | 385 | set_config('release', $release); |
00be1916 | 386 | } |
387 | ||
82b1cf00 | 388 | if (!$cache and $branch <> $CFG->branch) { // Update the branch |
ed01233a AB |
389 | set_config('branch', $branch); |
390 | } | |
391 | ||
82b1cf00 | 392 | if (!$cache and moodle_needs_upgrading()) { |
98b32c9e DM |
393 | |
394 | check_upgrade_key($upgradekeyhash); | |
395 | ||
575f245f | 396 | if (!$PAGE->headerprinted) { |
2361b7dd | 397 | // means core upgrade or installation was not already done |
fc281113 | 398 | |
575f245f | 399 | if (!$confirmplugins) { |
cc359566 TH |
400 | $strplugincheck = get_string('plugincheck'); |
401 | ||
575f245f PS |
402 | $PAGE->navbar->add($strplugincheck); |
403 | $PAGE->set_title($strplugincheck); | |
404 | $PAGE->set_heading($strplugincheck); | |
405 | $PAGE->set_cacheable(false); | |
b9934a17 | 406 | |
96dd9237 | 407 | if ($fetchupdates) { |
fc281113 PS |
408 | require_sesskey(); |
409 | $updateschecker = \core\update\checker::instance(); | |
410 | if ($updateschecker->enabled()) { | |
411 | $updateschecker->fetch(); | |
412 | } | |
96dd9237 DM |
413 | redirect($PAGE->url); |
414 | } | |
415 | ||
12890c57 SH |
416 | /** @var core_admin_renderer $output */ |
417 | $output = $PAGE->get_renderer('core', 'admin'); | |
418 | ||
e87214bd | 419 | $deployer = \core\update\deployer::instance(); |
292dbeac DM |
420 | if ($deployer->enabled()) { |
421 | $deployer->initialize($PAGE->url, $PAGE->url); | |
422 | ||
423 | $deploydata = $deployer->submitted_data(); | |
424 | if (!empty($deploydata)) { | |
fc281113 | 425 | require_sesskey(); |
292dbeac DM |
426 | echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata); |
427 | die(); | |
428 | } | |
429 | } | |
430 | ||
fc281113 | 431 | // Show plugins info. |
e87214bd | 432 | echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(), |
96dd9237 DM |
433 | $version, $showallplugins, |
434 | new moodle_url($PAGE->url), | |
98b32c9e | 435 | new moodle_url($PAGE->url, array('confirmplugincheck' => 1, 'cache' => 0))); |
fc281113 PS |
436 | die(); |
437 | } | |
438 | ||
439 | // Make sure plugin dependencies are always checked. | |
440 | $failed = array(); | |
441 | if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { | |
12890c57 SH |
442 | /** @var core_admin_renderer $output */ |
443 | $output = $PAGE->get_renderer('core', 'admin'); | |
98b32c9e | 444 | $reloadurl = new moodle_url($PAGE->url, array('cache' => 0)); |
fc281113 | 445 | echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl); |
575f245f PS |
446 | die(); |
447 | } | |
fc281113 | 448 | unset($failed); |
575f245f | 449 | } |
fc281113 | 450 | |
575f245f PS |
451 | // install/upgrade all plugins and other parts |
452 | upgrade_noncore(true); | |
453 | } | |
00be1916 | 454 | |
31a99877 | 455 | // If this is the first install, indicate that this site is fully configured |
456 | // except the admin password | |
457 | if (during_initial_install()) { | |
458 | set_config('rolesactive', 1); // after this, during_initial_install will return false. | |
00be1916 | 459 | set_config('adminsetuppending', 1); |
c8ae55e9 | 460 | // we need this redirect to setup proper session |
00be1916 | 461 | upgrade_finished("index.php?sessionstarted=1&lang=$CFG->lang"); |
462 | } | |
463 | ||
464 | // make sure admin user is created - this is the last step because we need | |
465 | // session to be working properly in order to edit admin account | |
466 | if (!empty($CFG->adminsetuppending)) { | |
467 | $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL); | |
468 | if (!$sessionstarted) { | |
469 | redirect("index.php?sessionstarted=1&lang=$CFG->lang"); | |
470 | } else { | |
471 | $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL); | |
472 | if (!$sessionverify) { | |
473 | $SESSION->sessionverify = 1; | |
474 | redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang"); | |
88582df4 | 475 | } else { |
00be1916 | 476 | if (empty($SESSION->sessionverify)) { |
477 | print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang"); | |
88582df4 | 478 | } |
00be1916 | 479 | unset($SESSION->sessionverify); |
88582df4 | 480 | } |
00be1916 | 481 | } |
88582df4 | 482 | |
4f73591a PS |
483 | // Cleanup SESSION to make sure other code does not complain in the future. |
484 | unset($SESSION->has_timed_out); | |
485 | unset($SESSION->wantsurl); | |
486 | ||
a7c9609b | 487 | // 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 |
488 | $adminids = explode(',', $CFG->siteadmins); |
489 | $adminuser = get_complete_user_data('id', reset($adminids)); | |
88582df4 | 490 | |
00be1916 | 491 | if ($adminuser->password === 'adminsetuppending') { |
492 | // prevent installation hijacking | |
493 | if ($adminuser->lastip !== getremoteaddr()) { | |
494 | print_error('installhijacked', 'admin'); | |
35d6a2a4 | 495 | } |
00be1916 | 496 | // login user and let him set password and admin details |
497 | $adminuser->newadminuser = 1; | |
0342fc36 | 498 | complete_user_login($adminuser); |
00be1916 | 499 | redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself |
db5af934 | 500 | |
5c144d60 | 501 | } else { |
00be1916 | 502 | unset_config('adminsetuppending'); |
4da1a0a1 | 503 | } |
504 | ||
00be1916 | 505 | } else { |
506 | // just make sure upgrade logging is properly terminated | |
507 | upgrade_finished('upgradesettings.php'); | |
508 | } | |
b3732604 | 509 | |
fc281113 PS |
510 | if (has_capability('moodle/site:config', context_system::instance())) { |
511 | if ($fetchupdates) { | |
512 | require_sesskey(); | |
513 | $updateschecker = \core\update\checker::instance(); | |
514 | if ($updateschecker->enabled()) { | |
515 | $updateschecker->fetch(); | |
516 | } | |
517 | redirect(new moodle_url('/admin/index.php', array('cache' => 0))); | |
518 | } | |
519 | } | |
520 | ||
e2e35e71 PS |
521 | // Now we can be sure everything was upgraded and caches work fine, |
522 | // redirect if necessary to make sure caching is enabled. | |
82b1cf00 PS |
523 | if (!$cache) { |
524 | redirect(new moodle_url('/admin/index.php', array('cache' => 1))); | |
e2e35e71 PS |
525 | } |
526 | ||
00be1916 | 527 | // Check for valid admin user - no guest autologin |
528 | require_login(0, false); | |
fc1d0e82 PŠ |
529 | if (isguestuser()) { |
530 | // Login as real user! | |
531 | $SESSION->wantsurl = (string)new moodle_url('/admin/index.php'); | |
532 | redirect(get_login_url()); | |
533 | } | |
bf006d2c | 534 | $context = context_system::instance(); |
336a8433 MG |
535 | |
536 | if (!has_capability('moodle/site:config', $context)) { | |
537 | // Do not throw exception display an empty page with administration menu if visible for current user. | |
538 | $PAGE->set_title($SITE->fullname); | |
539 | $PAGE->set_heading($SITE->fullname); | |
540 | echo $OUTPUT->header(); | |
541 | echo $OUTPUT->footer(); | |
542 | exit; | |
543 | } | |
00be1916 | 544 | |
545 | // check that site is properly customized | |
546 | $site = get_site(); | |
547 | if (empty($site->shortname)) { | |
548 | // probably new installation - lets return to frontpage after this step | |
549 | // remove settings that we want uninitialised | |
550 | unset_config('registerauth'); | |
d6e7a63d | 551 | unset_config('timezone'); // Force admin to select timezone! |
00be1916 | 552 | redirect('upgradesettings.php?return=site'); |
553 | } | |
554 | ||
00be1916 | 555 | // setup critical warnings before printing admin tree block |
bc76b3c0 | 556 | $insecuredataroot = is_dataroot_insecure(true); |
00be1916 | 557 | $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR); |
558 | ||
559 | $adminroot = admin_get_root(); | |
560 | ||
561 | // Check if there are any new admin settings which have still yet to be set | |
562 | if (any_new_admin_settings($adminroot)){ | |
563 | redirect('upgradesettings.php'); | |
564 | } | |
565 | ||
e87214bd PS |
566 | // Return to original page that started the plugin uninstallation if necessary. |
567 | if (isset($SESSION->pluginuninstallreturn)) { | |
568 | $return = $SESSION->pluginuninstallreturn; | |
569 | unset($SESSION->pluginuninstallreturn); | |
570 | if ($return) { | |
571 | redirect($return); | |
572 | } | |
573 | } | |
574 | ||
00be1916 | 575 | // Everything should now be set up, and the user is an admin |
576 | ||
577 | // Print default admin page with notifications. | |
cc359566 | 578 | $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED'); |
a95682b2 | 579 | |
d5fcf4b4 DP |
580 | // We make the assumption that at least one schedule task should run once per day. |
581 | $lastcron = $DB->get_field_sql('SELECT MAX(lastruntime) FROM {task_scheduled}'); | |
cc359566 TH |
582 | $cronoverdue = ($lastcron < time() - 3600 * 24); |
583 | $dbproblems = $DB->diagnose(); | |
584 | $maintenancemode = !empty($CFG->maintenance_enabled); | |
74944b73 | 585 | |
ca6f3a8b | 586 | // Available updates for Moodle core. |
e87214bd | 587 | $updateschecker = \core\update\checker::instance(); |
966bd785 | 588 | $availableupdates = array(); |
ca6f3a8b FM |
589 | $availableupdatesfetch = null; |
590 | ||
e9d3c212 | 591 | if ($updateschecker->enabled()) { |
ca6f3a8b FM |
592 | // Only compute the update information when it is going to be displayed to the user. |
593 | $availableupdates['core'] = $updateschecker->get_update_info('core', | |
594 | array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds)); | |
595 | ||
596 | // Available updates for contributed plugins | |
597 | $pluginman = core_plugin_manager::instance(); | |
598 | foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) { | |
599 | foreach ($plugintypeinstances as $pluginname => $plugininfo) { | |
30d8bc5f DM |
600 | $pluginavailableupdates = $plugininfo->available_updates(); |
601 | if (!empty($pluginavailableupdates)) { | |
602 | foreach ($pluginavailableupdates as $pluginavailableupdate) { | |
603 | if (!isset($availableupdates[$plugintype.'_'.$pluginname])) { | |
604 | $availableupdates[$plugintype.'_'.$pluginname] = array(); | |
966bd785 | 605 | } |
30d8bc5f | 606 | $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate; |
966bd785 DM |
607 | } |
608 | } | |
609 | } | |
610 | } | |
966bd785 | 611 | |
ca6f3a8b FM |
612 | // The timestamp of the most recent check for available updates |
613 | $availableupdatesfetch = $updateschecker->get_last_timefetched(); | |
614 | } | |
55585f3a | 615 | |
0aff15c2 | 616 | $buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€'); |
b3245b75 DP |
617 | //check if the site is registered on Moodle.org |
618 | $registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL, 'confirmed' => 1)); | |
915140c9 SH |
619 | // Check if there are any cache warnings. |
620 | $cachewarnings = cache_helper::warnings(); | |
0aff15c2 | 621 | |
cc359566 | 622 | admin_externalpage_setup('adminnotifications'); |
55585f3a | 623 | |
915140c9 | 624 | /* @var core_admin_renderer $output */ |
cc359566 | 625 | $output = $PAGE->get_renderer('core', 'admin'); |
915140c9 SH |
626 | |
627 | echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems, | |
628 | $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, | |
629 | $registered, $cachewarnings); |