MDL-17457 moved a lot of code into lib/db/install.php + other refactoring and cleanup
[moodle.git] / lib / db / install.php
CommitLineData
1caea91e 1<?php //$Id$
2
3// This file is executed right after the install.xml
4//
5
6function xmldb_main_install($version) {
7 global $CFG, $DB, $SITE;
8
9/// TODO: move all statements from install.xml here
10
11
12/// make sure system context exists
13 $syscontext = get_context_instance(CONTEXT_SYSTEM);
14 if ($syscontext->id != 1) {
15 throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected system context id created!');
16 }
17
18
19// create site course
20 $newsite = new object();
21 $newsite->fullname = "";
22 $newsite->shortname = "";
23 $newsite->summary = NULL;
24 $newsite->newsitems = 3;
25 $newsite->numsections = 0;
26 $newsite->category = 0;
27 $newsite->format = 'site'; // Only for this course
28 $newsite->teacher = get_string("defaultcourseteacher");
29 $newsite->teachers = get_string("defaultcourseteachers");
30 $newsite->student = get_string("defaultcoursestudent");
31 $newsite->students = get_string("defaultcoursestudents");
32 $newsite->timemodified = time();
33
34 $DB->insert_record('course', $newsite);
35 $SITE = get_site();
36 if ($SITE->id != 1) {
37 throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected site course id created!');
38 }
39
40
41/// make sure site course context exists
42 get_context_instance(CONTEXT_COURSE, $SITE->id);
43
44/// create default course category
45 $cat = get_course_category();
46
47
48 $defaults = array('auth' => 'email',
49 'auth_pop3mailbox' => 'INBOX',
50 'enrol' => 'manual',
51 'enrol_plugins_enabled' => 'manual',
52 'style' => 'default',
53 'template' => 'default',
54 'theme' => 'standardwhite',
55 'filter_multilang_converted' => 1,
56 'siteidentifier' => random_string(32).$_SERVER['HTTP_HOST'],
57 'backup_version' => 2008111700,
58 'backup_release' => '2.0 dev',
59 'blocks_version' => 2007081300, // might be removed soon
60 'mnet_dispatcher_mode' => 'off',
61 'sessiontimeout' => 7200, // must be present during roles installation
62
63 );
64 foreach($defaults as $key => $value) {
65 set_config($key, $value);
66 }
67
68
69/// bootstrap mnet
70 $mnethost = new object();
71 $mnethost->wwwroot = $CFG->wwwroot;
72 $mnethost->name = '';
73 $mnethost->name = '';
74 $mnethost->public_key = '';
75
76 if (empty($_SERVER['SERVER_ADDR'])) {
77 // SERVER_ADDR is only returned by Apache-like webservers
78 preg_match("@^(?:http[s]?://)?([A-Z0-9\-\.]+).*@i", $CFG->wwwroot, $matches);
79 $my_hostname = $matches[1];
80 $my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH!
81 if ($my_ip == $my_hostname) {
82 $mnethost->ip_address = 'UNKNOWN';
83 } else {
84 $mnethost->ip_address = $my_ip;
85 }
86 } else {
87 $mnethost->ip_address = $_SERVER['SERVER_ADDR'];
88 }
89
90 $mnetid = $DB->insert_record('mnet_host', $mnethost);
91 set_config('mnet_localhost_id', $mnetid);
92
93
94/// Create guest record
95 create_guest_record();
96
97
98/// everything ready - store main version :-D
99 set_config('version', $version);
100
101}