MDL-13766, fixed repository instance name and configplugin language string
[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',
df997f84 48 'enrol_plugins_enabled' => 'manual,guest,self,cohort',
5f0baa43 49 'theme' => theme_config::DEFAULT_THEME,
5b8fa09b 50 'filter_multilang_converted' => 1,
aa282b10 51 'siteidentifier' => random_string(32).get_host_from_url($CFG->wwwroot),
5b8fa09b 52 'backup_version' => 2008111700,
53 'backup_release' => '2.0 dev',
54 'blocks_version' => 2007081300, // might be removed soon
55 'mnet_dispatcher_mode' => 'off',
56 'sessiontimeout' => 7200, // must be present during roles installation
57 'stringfilters' => '', // These two are managed in a strange way by the filters
58 'filterall' => 0, // setting page, so have to be initialised here.
a5747cf8 59 'texteditors' => 'tinymce,textarea',
5b8fa09b 60 );
1caea91e 61 foreach($defaults as $key => $value) {
62 set_config($key, $value);
63 }
64
65
4f0c2d00 66 /// bootstrap mnet
1caea91e 67 $mnethost = new object();
68 $mnethost->wwwroot = $CFG->wwwroot;
69 $mnethost->name = '';
70 $mnethost->name = '';
71 $mnethost->public_key = '';
72
73 if (empty($_SERVER['SERVER_ADDR'])) {
74 // SERVER_ADDR is only returned by Apache-like webservers
75 preg_match("@^(?:http[s]?://)?([A-Z0-9\-\.]+).*@i", $CFG->wwwroot, $matches);
76 $my_hostname = $matches[1];
77 $my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH!
78 if ($my_ip == $my_hostname) {
79 $mnethost->ip_address = 'UNKNOWN';
80 } else {
81 $mnethost->ip_address = $my_ip;
82 }
83 } else {
84 $mnethost->ip_address = $_SERVER['SERVER_ADDR'];
85 }
86
87 $mnetid = $DB->insert_record('mnet_host', $mnethost);
88 set_config('mnet_localhost_id', $mnetid);
89
c20ce874 90 // Initial insert of mnet applications info
91 $mnet_app = new object();
92 $mnet_app->name = 'moodle';
93 $mnet_app->display_name = 'Moodle';
94 $mnet_app->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
95 $mnet_app->sso_land_url = '/auth/mnet/land.php';
96 $mnet_app->sso_jump_url = '/auth/mnet/land.php';
6f4f82f2 97 $moodleapplicationid = $DB->insert_record('mnet_application', $mnet_app);
c20ce874 98
99 $mnet_app = new object();
100 $mnet_app->name = 'mahara';
101 $mnet_app->display_name = 'Mahara';
102 $mnet_app->xmlrpc_server_url = '/api/xmlrpc/server.php';
103 $mnet_app->sso_land_url = '/auth/xmlrpc/land.php';
104 $mnet_app->sso_jump_url = '/auth/xmlrpc/jump.php';
105 $DB->insert_record('mnet_application', $mnet_app);
106
6f4f82f2
PS
107 // Set up the probably-to-be-removed-soon 'All hosts' record
108 $mnetallhosts = new object();
109 $mnetallhosts->wwwroot = '';
110 $mnetallhosts->ip_address = '';
111 $mnetallhosts->public_key = '';
112 $mnetallhosts->public_key_expires = 0;
113 $mnetallhosts->last_connect_time = 0;
114 $mnetallhosts->last_log_id = 0;
115 $mnetallhosts->deleted = 0;
116 $mnetallhosts->name = 'All Hosts';
117 $mnetallhosts->applicationid = $moodleapplicationid;
118 $mnetallhosts->id = $DB->insert_record('mnet_host', $mnetallhosts, true);
119 set_config('mnet_all_hosts_id', $mnetallhosts->id);
88582df4 120
4f0c2d00 121 /// insert log entries - replaces statements section in install.xml
0d6b8715
SH
122 update_log_display_entry('user', 'view', 'user', $DB->sql_concat('firstname', "' '" , 'lastname'));
123 update_log_display_entry('course', 'user report', 'user', $DB->sql_concat('firstname', "' '" , 'lastname'));
0cb93a7e 124 update_log_display_entry('course', 'view', 'course', 'fullname');
125 update_log_display_entry('course', 'update', 'course', 'fullname');
df997f84
PS
126 update_log_display_entry('course', 'enrol', 'user', 'course', 'fullname'); // there should be some way to store user id of the enrolled user!
127 update_log_display_entry('course', 'unenrol', 'user', 'course', 'fullname'); // there should be some way to store user id of the enrolled user!
0cb93a7e 128 update_log_display_entry('course', 'report log', 'course', 'fullname');
129 update_log_display_entry('course', 'report live', 'course', 'fullname');
130 update_log_display_entry('course', 'report outline', 'course', 'fullname');
131 update_log_display_entry('course', 'report participation', 'course', 'fullname');
132 update_log_display_entry('course', 'report stats', 'course', 'fullname');
0d6b8715
SH
133 update_log_display_entry('message', 'write', 'user', $DB->sql_concat('firstname', "' '" , 'lastname'));
134 update_log_display_entry('message', 'read', 'user', $DB->sql_concat('firstname', "' '" , 'lastname'));
135 update_log_display_entry('message', 'add contact', 'user', $DB->sql_concat('firstname', "' '" , 'lastname'));
136 update_log_display_entry('message', 'remove contact', 'user', $DB->sql_concat('firstname', "' '" , 'lastname'));
137 update_log_display_entry('message', 'block contact', 'user', $DB->sql_concat('firstname', "' '" , 'lastname'));
138 update_log_display_entry('message', 'unblock contact', 'user', $DB->sql_concat('firstname', "' '" , 'lastname'));
0cb93a7e 139 update_log_display_entry('group', 'view', 'groups', 'name');
b89e4ad8 140 update_log_display_entry('tag', 'update', 'tag', 'name');
c20ce874 141
1caea91e 142
4f0c2d00 143 /// Create guest record - do not assign any role, guest user get's the default guest role automatically on the fly
88582df4 144 $guest = new object();
145 $guest->auth = 'manual';
146 $guest->username = 'guest';
147 $guest->password = hash_internal_user_password('guest');
148 $guest->firstname = get_string('guestuser');
149 $guest->lastname = ' ';
150 $guest->email = 'root@localhost';
151 $guest->description = get_string('guestuserinfo');
152 $guest->mnethostid = $CFG->mnet_localhost_id;
153 $guest->confirmed = 1;
154 $guest->lang = $CFG->lang;
155 $guest->timemodified= time();
156 $guest->id = $DB->insert_record('user', $guest);
157
158
4f0c2d00 159 /// Now create admin user
88582df4 160 $admin = new object();
161 $admin->auth = 'manual';
162 $admin->firstname = get_string('admin');
163 $admin->lastname = get_string('user');
164 $admin->username = 'admin';
165 $admin->password = 'adminsetuppending';
1deff123 166 $admin->email = '';
88582df4 167 $admin->confirmed = 1;
168 $admin->mnethostid = $CFG->mnet_localhost_id;
169 $admin->lang = $CFG->lang;
170 $admin->maildisplay = 1;
171 $admin->timemodified = time();
aa282b10 172 $admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr(); // installation hijacking prevention
88582df4 173 $admin->id = $DB->insert_record('user', $admin);
4f0c2d00
PS
174 /// Store list of admins
175 set_config('siteadmins', $admin->id);
88582df4 176
1caea91e 177
4f0c2d00
PS
178 /// Install the roles system.
179 $managerrole = create_role(get_string('manager', 'role'), 'manager', get_string('managerdescription', 'role'), 'manager');
180 $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'coursecreator');
181 $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'editingteacher');
182 $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'teacher');
183 $studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'student');
184 $guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'guest');
185 $userrole = create_role(get_string('authenticateduser'), 'user', get_string('authenticateduserdescription'), 'user');
186 $frontpagerole = create_role(get_string('frontpageuser', 'role'), 'frontpage', get_string('frontpageuserdescription', 'role'), 'frontpage');
88582df4 187
188 /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
88582df4 189 update_capabilities('moodle');
c976e271 190 external_update_descriptions('moodle');
88582df4 191
4f0c2d00
PS
192 /// Default allow assign
193 $defaultallowassigns = array(
194 array($managerrole, $managerrole),
195 array($managerrole, $coursecreatorrole),
196 array($managerrole, $editteacherrole),
197 array($managerrole, $noneditteacherrole),
198 array($managerrole, $studentrole),
88582df4 199
4f0c2d00
PS
200 array($editteacherrole, $noneditteacherrole),
201 array($editteacherrole, $studentrole),
c468795c 202 );
4f0c2d00
PS
203 foreach ($defaultallowassigns as $allow) {
204 list($fromroleid, $toroleid) = $allow;
c468795c 205 allow_assign($fromroleid, $toroleid);
4f0c2d00
PS
206 }
207
208 /// Default allow override
209 $defaultallowoverrides = array(
210 array($managerrole, $managerrole),
211 array($managerrole, $coursecreatorrole),
212 array($managerrole, $editteacherrole),
213 array($managerrole, $noneditteacherrole),
214 array($managerrole, $studentrole),
215 array($managerrole, $guestrole),
216 array($managerrole, $userrole),
217 array($managerrole, $frontpagerole),
218
219 array($editteacherrole, $noneditteacherrole),
220 array($editteacherrole, $studentrole),
221 array($editteacherrole, $guestrole),
222 );
223 foreach ($defaultallowoverrides as $allow) {
224 list($fromroleid, $toroleid) = $allow;
c468795c 225 allow_override($fromroleid, $toroleid); // There is a rant about this in MDL-15841.
4f0c2d00
PS
226 }
227
228 /// Default allow switch.
229 $defaultallowswitch = array(
230 array($managerrole, $editteacherrole),
231 array($managerrole, $noneditteacherrole),
232 array($managerrole, $studentrole),
233 array($managerrole, $guestrole),
234
235 array($editteacherrole, $noneditteacherrole),
236 array($editteacherrole, $studentrole),
237 array($editteacherrole, $guestrole),
238
239 array($noneditteacherrole, $studentrole),
240 array($noneditteacherrole, $guestrole),
241 );
242 foreach ($defaultallowswitch as $allow) {
243 list($fromroleid, $toroleid) = $allow;
c468795c 244 allow_switch($fromroleid, $toroleid);
245 }
88582df4 246
247 /// Set up the context levels where you can assign each role.
4f0c2d00 248 set_role_contextlevels($managerrole, get_default_contextlevels('manager'));
88582df4 249 set_role_contextlevels($coursecreatorrole, get_default_contextlevels('coursecreator'));
250 set_role_contextlevels($editteacherrole, get_default_contextlevels('editingteacher'));
251 set_role_contextlevels($noneditteacherrole, get_default_contextlevels('teacher'));
252 set_role_contextlevels($studentrole, get_default_contextlevels('student'));
253 set_role_contextlevels($guestrole, get_default_contextlevels('guest'));
254 set_role_contextlevels($userrole, get_default_contextlevels('user'));
ac173d3e 255
4f0c2d00 256 // Init themes
78946b9b 257 set_config('themerev', 1);
b64b465c
PS
258
259 // Install licenses
260 require_once($CFG->libdir . '/licenselib.php');
261 license_manager::install_licenses();
03d9401e
MD
262
263 /// Add two lines of data into this new table
264 $mypage = new object();
265 $mypage->userid = NULL;
266 $mypage->name = '__default';
267 $mypage->private = 0;
268 $mypage->sortorder = 0;
269 if (!$DB->record_exists('my_pages', array('userid'=>NULL, 'private'=>0))) {
270 $DB->insert_record('my_pages', $mypage);
271 }
272 $mypage->private = 1;
273 if (!$DB->record_exists('my_pages', array('userid'=>NULL, 'private'=>1))) {
274 $DB->insert_record('my_pages', $mypage);
275 }
117bd748 276}