libdir.'/adminlib.php'); // Contains various admin-only functions
require_once($CFG->libdir.'/ddllib.php'); // Install/upgrade related db functions
$id = optional_param('id', '', PARAM_ALPHANUM);
$confirmupgrade = optional_param('confirmupgrade', 0, PARAM_BOOL);
$confirmrelease = optional_param('confirmrelease', 0, PARAM_BOOL);
$agreelicence = optional_param('agreelicence',0, PARAM_BOOL);
$ignoreupgradewarning = optional_param('ignoreupgradewarning', 0, PARAM_BOOL);
/// check upgrade status first
if ($ignoreupgradewarning and !empty($_SESSION['upgraderunning'])) {
$_SESSION['upgraderunning'] = 0;
}
upgrade_check_running("Upgrade already running in this session, please wait!
Click on the exclamation marks to ignore this warning (!!!).", 10);
/// Check some PHP server settings
$documentationlink = 'Installation docs';
if (ini_get_bool('session.auto_start')) {
error("The PHP server variable 'session.auto_start' should be Off - $documentationlink");
}
if (ini_get_bool('magic_quotes_runtime')) {
error("The PHP server variable 'magic_quotes_runtime' should be Off - $documentationlink");
}
if (!ini_get_bool('file_uploads')) {
error("The PHP server variable 'file_uploads' is not turned On - $documentationlink");
}
if (empty($CFG->prefix) && $CFG->dbtype != 'mysql') { //Enforce prefixes for everybody but mysql
error('$CFG->prefix can\'t be empty for your target DB (' . $CFG->dbtype . ')');
}
if ($CFG->dbtype == 'oci8po' && strlen($CFG->prefix) > 2) { //Max prefix length for Oracle is 2cc
error('$CFG->prefix maximum allowed length for Oracle DBs is 2cc.');
}
/// Check that config.php has been edited
if ($CFG->wwwroot == "http://example.com/moodle") {
error("Moodle has not been configured yet. You need to edit config.php first.");
}
/// Check settings in config.php
$dirroot = dirname(realpath("../index.php"));
if (!empty($dirroot) and $dirroot != $CFG->dirroot) {
error("Please fix your settings in config.php:
You have:
\$CFG->dirroot = \"".addslashes($CFG->dirroot)."\";
but it should be:
\$CFG->dirroot = \"".addslashes($dirroot)."\";",
"./");
}
/// Set some necessary variables during set-up to avoid PHP warnings later on this page
if (!isset($CFG->framename)) {
$CFG->framename = "_top";
}
if (!isset($CFG->release)) {
$CFG->release = "";
}
if (!isset($CFG->version)) {
$CFG->version = "";
}
/// Check if the main tables have been installed yet or not.
if (! $tables = $db->Metatables() ) { // No tables yet at all.
$maintables = false;
} else { // Check for missing main tables
$maintables = true;
$mtables = array("config", "course", "course_categories", "course_modules",
"course_sections", "log", "log_display", "modules",
"user");
foreach ($mtables as $mtable) {
if (!in_array($CFG->prefix.$mtable, $tables)) {
$maintables = false;
break;
}
}
}
$linktoscrolltoerrors = '';
if (! $maintables) {
/// hide errors from headers in case debug enabled in config.php
$origdebug = $CFG->debug;
$CFG->debug = DEBUG_MINIMAL;
error_reporting($CFG->debug);
if (empty($agreelicence)) {
$strlicense = get_string("license");
print_header($strlicense, $strlicense, $strlicense, "", "", false, " ", " ");
print_heading("Moodle - Modular Object-Oriented Dynamic Learning Environment");
print_heading(get_string("copyrightnotice"));
print_simple_box_start('center');
echo text_to_html(get_string("gpl"));
print_simple_box_end();
echo "
";
notice_yesno(get_string("doyouagree"), "index.php?agreelicence=true",
"http://docs.moodle.org/en/License");
exit;
}
$strdatabasesetup = get_string("databasesetup");
$strdatabasesuccess = get_string("databasesuccess");
print_header($strdatabasesetup, $strdatabasesetup, $strdatabasesetup,
"", $linktoscrolltoerrors, false, " ", " ");
/// return to original debugging level
$CFG->debug = $origdebug;
error_reporting($CFG->debug);
upgrade_log_start();
$db->debug = true;
/// Both old .sql files and new install.xml are supported
/// But we prioritise install.xml (XMLDB) if present
change_db_encoding(); // first try to change db encoding to utf8
$status = false;
if (file_exists("$CFG->libdir/db/install.xml")) {
$status = install_from_xmldb_file("$CFG->libdir/db/install.xml"); //New method
} else if (file_exists("$CFG->libdir/db/$CFG->dbtype.sql")) {
$status = modify_database("$CFG->libdir/db/$CFG->dbtype.sql"); //Old method
} else {
error("Error: Your database ($CFG->dbtype) is not yet fully supported by Moodle or install.xml is not present. See the lib/db directory.");
}
/// Continue with the instalation
$db->debug = false;
if ($status) {
// Install the roles system.
moodle_install_roles();
set_config('statsrolesupgraded',time());
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
// (this should only have any effect during initial install).
$adminroot = admin_get_root();
$adminroot->prune('backups'); // backup settings table not created yet
apply_default_settings($adminroot);
/// This is used to handle any settings that must exist in $CFG but which do not exist in
/// admin_get_root()/$ADMIN as admin_setting objects (there are some exceptions).
apply_default_exception_settings(array('alternateloginurl' => '',
'auth' => 'email',
'auth_pop3mailbox' => 'INBOX',
'changepassword' => '',
'enrol' => 'manual',
'enrol_plugins_enabled' => 'manual',
'guestloginbutton' => 1,
'style' => 'default',
'template' => 'default',
'theme' => 'standardwhite'));
notify($strdatabasesuccess, "green");
} else {
error("Error: Main databases NOT set up successfully");
}
print_continue('index.php');
die;
}
/// Check version of Moodle code on disk compared with database
/// and upgrade if possible.
if ( is_readable("$CFG->dirroot/version.php")) {
include_once("$CFG->dirroot/version.php"); # defines $version
}
if (!$version) {
error('Main version.php was not readable or specified');# without version, stop
}
if (file_exists("$CFG->dirroot/lib/db/$CFG->dbtype.php")) {
include_once("$CFG->dirroot/lib/db/$CFG->dbtype.php"); # defines old upgrades
}
if (file_exists("$CFG->dirroot/lib/db/upgrade.php")) {
include_once("$CFG->dirroot/lib/db/upgrade.php"); # defines new upgrades
}
$stradministration = get_string("administration");
if ($CFG->version) {
if ($version > $CFG->version) { // upgrade
$a->oldversion = "$CFG->release ($CFG->version)";
$a->newversion = "$release ($version)";
$strdatabasechecking = get_string("databasechecking", "", $a);
// hide errors from headers in case debug is enabled
$origdebug = $CFG->debug;
$CFG->debug = DEBUG_MINIMAL;
error_reporting($CFG->debug);
// logout in case we are upgrading from pre 1.7 version - prevention of weird session problems
if ($CFG->version < 2006050600) {
require_logout();
}
if (empty($confirmupgrade)) {
print_header($strdatabasechecking, $stradministration, $strdatabasechecking,
"", "", false, " ", " ");
notice_yesno(get_string('upgradesure', 'admin', $a->newversion), 'index.php?confirmupgrade=yes', 'index.php');
exit;
} else if (empty($confirmrelease)) {
$strcurrentrelease = get_string("currentrelease");
print_header($strcurrentrelease, $strcurrentrelease, $strcurrentrelease, "", "", false, " ", " ");
print_heading("Moodle $release");
print_simple_box(get_string('releasenoteslink', 'admin', 'http://docs.moodle.org/en/Release_Notes'), 'center');
require_once($CFG->libdir.'/environmentlib.php');
print_heading(get_string('environment', 'admin'));
if (check_moodle_environment($release, $environment_results, true)) {
notice_yesno(get_string('environmenterrorupgrade', 'admin'),
'index.php?confirmupgrade=1&confirmrelease=1', 'index.php');
} else {
notify(get_string('environmentok', 'admin'), 'notifysuccess');
echo '
'.$copyrighttext.'
'; ////////////////////////////////////////////////////////////////////////////////////////////////// if (empty($registrationbuttonshown)) { echo '