MDL-17267 simplified create_role - not adding assign and override perm to admin accou...
[moodle.git] / lib / db / install.php
CommitLineData
1caea91e 1<?php //$Id$
2
3// This file is executed right after the install.xml
4//
5
c20ce874 6function xmldb_main_install() {
1caea91e 7 global $CFG, $DB, $SITE;
8
1caea91e 9/// make sure system context exists
10 $syscontext = get_context_instance(CONTEXT_SYSTEM);
11 if ($syscontext->id != 1) {
12 throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected system context id created!');
13 }
14
15
16// create site course
17 $newsite = new object();
18 $newsite->fullname = "";
19 $newsite->shortname = "";
20 $newsite->summary = NULL;
21 $newsite->newsitems = 3;
22 $newsite->numsections = 0;
23 $newsite->category = 0;
24 $newsite->format = 'site'; // Only for this course
25 $newsite->teacher = get_string("defaultcourseteacher");
26 $newsite->teachers = get_string("defaultcourseteachers");
27 $newsite->student = get_string("defaultcoursestudent");
28 $newsite->students = get_string("defaultcoursestudents");
29 $newsite->timemodified = time();
30
31 $DB->insert_record('course', $newsite);
32 $SITE = get_site();
33 if ($SITE->id != 1) {
34 throw new moodle_exception('generalexceptionmessafe', 'error', '', 'Unexpected site course id created!');
35 }
36
37
38/// make sure site course context exists
39 get_context_instance(CONTEXT_COURSE, $SITE->id);
40
41/// create default course category
42 $cat = get_course_category();
43
44
1045a007 45 $defaults = array('rolesactive' => '0', // marks fully set up system
46 'auth' => 'email',
1caea91e 47 'auth_pop3mailbox' => 'INBOX',
48 'enrol' => 'manual',
49 'enrol_plugins_enabled' => 'manual',
50 'style' => 'default',
51 'template' => 'default',
52 'theme' => 'standardwhite',
53 'filter_multilang_converted' => 1,
54 'siteidentifier' => random_string(32).$_SERVER['HTTP_HOST'],
55 'backup_version' => 2008111700,
56 'backup_release' => '2.0 dev',
57 'blocks_version' => 2007081300, // might be removed soon
58 'mnet_dispatcher_mode' => 'off',
59 'sessiontimeout' => 7200, // must be present during roles installation
60
61 );
62 foreach($defaults as $key => $value) {
63 set_config($key, $value);
64 }
65
66
67/// bootstrap mnet
68 $mnethost = new object();
69 $mnethost->wwwroot = $CFG->wwwroot;
70 $mnethost->name = '';
71 $mnethost->name = '';
72 $mnethost->public_key = '';
73
74 if (empty($_SERVER['SERVER_ADDR'])) {
75 // SERVER_ADDR is only returned by Apache-like webservers
76 preg_match("@^(?:http[s]?://)?([A-Z0-9\-\.]+).*@i", $CFG->wwwroot, $matches);
77 $my_hostname = $matches[1];
78 $my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH!
79 if ($my_ip == $my_hostname) {
80 $mnethost->ip_address = 'UNKNOWN';
81 } else {
82 $mnethost->ip_address = $my_ip;
83 }
84 } else {
85 $mnethost->ip_address = $_SERVER['SERVER_ADDR'];
86 }
87
88 $mnetid = $DB->insert_record('mnet_host', $mnethost);
89 set_config('mnet_localhost_id', $mnetid);
90
c20ce874 91 // Initial insert of mnet applications info
92 $mnet_app = new object();
93 $mnet_app->name = 'moodle';
94 $mnet_app->display_name = 'Moodle';
95 $mnet_app->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
96 $mnet_app->sso_land_url = '/auth/mnet/land.php';
97 $mnet_app->sso_jump_url = '/auth/mnet/land.php';
98 $DB->insert_record('mnet_application', $mnet_app);
99
100 $mnet_app = new object();
101 $mnet_app->name = 'mahara';
102 $mnet_app->display_name = 'Mahara';
103 $mnet_app->xmlrpc_server_url = '/api/xmlrpc/server.php';
104 $mnet_app->sso_land_url = '/auth/xmlrpc/land.php';
105 $mnet_app->sso_jump_url = '/auth/xmlrpc/jump.php';
106 $DB->insert_record('mnet_application', $mnet_app);
107
108/// insert log entries - replaces statements section in install.xml
109 upgrade_log_display_entry('user', 'view', 'user', 'CONCAT(firstname,\' \',lastname)');
110 upgrade_log_display_entry('course', 'user report', 'user', 'CONCAT(firstname,\' \',lastname)');
111 upgrade_log_display_entry('course', 'view', 'course', 'fullname');
112 upgrade_log_display_entry('course', 'update', 'course', 'fullname');
113 upgrade_log_display_entry('course', 'enrol', 'course', 'fullname');
114 upgrade_log_display_entry('course', 'unenrol', 'course', 'fullname');
115 upgrade_log_display_entry('course', 'report log', 'course', 'fullname');
116 upgrade_log_display_entry('course', 'report live', 'course', 'fullname');
117 upgrade_log_display_entry('course', 'report outline', 'course', 'fullname');
118 upgrade_log_display_entry('course', 'report participation', 'course', 'fullname');
119 upgrade_log_display_entry('course', 'report stats', 'course', 'fullname');
120 upgrade_log_display_entry('message', 'write', 'user', 'CONCAT(firstname,\' \',lastname)');
121 upgrade_log_display_entry('message', 'read', 'user', 'CONCAT(firstname,\' \',lastname)');
122 upgrade_log_display_entry('message', 'add contact', 'user', 'CONCAT(firstname,\' \',lastname)');
123 upgrade_log_display_entry('message', 'remove contact', 'user', 'CONCAT(firstname,\' \',lastname)');
124 upgrade_log_display_entry('message', 'block contact', 'user', 'CONCAT(firstname,\' \',lastname)');
125 upgrade_log_display_entry('message', 'unblock contact', 'user', 'CONCAT(firstname,\' \',lastname)');
126 upgrade_log_display_entry('group', 'view', 'groups', 'name');
127
1caea91e 128
129/// Create guest record
130 create_guest_record();
131
ac173d3e 132/// Install the roles system.
133 moodle_install_roles();
134
1caea91e 135}