ATÉ AQUI OK ------ if (!$cache and $version > $CFG->version) { // upgrade // Warning about upgrading a test site. $testsite = false; if (defined('BEHAT_SITE_RUNNING')) { $testsite = 'behat'; } // We purge all of MUC's caches here. // Caches are disabled for upgrade by CACHE_DISABLE_ALL so we must set the first arg to true. // This ensures a real config object is loaded and the stores will be purged. // This is the only way we can purge custom caches such as memcache or APC. // Note: all other calls to caches will still used the disabled API. cache_helper::purge_all(true); // We then purge the regular caches. purge_all_caches(); /** @var core_admin_renderer $output */ $output = $PAGE->get_renderer('core', 'admin'); if (upgrade_stale_php_files_present()) { $PAGE->set_title($stradministration); $PAGE->set_cacheable(false); echo $output->upgrade_stale_php_files_page(); die(); } if (empty($confirmupgrade)) { $a = new stdClass(); $a->oldversion = "$CFG->release (".sprintf('%.2f', $CFG->version).")"; $a->newversion = "$release (".sprintf('%.2f', $version).")"; $strdatabasechecking = get_string('databasechecking', '', $a); $PAGE->set_title($stradministration); $PAGE->set_heading($strdatabasechecking); $PAGE->set_cacheable(false); echo $output->upgrade_confirm_page($a->newversion, $maturity, $testsite); die(); } else if (empty($confirmrelease)){ require_once($CFG->libdir.'/environmentlib.php'); list($envstatus, $environment_results) = check_moodle_environment($release, ENV_SELECT_RELEASE); $strcurrentrelease = get_string('currentrelease'); $PAGE->navbar->add($strcurrentrelease); $PAGE->set_title($strcurrentrelease); $PAGE->set_heading($strcurrentrelease); $PAGE->set_cacheable(false); echo $output->upgrade_environment_page($release, $envstatus, $environment_results); die(); } else if (empty($confirmplugins)) { $strplugincheck = get_string('plugincheck'); $PAGE->navbar->add($strplugincheck); $PAGE->set_title($strplugincheck); $PAGE->set_heading($strplugincheck); $PAGE->set_cacheable(false); $reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)); if ($fetchupdates) { // No sesskey support guaranteed here, because sessions might not work yet. $updateschecker = \core\update\checker::instance(); if ($updateschecker->enabled()) { $updateschecker->fetch(); } redirect($reloadurl); } $deployer = \core\update\deployer::instance(); if ($deployer->enabled()) { $deployer->initialize($reloadurl, $reloadurl); $deploydata = $deployer->submitted_data(); if (!empty($deploydata)) { // No sesskey support guaranteed here, because sessions might not work yet. echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata); die(); } } echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(), $version, $showallplugins, $reloadurl, new moodle_url('/admin/index.php', array('confirmupgrade'=>1, 'confirmrelease'=>1, 'confirmplugincheck'=>1, 'cache'=>0))); die(); } else { // Always verify plugin dependencies! $failed = array(); if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { $reloadurl = new moodle_url('/admin/index.php', array('confirmupgrade' => 1, 'confirmrelease' => 1, 'cache' => 0)); echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl); die(); } unset($failed); // Launch main upgrade. upgrade_core($version, true); } } else if ($version < $CFG->version) { // better stop here, we can not continue with plugin upgrades or anything else throw new moodle_exception('downgradedcore', 'error', new moodle_url('/admin/')); } echo 'ATÉ AQUI OK ------' ?> // Updated human-readable release version if necessary if (!$cache and $release <> $CFG->release) { // Update the release version set_config('release', $release); } if (!$cache and $branch <> $CFG->branch) { // Update the branch set_config('branch', $branch); } if (!$cache and moodle_needs_upgrading()) { if (!$PAGE->headerprinted) { // means core upgrade or installation was not already done if (!$confirmplugins) { $strplugincheck = get_string('plugincheck'); $PAGE->navbar->add($strplugincheck); $PAGE->set_title($strplugincheck); $PAGE->set_heading($strplugincheck); $PAGE->set_cacheable(false); if ($fetchupdates) { require_sesskey(); $updateschecker = \core\update\checker::instance(); if ($updateschecker->enabled()) { $updateschecker->fetch(); } redirect($PAGE->url); } /** @var core_admin_renderer $output */ $output = $PAGE->get_renderer('core', 'admin'); $deployer = \core\update\deployer::instance(); if ($deployer->enabled()) { $deployer->initialize($PAGE->url, $PAGE->url); $deploydata = $deployer->submitted_data(); if (!empty($deploydata)) { require_sesskey(); echo $output->upgrade_plugin_confirm_deploy_page($deployer, $deploydata); die(); } } // Show plugins info. echo $output->upgrade_plugin_check_page(core_plugin_manager::instance(), \core\update\checker::instance(), $version, $showallplugins, new moodle_url($PAGE->url), new moodle_url('/admin/index.php', array('confirmplugincheck'=>1, 'cache'=>0))); die(); } // Make sure plugin dependencies are always checked. $failed = array(); if (!core_plugin_manager::instance()->all_plugins_ok($version, $failed)) { /** @var core_admin_renderer $output */ $output = $PAGE->get_renderer('core', 'admin'); $reloadurl = new moodle_url('/admin/index.php', array('cache' => 0)); echo $output->unsatisfied_dependencies_page($version, $failed, $reloadurl); die(); } unset($failed); } // install/upgrade all plugins and other parts upgrade_noncore(true); } // If this is the first install, indicate that this site is fully configured // except the admin password if (during_initial_install()) { set_config('rolesactive', 1); // after this, during_initial_install will return false. set_config('adminsetuppending', 1); // we need this redirect to setup proper session upgrade_finished("index.php?sessionstarted=1&lang=$CFG->lang"); } // make sure admin user is created - this is the last step because we need // session to be working properly in order to edit admin account if (!empty($CFG->adminsetuppending)) { $sessionstarted = optional_param('sessionstarted', 0, PARAM_BOOL); if (!$sessionstarted) { redirect("index.php?sessionstarted=1&lang=$CFG->lang"); } else { $sessionverify = optional_param('sessionverify', 0, PARAM_BOOL); if (!$sessionverify) { $SESSION->sessionverify = 1; redirect("index.php?sessionstarted=1&sessionverify=1&lang=$CFG->lang"); } else { if (empty($SESSION->sessionverify)) { print_error('installsessionerror', 'admin', "index.php?sessionstarted=1&lang=$CFG->lang"); } unset($SESSION->sessionverify); } } // Cleanup SESSION to make sure other code does not complain in the future. unset($SESSION->has_timed_out); unset($SESSION->wantsurl); // 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 $adminids = explode(',', $CFG->siteadmins); $adminuser = get_complete_user_data('id', reset($adminids)); if ($adminuser->password === 'adminsetuppending') { // prevent installation hijacking if ($adminuser->lastip !== getremoteaddr()) { print_error('installhijacked', 'admin'); } // login user and let him set password and admin details $adminuser->newadminuser = 1; complete_user_login($adminuser); redirect("$CFG->wwwroot/user/editadvanced.php?id=$adminuser->id"); // Edit thyself } else { unset_config('adminsetuppending'); } } else { // just make sure upgrade logging is properly terminated upgrade_finished('upgradesettings.php'); } if (has_capability('moodle/site:config', context_system::instance())) { if ($fetchupdates) { require_sesskey(); $updateschecker = \core\update\checker::instance(); if ($updateschecker->enabled()) { $updateschecker->fetch(); } redirect(new moodle_url('/admin/index.php', array('cache' => 0))); } } // Now we can be sure everything was upgraded and caches work fine, // redirect if necessary to make sure caching is enabled. if (!$cache) { redirect(new moodle_url('/admin/index.php', array('cache' => 1))); } // Check for valid admin user - no guest autologin require_login(0, false); if (isguestuser()) { // Login as real user! $SESSION->wantsurl = (string)new moodle_url('/admin/index.php'); redirect(get_login_url()); } $context = context_system::instance(); require_capability('moodle/site:config', $context); // check that site is properly customized $site = get_site(); if (empty($site->shortname)) { // probably new installation - lets return to frontpage after this step // remove settings that we want uninitialised unset_config('registerauth'); redirect('upgradesettings.php?return=site'); } // Check if we are returning from moodle.org registration and if so, we mark that fact to remove reminders if (!empty($id) and $id == $CFG->siteidentifier) { set_config('registered', time()); } // setup critical warnings before printing admin tree block $insecuredataroot = is_dataroot_insecure(true); $SESSION->admin_critical_warning = ($insecuredataroot==INSECURE_DATAROOT_ERROR); $adminroot = admin_get_root(); // Check if there are any new admin settings which have still yet to be set if (any_new_admin_settings($adminroot)){ redirect('upgradesettings.php'); } // Return to original page that started the plugin uninstallation if necessary. if (isset($SESSION->pluginuninstallreturn)) { $return = $SESSION->pluginuninstallreturn; unset($SESSION->pluginuninstallreturn); if ($return) { redirect($return); } } // Everything should now be set up, and the user is an admin // Print default admin page with notifications. $errorsdisplayed = defined('WARN_DISPLAY_ERRORS_ENABLED'); // We make the assumption that at least one schedule task should run once per day. $lastcron = $DB->get_field_sql('SELECT MAX(lastruntime) FROM {task_scheduled}'); $cronoverdue = ($lastcron < time() - 3600 * 24); $dbproblems = $DB->diagnose(); $maintenancemode = !empty($CFG->maintenance_enabled); // Available updates for Moodle core. $updateschecker = \core\update\checker::instance(); $availableupdates = array(); $availableupdatesfetch = null; if (empty($CFG->disableupdatenotifications)) { // Only compute the update information when it is going to be displayed to the user. $availableupdates['core'] = $updateschecker->get_update_info('core', array('minmaturity' => $CFG->updateminmaturity, 'notifybuilds' => $CFG->updatenotifybuilds)); // Available updates for contributed plugins $pluginman = core_plugin_manager::instance(); foreach ($pluginman->get_plugins() as $plugintype => $plugintypeinstances) { foreach ($plugintypeinstances as $pluginname => $plugininfo) { if (!empty($plugininfo->availableupdates)) { foreach ($plugininfo->availableupdates as $pluginavailableupdate) { if ($pluginavailableupdate->version > $plugininfo->versiondisk) { if (!isset($availableupdates[$plugintype.'_'.$pluginname])) { $availableupdates[$plugintype.'_'.$pluginname] = array(); } $availableupdates[$plugintype.'_'.$pluginname][] = $pluginavailableupdate; } } } } } // The timestamp of the most recent check for available updates $availableupdatesfetch = $updateschecker->get_last_timefetched(); } $buggyiconvnomb = (!function_exists('mb_convert_encoding') and @iconv('UTF-8', 'UTF-8//IGNORE', '100'.chr(130).'€') !== '100€'); //check if the site is registered on Moodle.org $registered = $DB->count_records('registration_hubs', array('huburl' => HUB_MOODLEORGHUBURL, 'confirmed' => 1)); // Check if there are any cache warnings. $cachewarnings = cache_helper::warnings(); admin_externalpage_setup('adminnotifications'); /* @var core_admin_renderer $output */ $output = $PAGE->get_renderer('core', 'admin'); echo $output->admin_notifications_page($maturity, $insecuredataroot, $errorsdisplayed, $cronoverdue, $dbproblems, $maintenancemode, $availableupdates, $availableupdatesfetch, $buggyiconvnomb, $registered, $cachewarnings);