mirror of
https://github.com/moodle/moodle.git
synced 2025-08-05 00:46:50 +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
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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue