mirror of
https://github.com/moodle/moodle.git
synced 2025-08-04 16:36:37 +02:00
MDL-17457 moved a lot of code into lib/db/install.php + other refactoring and cleanup
This commit is contained in:
parent
51176ec09c
commit
1caea91efb
15 changed files with 280 additions and 361 deletions
|
@ -15,7 +15,6 @@ if ($hassiteconfig
|
|||
|
||||
/// Course Default Settings Page
|
||||
/// NOTE: these settings must be applied after all other settings because they depend on them
|
||||
if (isset($CFG->maxbytes)) { // TODO: replace this hack by something better
|
||||
///main course settings
|
||||
$temp = new admin_settingpage('coursesettings', get_string('coursesettings'));
|
||||
$temp->add(new admin_settings_coursecat_select('moodlecourse/category', get_string('category'), get_string('coursehelpcategory'), 1));
|
||||
|
@ -40,7 +39,11 @@ if ($hassiteconfig
|
|||
$temp->add(new admin_setting_configselect('moodlecourse/newsitems', get_string('newsitemsnumber'), get_string('coursehelpnewsitemsnumber'), 5,$options));
|
||||
$temp->add(new admin_setting_configselect('moodlecourse/showgrades', get_string('showgrades'), get_string('coursehelpshowgrades'), 1,array(0 => get_string('no'), 1 => get_string('yes'))));
|
||||
$temp->add(new admin_setting_configselect('moodlecourse/showreports', get_string('showreports'), '', 0,array(0 => get_string('no'), 1 => get_string('yes'))));
|
||||
if (isset($CFG->maxbytes)) {
|
||||
$choices = get_max_upload_sizes($CFG->maxbytes);
|
||||
} else {
|
||||
$choices = get_max_upload_sizes();
|
||||
}
|
||||
$temp->add(new admin_setting_configselect('moodlecourse/maxbytes', get_string('maximumupload'), get_string('coursehelpmaximumupload'), key($choices), $choices));
|
||||
$temp->add(new admin_setting_configselect('moodlecourse/metacourse', get_string('metacourse'), get_string('coursehelpmetacourse'), 0,array(0 => get_string('no'), 1 => get_string('yes'))));
|
||||
|
||||
|
@ -116,7 +119,6 @@ if ($hassiteconfig
|
|||
1,array(0 => get_string('completiondisabled','completion'), 1 => get_string('completionenabled','completion'))));
|
||||
}
|
||||
$ADMIN->add('courses', $temp);
|
||||
}
|
||||
|
||||
/// "courserequests" settingpage
|
||||
$temp = new admin_settingpage('courserequest', get_string('courserequest'));
|
||||
|
|
|
@ -12,7 +12,7 @@ $temp->add(new admin_setting_configselect('gdversion', get_string('gdversion','a
|
|||
'2' => get_string('gd2'))));
|
||||
$temp->add(new admin_setting_configexecutable('pathtodu', get_string('pathtodu', 'admin'), get_string('configpathtodu', 'admin'), ''));
|
||||
$temp->add(new admin_setting_configexecutable('aspellpath', get_string('aspellpath', 'admin'), get_string('edhelpaspellpath'), ''));
|
||||
$ADMIN->add('server', $temp, 0);
|
||||
$ADMIN->add('server', $temp);
|
||||
|
||||
|
||||
|
||||
|
@ -69,7 +69,7 @@ if (isloggedin()) {
|
|||
$temp->add(new admin_setting_configtext('supportname', get_string('supportname', 'admin'), get_string('configsupportname', 'admin'), $primaryadminname, PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_configtext('supportemail', get_string('supportemail', 'admin'), get_string('configsupportemail', 'admin'), $primaryadminemail, PARAM_NOTAGS));
|
||||
$temp->add(new admin_setting_configtext('supportpage', get_string('supportpage', 'admin'), get_string('configsupportpage', 'admin'), '', PARAM_URL));
|
||||
$ADMIN->add('server', $temp, 100);
|
||||
$ADMIN->add('server', $temp);
|
||||
|
||||
|
||||
|
||||
|
@ -88,7 +88,7 @@ $temp->add(new admin_setting_configselect('sessiontimeout', get_string('sessiont
|
|||
$temp->add(new admin_setting_configtext('sessioncookie', get_string('sessioncookie', 'admin'), get_string('configsessioncookie', 'admin'), '', PARAM_ALPHANUM));
|
||||
$temp->add(new admin_setting_configtext('sessioncookiepath', get_string('sessioncookiepath', 'admin'), get_string('configsessioncookiepath', 'admin'), '/', PARAM_LOCALURL));
|
||||
$temp->add(new admin_setting_configtext('sessioncookiedomain', get_string('sessioncookiedomain', 'admin'), get_string('configsessioncookiedomain', 'admin'), '', PARAM_TEXT, 50));
|
||||
$ADMIN->add('server', $temp, 50);
|
||||
$ADMIN->add('server', $temp);
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@
|
|||
// are added to them.
|
||||
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
if (get_site()) {
|
||||
$hassiteconfig = has_capability('moodle/site:config', $systemcontext);
|
||||
} else {
|
||||
if (empty($CFG->rolesactive)) {
|
||||
// installation starts - no permission checks
|
||||
$hassiteconfig = true;
|
||||
} else {
|
||||
$hassiteconfig = has_capability('moodle/site:config', $systemcontext);
|
||||
}
|
||||
|
||||
$ADMIN->add('root', new admin_externalpage('adminnotifications', get_string('notifications'), "$CFG->wwwroot/$CFG->admin/index.php"));
|
||||
|
|
166
lib/adminlib.php
166
lib/adminlib.php
|
@ -128,6 +128,10 @@ function upgrade_db($version, $release) {
|
|||
|
||||
$DB->get_manager()->install_from_xmldb_file("$CFG->libdir/db/install.xml");
|
||||
|
||||
/// set all core default records and default settings
|
||||
require_once("$CFG->libdir/db/install.php");
|
||||
xmldb_main_install($version);
|
||||
|
||||
/// Continue with the instalation
|
||||
|
||||
// Install the roles system.
|
||||
|
@ -140,39 +144,13 @@ function upgrade_db($version, $release) {
|
|||
message_update_providers();
|
||||
message_update_providers('message');
|
||||
|
||||
/// 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('auth' => 'email',
|
||||
'auth_pop3mailbox' => 'INBOX',
|
||||
'enrol' => 'manual',
|
||||
'enrol_plugins_enabled' => 'manual',
|
||||
'style' => 'default',
|
||||
'template' => 'default',
|
||||
'theme' => 'standardwhite',
|
||||
'filter_multilang_converted' => 1,
|
||||
'backup_version' => 2008111700,
|
||||
'backup_release' => '2.0 dev',
|
||||
'blocks_version' => 2007081300, // might be removed soon
|
||||
));
|
||||
|
||||
// store main version
|
||||
if (!set_config('version', $version)) {
|
||||
print_error('cannotupdateversion', 'debug');
|
||||
}
|
||||
|
||||
|
||||
// Write default settings unconditionally (i.e. even if a setting is already set, overwrite it)
|
||||
// (this should only have any effect during initial install).
|
||||
admin_apply_default_settings(NULL, true);
|
||||
|
||||
notify($strdatabasesuccess, 'notifysuccess');
|
||||
|
||||
/// do not show certificates in log ;-)
|
||||
$DB->set_debug(false);
|
||||
|
||||
// hack - set up mnet
|
||||
require_once $CFG->dirroot.'/mnet/lib.php';
|
||||
|
||||
print_continue("index.php?continuesetuptesttables=$setuptesttables&upgradetesttables=$upgradetesttables");
|
||||
print_footer('none');
|
||||
|
||||
|
@ -190,7 +168,6 @@ function upgrade_db($version, $release) {
|
|||
}
|
||||
|
||||
if ($version > $CFG->version) { // upgrade
|
||||
|
||||
require_once($CFG->libdir.'/db/upgrade.php'); // Defines upgrades
|
||||
require_once($CFG->libdir.'/db/upgradelib.php'); // Upgrade-related functions
|
||||
|
||||
|
@ -297,14 +274,7 @@ function upgrade_db($version, $release) {
|
|||
print_heading($strdatabasechecking);
|
||||
$DB->set_debug(true);
|
||||
/// Launch the old main upgrade (if exists)
|
||||
$status = true;
|
||||
if (function_exists('main_upgrade')) {
|
||||
$status = main_upgrade($CFG->version);
|
||||
}
|
||||
/// If succesful and exists launch the new main upgrade (XMLDB), called xmldb_main_upgrade
|
||||
if ($status && function_exists('xmldb_main_upgrade')) {
|
||||
$status = xmldb_main_upgrade($CFG->version);
|
||||
}
|
||||
$DB->set_debug(false);
|
||||
/// If successful, continue upgrading roles and setting everything properly
|
||||
if ($status) {
|
||||
|
@ -369,13 +339,15 @@ function upgrade_db($version, $release) {
|
|||
|
||||
if ($upgradedplugins) {
|
||||
print_continue($return_url);
|
||||
print_footer();
|
||||
print_footer('none');
|
||||
die;
|
||||
}
|
||||
|
||||
/// Check for changes to RPC functions
|
||||
if ($CFG->mnet_dispatcher_mode != 'off') {
|
||||
require_once("$CFG->dirroot/$CFG->admin/mnet/adminlib.php");
|
||||
upgrade_RPC_functions($return_url); // Return here afterwards
|
||||
}
|
||||
|
||||
/// Check for local database customisations
|
||||
/// first old *.php update and then the new upgrade.php script
|
||||
|
@ -388,101 +360,11 @@ function upgrade_db($version, $release) {
|
|||
// Turn xmlstrictheaders back on now.
|
||||
$CFG->xmlstrictheaders = $origxmlstrictheaders;
|
||||
|
||||
if (!$unittest) {
|
||||
/// Set up the blank site - to be customized later at the end of install.
|
||||
if (! $site = get_site()) {
|
||||
build_site_course();
|
||||
redirect("index.php?continuesetuptesttables=$continuesetuptesttables&upgradetesttables=$upgradetesttables");
|
||||
}
|
||||
|
||||
// initialise default blocks on admin and site page if needed
|
||||
if (empty($CFG->adminblocks_initialised)) {
|
||||
require_once("$CFG->dirroot/$CFG->admin/pagelib.php");
|
||||
require_once($CFG->libdir.'/blocklib.php');
|
||||
page_map_class(PAGE_ADMIN, 'page_admin');
|
||||
$page = page_create_object(PAGE_ADMIN, 0); // there must be some id number
|
||||
blocks_repopulate_page($page);
|
||||
|
||||
//add admin_tree block to site if not already present
|
||||
if ($admintree = $DB->get_record('block', array('name'=>'admin_tree'))) {
|
||||
$page = page_create_object(PAGE_COURSE_VIEW, SITEID);
|
||||
$pageblocks=blocks_get_by_page($page);
|
||||
blocks_execute_action($page, $pageblocks, 'add', (int)$admintree->id, false, false);
|
||||
if ($admintreeinstance = $DB->get_record('block_instance', array('pagetype'=>$page->type, 'pageid'=>SITEID, 'blockid'=>$admintree->id))) {
|
||||
$pageblocks=blocks_get_by_page($page);
|
||||
blocks_execute_action($page, $pageblocks, 'moveleft', $admintreeinstance, false, false);
|
||||
}
|
||||
}
|
||||
|
||||
set_config('adminblocks_initialised', 1);
|
||||
}
|
||||
|
||||
/// Define the unique site ID code if it isn't already
|
||||
if (empty($CFG->siteidentifier)) { // Unique site identification code
|
||||
set_config('siteidentifier', random_string(32).$_SERVER['HTTP_HOST']);
|
||||
}
|
||||
|
||||
/// ugly hack - if mnet is not initialised include the mnet lib, it adds needed mnet records and configures config options
|
||||
/// we should not do such crazy stuff in lib functions!!!
|
||||
if (empty($CFG->mnet_localhost_id)) {
|
||||
require_once $CFG->dirroot.'/mnet/lib.php';
|
||||
}
|
||||
|
||||
/// Check if the guest user exists. If not, create one.
|
||||
if (!$DB->record_exists('user', array('username'=>'guest'))) {
|
||||
if (! $guest = create_guest_record()) {
|
||||
notify("Could not create guest user record !!!");
|
||||
}
|
||||
}
|
||||
|
||||
/// Set up the admin user
|
||||
/// 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->rolesactive)) {
|
||||
build_context_path(); // just in case - should not be needed
|
||||
create_admin_user();
|
||||
}
|
||||
} else {
|
||||
build_site_course();
|
||||
create_guest_record();
|
||||
create_admin_user();
|
||||
redirect($return_url);
|
||||
}
|
||||
}
|
||||
|
||||
function build_site_course() {
|
||||
global $CFG, $DB, $unittest;
|
||||
|
||||
$continuesetuptesttables= optional_param('continuesetuptesttables', $unittest, PARAM_BOOL);
|
||||
|
||||
// We are about to create the site "course"
|
||||
require_once($CFG->libdir.'/blocklib.php');
|
||||
|
||||
$newsite = new object();
|
||||
$newsite->fullname = "";
|
||||
$newsite->shortname = "";
|
||||
$newsite->summary = NULL;
|
||||
$newsite->newsitems = 3;
|
||||
$newsite->numsections = 0;
|
||||
$newsite->category = 0;
|
||||
$newsite->format = 'site'; // Only for this course
|
||||
$newsite->teacher = get_string("defaultcourseteacher");
|
||||
$newsite->teachers = get_string("defaultcourseteachers");
|
||||
$newsite->student = get_string("defaultcoursestudent");
|
||||
$newsite->students = get_string("defaultcoursestudents");
|
||||
$newsite->timemodified = time();
|
||||
|
||||
if (!$newid = $DB->insert_record('course', $newsite)) {
|
||||
print_error('cannotsetupsite', 'error');
|
||||
}
|
||||
// make sure course context exists
|
||||
get_context_instance(CONTEXT_COURSE, $newid);
|
||||
|
||||
// Site created, add blocks for it
|
||||
$page = page_create_object(PAGE_COURSE_VIEW, $newid);
|
||||
blocks_repopulate_page($page); // Return value not checked because you can always edit later
|
||||
|
||||
// create default course category
|
||||
$cat = get_course_category();
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1329,9 +1211,9 @@ function create_admin_user($user_input=NULL) {
|
|||
print_error('noadminrole', 'message');
|
||||
}
|
||||
|
||||
$sitecontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
$systemcontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
foreach ($adminroles as $adminrole) {
|
||||
role_assign($adminrole->id, $user->id, 0, $sitecontext->id);
|
||||
role_assign($adminrole->id, $user->id, 0, $systemcontext->id);
|
||||
}
|
||||
|
||||
//set default message preferences
|
||||
|
@ -2120,7 +2002,8 @@ class admin_externalpage extends part_of_admin_tree {
|
|||
* @return bool True if user has access, false otherwise.
|
||||
*/
|
||||
function check_access() {
|
||||
if (!get_site()) {
|
||||
global $CFG;
|
||||
if (empty($CFG->rolesactive)) {
|
||||
return true; // no access check before site is fully set up
|
||||
}
|
||||
$context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
|
||||
|
@ -2270,7 +2153,8 @@ class admin_settingpage extends part_of_admin_tree {
|
|||
|
||||
// see admin_externalpage
|
||||
function check_access() {
|
||||
if (!get_site()) {
|
||||
global $CFG;
|
||||
if (empty($CFG->rolesactive)) {
|
||||
return true; // no access check before site is fully set up
|
||||
}
|
||||
$context = empty($this->context) ? get_context_instance(CONTEXT_SYSTEM) : $this->context;
|
||||
|
@ -5347,7 +5231,7 @@ function admin_externalpage_print_footer() {
|
|||
* Returns the reference to admin tree root
|
||||
* @return reference
|
||||
*/
|
||||
function &admin_get_root($reload=false, $requirefulltree=true) {
|
||||
function admin_get_root($reload=false, $requirefulltree=true) {
|
||||
global $CFG, $DB;
|
||||
|
||||
static $ADMIN = NULL;
|
||||
|
@ -5390,12 +5274,12 @@ function &admin_get_root($reload=false, $requirefulltree=true) {
|
|||
// plugins are loaded last - they may insert pages anywhere
|
||||
continue;
|
||||
}
|
||||
include($file);
|
||||
require($file);
|
||||
}
|
||||
include($CFG->dirroot.'/'.$CFG->admin.'/settings/plugins.php');
|
||||
require($CFG->dirroot.'/'.$CFG->admin.'/settings/plugins.php');
|
||||
|
||||
if (file_exists($CFG->dirroot.'/local/settings.php')) {
|
||||
include_once($CFG->dirroot.'/local/settings.php');
|
||||
require($CFG->dirroot.'/local/settings.php');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -5414,7 +5298,7 @@ function admin_apply_default_settings($node=NULL, $unconditional=true) {
|
|||
global $CFG;
|
||||
|
||||
if (is_null($node)) {
|
||||
$node =& admin_get_root(true, true);
|
||||
$node = admin_get_root(true, true);
|
||||
}
|
||||
|
||||
if (is_a($node, 'admin_category')) {
|
||||
|
@ -5622,16 +5506,6 @@ function admin_output_new_settings_by_page($node) {
|
|||
return $return;
|
||||
}
|
||||
|
||||
/**
|
||||
* Unconditionally applies default admin settings in main config table
|
||||
* @param array $defaults array of string values
|
||||
*/
|
||||
function apply_default_exception_settings($defaults) {
|
||||
foreach($defaults as $key => $value) {
|
||||
set_config($key, $value, NULL);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Format admin settings
|
||||
* @param string $object setting
|
||||
|
|
|
@ -1072,7 +1072,9 @@ function blocks_repopulate_page($page) {
|
|||
//This function finds all available blocks and install them
|
||||
//into blocks table or do all the upgrade process if newer
|
||||
function upgrade_blocks_plugins() {
|
||||
global $CFG, $interactive, $DB;
|
||||
global $CFG, $interactive, $DB, $SITE;
|
||||
|
||||
require_once($CFG->dirroot .'/blocks/moodleblock.class.php');
|
||||
|
||||
$updated_blocks = false;
|
||||
|
||||
|
@ -1084,19 +1086,12 @@ function upgrade_blocks_plugins() {
|
|||
//Count the number of blocks in db
|
||||
$blockcount = $DB->count_records('block');
|
||||
//If there isn't records. This is the first install, so I remember it
|
||||
if ($blockcount == 0) {
|
||||
$first_install = true;
|
||||
} else {
|
||||
$first_install = false;
|
||||
}
|
||||
|
||||
$site = get_site();
|
||||
$first_install = ($blockcount == 0);
|
||||
|
||||
if (!$blocks = get_list_of_plugins('blocks') ) {
|
||||
print_error('noblocks', 'debug');
|
||||
}
|
||||
|
||||
include_once($CFG->dirroot .'/blocks/moodleblock.class.php');
|
||||
if (!class_exists('block_base')) {
|
||||
print_error('noblockbase');
|
||||
}
|
||||
|
@ -1308,24 +1303,22 @@ function upgrade_blocks_plugins() {
|
|||
}
|
||||
}
|
||||
|
||||
// Finally, if we are in the first_install of BLOCKS (this means that we are
|
||||
// upgrading from Moodle < 1.3), put blocks in all existing courses.
|
||||
// Finally, if we are in the first_install of BLOCKS setup frontpage and admin page blocks
|
||||
if ($first_install) {
|
||||
require_once($CFG->dirroot.'/'.$CFG->admin.'/pagelib.php');
|
||||
|
||||
upgrade_log_start();
|
||||
//Iterate over each course
|
||||
//Iterate over each course - there should be only site course here now
|
||||
if ($courses = $DB->get_records('course')) {
|
||||
foreach ($courses as $course) {
|
||||
$page = page_create_object(PAGE_COURSE_VIEW, $course->id);
|
||||
blocks_repopulate_page($page);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($CFG->siteblocksadded)) { /// This is a once-off hack to make a proper upgrade
|
||||
upgrade_log_start();
|
||||
$page = page_create_object(PAGE_COURSE_VIEW, SITEID);
|
||||
page_map_class(PAGE_ADMIN, 'page_admin');
|
||||
$page = page_create_object(PAGE_ADMIN, 0); // there must be some id number
|
||||
blocks_repopulate_page($page);
|
||||
$DB->delete_records('config', array('name'=>'siteblocksadded'));
|
||||
}
|
||||
|
||||
upgrade_log_finish();
|
||||
|
|
|
@ -94,7 +94,7 @@ class completion_info {
|
|||
*/
|
||||
public static function is_enabled_for_site() {
|
||||
global $CFG;
|
||||
return $CFG->enablecompletion;
|
||||
return !empty($CFG->enablecompletion);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
101
lib/db/install.php
Normal file
101
lib/db/install.php
Normal file
|
@ -0,0 +1,101 @@
|
|||
<?php //$Id$
|
||||
|
||||
// This file is executed right after the install.xml
|
||||
//
|
||||
|
||||
function xmldb_main_install($version) {
|
||||
global $CFG, $DB, $SITE;
|
||||
|
||||
/// TODO: move all statements from install.xml here
|
||||
|
||||
|
||||
/// make sure system context exists
|
||||
$syscontext = get_context_instance(CONTEXT_SYSTEM);
|
||||
if ($syscontext->id != 1) {
|
||||
throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected system context id created!');
|
||||
}
|
||||
|
||||
|
||||
// create site course
|
||||
$newsite = new object();
|
||||
$newsite->fullname = "";
|
||||
$newsite->shortname = "";
|
||||
$newsite->summary = NULL;
|
||||
$newsite->newsitems = 3;
|
||||
$newsite->numsections = 0;
|
||||
$newsite->category = 0;
|
||||
$newsite->format = 'site'; // Only for this course
|
||||
$newsite->teacher = get_string("defaultcourseteacher");
|
||||
$newsite->teachers = get_string("defaultcourseteachers");
|
||||
$newsite->student = get_string("defaultcoursestudent");
|
||||
$newsite->students = get_string("defaultcoursestudents");
|
||||
$newsite->timemodified = time();
|
||||
|
||||
$DB->insert_record('course', $newsite);
|
||||
$SITE = get_site();
|
||||
if ($SITE->id != 1) {
|
||||
throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected site course id created!');
|
||||
}
|
||||
|
||||
|
||||
/// make sure site course context exists
|
||||
get_context_instance(CONTEXT_COURSE, $SITE->id);
|
||||
|
||||
/// create default course category
|
||||
$cat = get_course_category();
|
||||
|
||||
|
||||
$defaults = array('auth' => 'email',
|
||||
'auth_pop3mailbox' => 'INBOX',
|
||||
'enrol' => 'manual',
|
||||
'enrol_plugins_enabled' => 'manual',
|
||||
'style' => 'default',
|
||||
'template' => 'default',
|
||||
'theme' => 'standardwhite',
|
||||
'filter_multilang_converted' => 1,
|
||||
'siteidentifier' => random_string(32).$_SERVER['HTTP_HOST'],
|
||||
'backup_version' => 2008111700,
|
||||
'backup_release' => '2.0 dev',
|
||||
'blocks_version' => 2007081300, // might be removed soon
|
||||
'mnet_dispatcher_mode' => 'off',
|
||||
'sessiontimeout' => 7200, // must be present during roles installation
|
||||
|
||||
);
|
||||
foreach($defaults as $key => $value) {
|
||||
set_config($key, $value);
|
||||
}
|
||||
|
||||
|
||||
/// bootstrap mnet
|
||||
$mnethost = new object();
|
||||
$mnethost->wwwroot = $CFG->wwwroot;
|
||||
$mnethost->name = '';
|
||||
$mnethost->name = '';
|
||||
$mnethost->public_key = '';
|
||||
|
||||
if (empty($_SERVER['SERVER_ADDR'])) {
|
||||
// SERVER_ADDR is only returned by Apache-like webservers
|
||||
preg_match("@^(?:http[s]?://)?([A-Z0-9\-\.]+).*@i", $CFG->wwwroot, $matches);
|
||||
$my_hostname = $matches[1];
|
||||
$my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH!
|
||||
if ($my_ip == $my_hostname) {
|
||||
$mnethost->ip_address = 'UNKNOWN';
|
||||
} else {
|
||||
$mnethost->ip_address = $my_ip;
|
||||
}
|
||||
} else {
|
||||
$mnethost->ip_address = $_SERVER['SERVER_ADDR'];
|
||||
}
|
||||
|
||||
$mnetid = $DB->insert_record('mnet_host', $mnethost);
|
||||
set_config('mnet_localhost_id', $mnetid);
|
||||
|
||||
|
||||
/// Create guest record
|
||||
create_guest_record();
|
||||
|
||||
|
||||
/// everything ready - store main version :-D
|
||||
set_config('version', $version);
|
||||
|
||||
}
|
|
@ -1309,15 +1309,6 @@ function xmldb_main_upgrade($oldversion) {
|
|||
upgrade_main_savepoint($result, 2009010800);
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2009010801) {
|
||||
/// Remove unused settings
|
||||
unset_config('zip');
|
||||
unset_config('unzip');
|
||||
|
||||
/// Main savepoint reached
|
||||
upgrade_main_savepoint($result, 2009010801);
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2009011000) {
|
||||
|
||||
/// Changing nullability of field configdata on table block_instance to null
|
||||
|
@ -1332,6 +1323,17 @@ function xmldb_main_upgrade($oldversion) {
|
|||
upgrade_main_savepoint($result, 2009011000);
|
||||
}
|
||||
|
||||
if ($result && $oldversion < 2009011100) {
|
||||
/// Remove unused settings
|
||||
unset_config('zip');
|
||||
unset_config('unzip');
|
||||
unset_config('adminblocks_initialised');
|
||||
|
||||
/// Main savepoint reached
|
||||
upgrade_main_savepoint($result, 2009011100);
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
|
|
@ -2834,9 +2834,8 @@ function create_guest_record() {
|
|||
$guest->lang = $CFG->lang;
|
||||
$guest->timemodified= time();
|
||||
|
||||
if (! $guest->id = $DB->insert_record('user', $guest)) {
|
||||
return false;
|
||||
}
|
||||
$id = $DB->insert_record('user', $guest);
|
||||
$guest = $DB->get_record('user', array('id'=>$id));
|
||||
|
||||
return $guest;
|
||||
}
|
||||
|
|
|
@ -24,13 +24,6 @@
|
|||
$session_has_timed_out = false;
|
||||
}
|
||||
|
||||
/// Check if the guest user exists. If not, create one.
|
||||
if (!$DB->record_exists('user', array('username'=>'guest', 'mnethostid'=>$CFG->mnet_localhost_id))) {
|
||||
if (! $guest = create_guest_record()) {
|
||||
notify('Could not create guest user record !!!');
|
||||
}
|
||||
}
|
||||
|
||||
// setup and verify auth settings
|
||||
|
||||
if (!isset($CFG->registerauth)) {
|
||||
|
|
|
@ -24,53 +24,20 @@ class mnet_environment {
|
|||
function init() {
|
||||
global $CFG, $DB;
|
||||
|
||||
if (empty($CFG->mnet_dispatcher_mode)) {
|
||||
set_config('mnet_dispatcher_mode', 'off');
|
||||
}
|
||||
|
||||
// Bootstrap the object data on first load.
|
||||
if (empty($CFG->mnet_localhost_id) ) {
|
||||
if (!$CFG->mnet_localhost_id = get_config(NULL, 'mnet_localhost_id')) { // Double-check db
|
||||
$this->wwwroot = $CFG->wwwroot;
|
||||
if (empty($_SERVER['SERVER_ADDR'])) {
|
||||
// SERVER_ADDR is only returned by Apache-like webservers
|
||||
$my_hostname = mnet_get_hostname_from_uri($CFG->wwwroot);
|
||||
$my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH!
|
||||
if ($my_ip == $my_hostname) {
|
||||
$this->ip_address = 'UNKNOWN';
|
||||
} else {
|
||||
$this->ip_address = $my_ip;
|
||||
if (!$hostobject = $DB->get_record('mnet_host', array('id'=>$CFG->mnet_localhost_id))) {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
$this->ip_address = $_SERVER['SERVER_ADDR'];
|
||||
}
|
||||
|
||||
if ($existingrecord = $DB->get_record('mnet_host', array('ip_address'=>$this->ip_address))) {
|
||||
$this->id = $existingrecord->id;
|
||||
} else { // make a new one
|
||||
$this->id = $DB->insert_record('mnet_host', $this);
|
||||
}
|
||||
|
||||
set_config('mnet_localhost_id', $this->id);
|
||||
$this->get_keypair();
|
||||
}
|
||||
} else {
|
||||
$hostobject = $DB->get_record('mnet_host', array('id'=>$CFG->mnet_localhost_id));
|
||||
if(is_object($hostobject)) {
|
||||
$temparr = get_object_vars($hostobject);
|
||||
foreach($temparr as $key => $value) {
|
||||
$this->$key = $value;
|
||||
}
|
||||
unset($hostobject, $temparr);
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Unless this is an install/upgrade, generate the SSL keys.
|
||||
if (empty($this->public_key)) {
|
||||
$this->get_keypair();
|
||||
}
|
||||
}
|
||||
|
||||
// We need to set up a record that represents 'all hosts'. Any rights
|
||||
// granted to this host will be conferred on all hosts.
|
||||
|
@ -93,11 +60,12 @@ class mnet_environment {
|
|||
}
|
||||
|
||||
function get_keypair() {
|
||||
global $DB, $SESSION;
|
||||
global $DB, $CFG;
|
||||
|
||||
// We don't generate keys on install/upgrade because we want the USER
|
||||
// record to have an email address, city and country already.
|
||||
if (!empty($SESSION->upgraderunning)) return true;
|
||||
if (empty($CFG->rolesactive)) return true;
|
||||
if ($CFG->mnet_dispatcher_mode == 'off') return true;
|
||||
if (!extension_loaded("openssl")) return true;
|
||||
if (!empty($this->keypair)) return true;
|
||||
|
||||
|
|
|
@ -350,18 +350,15 @@ function mnet_generate_keypair($dn = null, $days=28) {
|
|||
$break = strpos($host.'/' , '/');
|
||||
$host = substr($host, 0, $break);
|
||||
|
||||
if ($result = $DB->get_record('course', array("id"=>SITEID))) {
|
||||
$organization = $result->fullname;
|
||||
} else {
|
||||
$organization = 'None';
|
||||
}
|
||||
$site = get_site();
|
||||
$organization = $site->fullname;
|
||||
|
||||
$keypair = array();
|
||||
|
||||
$country = 'NZ';
|
||||
$province = 'Wellington';
|
||||
$locality = 'Wellington';
|
||||
$email = $CFG->noreplyaddress;
|
||||
$email = !empty($CFG->noreplyaddress) ? $CFG->noreplyaddress : 'noreply@'.$_SERVER['HTTP_HOST'];
|
||||
|
||||
if(!empty($USER->country)) {
|
||||
$country = $USER->country;
|
||||
|
|
|
@ -1,15 +1,5 @@
|
|||
<?PHP // $Id$
|
||||
|
||||
//////////////////////////////////
|
||||
/// CONFIGURATION settings
|
||||
|
||||
if (!isset($CFG->hotpot_showtimes)) {
|
||||
set_config("hotpot_showtimes", 0);
|
||||
}
|
||||
if (!isset($CFG->hotpot_excelencodings)) {
|
||||
set_config("hotpot_excelencodings", "");
|
||||
}
|
||||
|
||||
//////////////////////////////////
|
||||
/// CONSTANTS and GLOBAL VARIABLES
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
// This is compared against the values stored in the database to determine
|
||||
// whether upgrades should be performed (see lib/db/*.php)
|
||||
|
||||
$version = 2009011000; // YYYYMMDD = date of the last version bump
|
||||
$version = 2009011100; // YYYYMMDD = date of the last version bump
|
||||
// XX = daily increments
|
||||
|
||||
$release = '2.0 dev (Build: 20090111)'; // Human-friendly version name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue