forked from moodle/moodle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinstall.php
217 lines (186 loc) · 9.82 KB
/
install.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
<?php //$Id$
// This file is executed right after the install.xml
//
function xmldb_main_install() {
global $CFG, $DB, $SITE;
/// make sure system context exists
$syscontext = get_system_context(false);
if ($syscontext->id != 1) {
throw new moodle_exception('generalexceptionmessage', '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('generalexceptionmessage', '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(
'rolesactive' => '0', // marks fully set up system
'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).get_host_from_url($CFG->wwwroot),
'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
'stringfilters' => '', // These two are managed in a strange way by the filters
'filterall' => 0, // setting page, so have to be initialised here.
'texteditors' => 'tinymce,textarea',
);
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);
// Initial insert of mnet applications info
$mnet_app = new object();
$mnet_app->name = 'moodle';
$mnet_app->display_name = 'Moodle';
$mnet_app->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
$mnet_app->sso_land_url = '/auth/mnet/land.php';
$mnet_app->sso_jump_url = '/auth/mnet/land.php';
$DB->insert_record('mnet_application', $mnet_app);
$mnet_app = new object();
$mnet_app->name = 'mahara';
$mnet_app->display_name = 'Mahara';
$mnet_app->xmlrpc_server_url = '/api/xmlrpc/server.php';
$mnet_app->sso_land_url = '/auth/xmlrpc/land.php';
$mnet_app->sso_jump_url = '/auth/xmlrpc/jump.php';
$DB->insert_record('mnet_application', $mnet_app);
/// insert log entries - replaces statements section in install.xml
update_log_display_entry('user', 'view', 'user', 'CONCAT(firstname,\' \',lastname)');
update_log_display_entry('course', 'user report', 'user', 'CONCAT(firstname,\' \',lastname)');
update_log_display_entry('course', 'view', 'course', 'fullname');
update_log_display_entry('course', 'update', 'course', 'fullname');
update_log_display_entry('course', 'enrol', 'course', 'fullname');
update_log_display_entry('course', 'unenrol', 'course', 'fullname');
update_log_display_entry('course', 'report log', 'course', 'fullname');
update_log_display_entry('course', 'report live', 'course', 'fullname');
update_log_display_entry('course', 'report outline', 'course', 'fullname');
update_log_display_entry('course', 'report participation', 'course', 'fullname');
update_log_display_entry('course', 'report stats', 'course', 'fullname');
update_log_display_entry('message', 'write', 'user', 'CONCAT(firstname,\' \',lastname)');
update_log_display_entry('message', 'read', 'user', 'CONCAT(firstname,\' \',lastname)');
update_log_display_entry('message', 'add contact', 'user', 'CONCAT(firstname,\' \',lastname)');
update_log_display_entry('message', 'remove contact', 'user', 'CONCAT(firstname,\' \',lastname)');
update_log_display_entry('message', 'block contact', 'user', 'CONCAT(firstname,\' \',lastname)');
update_log_display_entry('message', 'unblock contact', 'user', 'CONCAT(firstname,\' \',lastname)');
update_log_display_entry('group', 'view', 'groups', 'name');
/// Create guest record
$guest = new object();
$guest->auth = 'manual';
$guest->username = 'guest';
$guest->password = hash_internal_user_password('guest');
$guest->firstname = get_string('guestuser');
$guest->lastname = ' ';
$guest->email = 'root@localhost';
$guest->description = get_string('guestuserinfo');
$guest->mnethostid = $CFG->mnet_localhost_id;
$guest->confirmed = 1;
$guest->lang = $CFG->lang;
$guest->timemodified= time();
$guest->id = $DB->insert_record('user', $guest);
/// Now create admin user
$admin = new object();
$admin->auth = 'manual';
$admin->firstname = get_string('admin');
$admin->lastname = get_string('user');
$admin->username = 'admin';
$admin->password = 'adminsetuppending';
$admin->email = '';
$admin->confirmed = 1;
$admin->mnethostid = $CFG->mnet_localhost_id;
$admin->lang = $CFG->lang;
$admin->maildisplay = 1;
$admin->timemodified = time();
$admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr(); // installation hijacking prevention
$admin->id = $DB->insert_record('user', $admin);
/// Install the roles system.
$adminrole = create_role(get_string('administrator'), 'admin',
get_string('administratordescription'), 'moodle/legacy:admin');
$coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator',
get_string('coursecreatorsdescription'), 'moodle/legacy:coursecreator');
$editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher',
get_string('defaultcourseteacherdescription'), 'moodle/legacy:editingteacher');
$noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher',
get_string('noneditingteacherdescription'), 'moodle/legacy:teacher');
$studentrole = create_role(get_string('defaultcoursestudent'), 'student',
get_string('defaultcoursestudentdescription'), 'moodle/legacy:student');
$guestrole = create_role(get_string('guest'), 'guest',
get_string('guestdescription'), 'moodle/legacy:guest');
$userrole = create_role(get_string('authenticateduser'), 'user',
get_string('authenticateduserdescription'), 'moodle/legacy:user');
/// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
assign_capability('moodle/site:doanything', CAP_ALLOW, $adminrole, $syscontext->id);
update_capabilities('moodle');
/// assign default roles
role_assign($guestrole, $guest->id, 0, $syscontext->id);
role_assign($adminrole, $admin->id, 0, $syscontext->id);
/// Default allow assign/override/switch.
$defaultallows = array(
$coursecreatorrole => $noneditteacherrole,
$coursecreatorrole => $editteacherrole,
$coursecreatorrole => $studentrole,
$coursecreatorrole => $guestrole,
$editteacherrole => $noneditteacherrole,
$editteacherrole => $studentrole,
$editteacherrole => $guestrole,
);
foreach ($defaultallows as $fromroleid => $toroleid) {
allow_assign($fromroleid, $toroleid);
allow_override($fromroleid, $toroleid); // There is a rant about this in MDL-15841.
allow_switch($fromroleid, $toroleid);
}
allow_switch($noneditteacherrole, $studentrole);
/// Set up the context levels where you can assign each role.
set_role_contextlevels($adminrole, get_default_contextlevels('admin'));
set_role_contextlevels($coursecreatorrole, get_default_contextlevels('coursecreator'));
set_role_contextlevels($editteacherrole, get_default_contextlevels('editingteacher'));
set_role_contextlevels($noneditteacherrole, get_default_contextlevels('teacher'));
set_role_contextlevels($studentrole, get_default_contextlevels('student'));
set_role_contextlevels($guestrole, get_default_contextlevels('guest'));
set_role_contextlevels($userrole, get_default_contextlevels('user'));
}