MDL-19928 adding unofficial support for the cherokee web server + adding some notes...
[moodle.git] / lib / db / install.php
CommitLineData
117bd748 1<?php
1caea91e 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
4f0c2d00 9 /// make sure system context exists
b4154c2d 10 $syscontext = get_system_context(false);
1caea91e 11 if ($syscontext->id != 1) {
19a4a32e 12 throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected system context id created!');
1caea91e 13 }
14
15
4f0c2d00 16 /// create site course
1caea91e 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) {
19a4a32e 34 throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected site course id created!');
1caea91e 35 }
36
37
4f0c2d00 38 /// make sure site course context exists
1caea91e 39 get_context_instance(CONTEXT_COURSE, $SITE->id);
40
4f0c2d00 41 /// create default course category
1caea91e 42 $cat = get_course_category();
43
5b8fa09b 44 $defaults = array(
45 'rolesactive' => '0', // marks fully set up system
46 'auth' => 'email',
47 'auth_pop3mailbox' => 'INBOX',
48 'enrol' => 'manual',
49 'enrol_plugins_enabled' => 'manual',
50 'style' => 'default',
51 'template' => 'default',
5f0baa43 52 'theme' => theme_config::DEFAULT_THEME,
5b8fa09b 53 'filter_multilang_converted' => 1,
aa282b10 54 'siteidentifier' => random_string(32).get_host_from_url($CFG->wwwroot),
5b8fa09b 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 'stringfilters' => '', // These two are managed in a strange way by the filters
61 'filterall' => 0, // setting page, so have to be initialised here.
a5747cf8 62 'texteditors' => 'tinymce,textarea',
5b8fa09b 63 );
1caea91e 64 foreach($defaults as $key => $value) {
65 set_config($key, $value);
66 }
67
68
4f0c2d00 69 /// bootstrap mnet
1caea91e 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
c20ce874 93 // Initial insert of mnet applications info
94 $mnet_app = new object();
95 $mnet_app->name = 'moodle';
96 $mnet_app->display_name = 'Moodle';
97 $mnet_app->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
98 $mnet_app->sso_land_url = '/auth/mnet/land.php';
99 $mnet_app->sso_jump_url = '/auth/mnet/land.php';
100 $DB->insert_record('mnet_application', $mnet_app);
101
102 $mnet_app = new object();
103 $mnet_app->name = 'mahara';
104 $mnet_app->display_name = 'Mahara';
105 $mnet_app->xmlrpc_server_url = '/api/xmlrpc/server.php';
106 $mnet_app->sso_land_url = '/auth/xmlrpc/land.php';
107 $mnet_app->sso_jump_url = '/auth/xmlrpc/jump.php';
108 $DB->insert_record('mnet_application', $mnet_app);
109
88582df4 110
4f0c2d00 111 /// insert log entries - replaces statements section in install.xml
0cb93a7e 112 update_log_display_entry('user', 'view', 'user', 'CONCAT(firstname,\' \',lastname)');
113 update_log_display_entry('course', 'user report', 'user', 'CONCAT(firstname,\' \',lastname)');
114 update_log_display_entry('course', 'view', 'course', 'fullname');
115 update_log_display_entry('course', 'update', 'course', 'fullname');
116 update_log_display_entry('course', 'enrol', 'course', 'fullname');
117 update_log_display_entry('course', 'unenrol', 'course', 'fullname');
118 update_log_display_entry('course', 'report log', 'course', 'fullname');
119 update_log_display_entry('course', 'report live', 'course', 'fullname');
120 update_log_display_entry('course', 'report outline', 'course', 'fullname');
121 update_log_display_entry('course', 'report participation', 'course', 'fullname');
122 update_log_display_entry('course', 'report stats', 'course', 'fullname');
123 update_log_display_entry('message', 'write', 'user', 'CONCAT(firstname,\' \',lastname)');
124 update_log_display_entry('message', 'read', 'user', 'CONCAT(firstname,\' \',lastname)');
125 update_log_display_entry('message', 'add contact', 'user', 'CONCAT(firstname,\' \',lastname)');
126 update_log_display_entry('message', 'remove contact', 'user', 'CONCAT(firstname,\' \',lastname)');
127 update_log_display_entry('message', 'block contact', 'user', 'CONCAT(firstname,\' \',lastname)');
128 update_log_display_entry('message', 'unblock contact', 'user', 'CONCAT(firstname,\' \',lastname)');
129 update_log_display_entry('group', 'view', 'groups', 'name');
b89e4ad8 130 update_log_display_entry('tag', 'update', 'tag', 'name');
c20ce874 131
1caea91e 132
4f0c2d00 133 /// Create guest record - do not assign any role, guest user get's the default guest role automatically on the fly
88582df4 134 $guest = new object();
135 $guest->auth = 'manual';
136 $guest->username = 'guest';
137 $guest->password = hash_internal_user_password('guest');
138 $guest->firstname = get_string('guestuser');
139 $guest->lastname = ' ';
140 $guest->email = 'root@localhost';
141 $guest->description = get_string('guestuserinfo');
142 $guest->mnethostid = $CFG->mnet_localhost_id;
143 $guest->confirmed = 1;
144 $guest->lang = $CFG->lang;
145 $guest->timemodified= time();
146 $guest->id = $DB->insert_record('user', $guest);
147
148
4f0c2d00 149 /// Now create admin user
88582df4 150 $admin = new object();
151 $admin->auth = 'manual';
152 $admin->firstname = get_string('admin');
153 $admin->lastname = get_string('user');
154 $admin->username = 'admin';
155 $admin->password = 'adminsetuppending';
1deff123 156 $admin->email = '';
88582df4 157 $admin->confirmed = 1;
158 $admin->mnethostid = $CFG->mnet_localhost_id;
159 $admin->lang = $CFG->lang;
160 $admin->maildisplay = 1;
161 $admin->timemodified = time();
aa282b10 162 $admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr(); // installation hijacking prevention
88582df4 163 $admin->id = $DB->insert_record('user', $admin);
4f0c2d00
PS
164 /// Store list of admins
165 set_config('siteadmins', $admin->id);
88582df4 166
1caea91e 167
4f0c2d00
PS
168 /// Install the roles system.
169 $managerrole = create_role(get_string('manager', 'role'), 'manager', get_string('managerdescription', 'role'), 'manager');
170 $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'coursecreator');
171 $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'editingteacher');
172 $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'teacher');
173 $studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'student');
174 $guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'guest');
175 $userrole = create_role(get_string('authenticateduser'), 'user', get_string('authenticateduserdescription'), 'user');
176 $frontpagerole = create_role(get_string('frontpageuser', 'role'), 'frontpage', get_string('frontpageuserdescription', 'role'), 'frontpage');
88582df4 177
178 /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
88582df4 179 update_capabilities('moodle');
c976e271 180 external_update_descriptions('moodle');
88582df4 181
4f0c2d00
PS
182 /// Default allow assign
183 $defaultallowassigns = array(
184 array($managerrole, $managerrole),
185 array($managerrole, $coursecreatorrole),
186 array($managerrole, $editteacherrole),
187 array($managerrole, $noneditteacherrole),
188 array($managerrole, $studentrole),
88582df4 189
4f0c2d00
PS
190 array($editteacherrole, $noneditteacherrole),
191 array($editteacherrole, $studentrole),
c468795c 192 );
4f0c2d00
PS
193 foreach ($defaultallowassigns as $allow) {
194 list($fromroleid, $toroleid) = $allow;
c468795c 195 allow_assign($fromroleid, $toroleid);
4f0c2d00
PS
196 }
197
198 /// Default allow override
199 $defaultallowoverrides = array(
200 array($managerrole, $managerrole),
201 array($managerrole, $coursecreatorrole),
202 array($managerrole, $editteacherrole),
203 array($managerrole, $noneditteacherrole),
204 array($managerrole, $studentrole),
205 array($managerrole, $guestrole),
206 array($managerrole, $userrole),
207 array($managerrole, $frontpagerole),
208
209 array($editteacherrole, $noneditteacherrole),
210 array($editteacherrole, $studentrole),
211 array($editteacherrole, $guestrole),
212 );
213 foreach ($defaultallowoverrides as $allow) {
214 list($fromroleid, $toroleid) = $allow;
c468795c 215 allow_override($fromroleid, $toroleid); // There is a rant about this in MDL-15841.
4f0c2d00
PS
216 }
217
218 /// Default allow switch.
219 $defaultallowswitch = array(
220 array($managerrole, $editteacherrole),
221 array($managerrole, $noneditteacherrole),
222 array($managerrole, $studentrole),
223 array($managerrole, $guestrole),
224
225 array($editteacherrole, $noneditteacherrole),
226 array($editteacherrole, $studentrole),
227 array($editteacherrole, $guestrole),
228
229 array($noneditteacherrole, $studentrole),
230 array($noneditteacherrole, $guestrole),
231 );
232 foreach ($defaultallowswitch as $allow) {
233 list($fromroleid, $toroleid) = $allow;
c468795c 234 allow_switch($fromroleid, $toroleid);
235 }
88582df4 236
237 /// Set up the context levels where you can assign each role.
4f0c2d00 238 set_role_contextlevels($managerrole, get_default_contextlevels('manager'));
88582df4 239 set_role_contextlevels($coursecreatorrole, get_default_contextlevels('coursecreator'));
240 set_role_contextlevels($editteacherrole, get_default_contextlevels('editingteacher'));
241 set_role_contextlevels($noneditteacherrole, get_default_contextlevels('teacher'));
242 set_role_contextlevels($studentrole, get_default_contextlevels('student'));
243 set_role_contextlevels($guestrole, get_default_contextlevels('guest'));
244 set_role_contextlevels($userrole, get_default_contextlevels('user'));
ac173d3e 245
4f0c2d00 246 // Init themes
78946b9b 247 set_config('themerev', 1);
b64b465c
PS
248
249 // Install licenses
250 require_once($CFG->libdir . '/licenselib.php');
251 license_manager::install_licenses();
117bd748 252}