portfolio/leap2a MDL-23955 updated leap2a support to 2010-07 version
[moodle.git] / lib / db / install.php
CommitLineData
117bd748 1<?php
1caea91e 2
5b4a78e2 3// This file is part of Moodle - http://moodle.org/
1caea91e 4//
5b4a78e2
PS
5// Moodle is free software: you can redistribute it and/or modify
6// it under the terms of the GNU General Public License as published by
7// the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// Moodle is distributed in the hope that it will be useful,
11// but WITHOUT ANY WARRANTY; without even the implied warranty of
12// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13// GNU General Public License for more details.
14//
15// You should have received a copy of the GNU General Public License
16// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
17
18/**
19 * This file is executed right after the install.xml
20 *
21 * @package core
22 * @subpackage admin
23 * @copyright 2009 Petr Skoda (http://skodak.org)
24 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25 */
26
27defined('MOODLE_INTERNAL') || die();
1caea91e 28
c20ce874 29function xmldb_main_install() {
1caea91e 30 global $CFG, $DB, $SITE;
31
4f0c2d00 32 /// make sure system context exists
b4154c2d 33 $syscontext = get_system_context(false);
1caea91e 34 if ($syscontext->id != 1) {
19a4a32e 35 throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected system context id created!');
1caea91e 36 }
37
38
4f0c2d00 39 /// create site course
1caea91e 40 $newsite = new object();
41 $newsite->fullname = "";
42 $newsite->shortname = "";
43 $newsite->summary = NULL;
44 $newsite->newsitems = 3;
45 $newsite->numsections = 0;
46 $newsite->category = 0;
47 $newsite->format = 'site'; // Only for this course
48 $newsite->teacher = get_string("defaultcourseteacher");
49 $newsite->teachers = get_string("defaultcourseteachers");
50 $newsite->student = get_string("defaultcoursestudent");
51 $newsite->students = get_string("defaultcoursestudents");
52 $newsite->timemodified = time();
53
54 $DB->insert_record('course', $newsite);
55 $SITE = get_site();
56 if ($SITE->id != 1) {
19a4a32e 57 throw new moodle_exception('generalexceptionmessage', 'error', '', 'Unexpected site course id created!');
1caea91e 58 }
59
60
4f0c2d00 61 /// make sure site course context exists
1caea91e 62 get_context_instance(CONTEXT_COURSE, $SITE->id);
63
4f0c2d00 64 /// create default course category
1caea91e 65 $cat = get_course_category();
66
5b8fa09b 67 $defaults = array(
68 'rolesactive' => '0', // marks fully set up system
69 'auth' => 'email',
70 'auth_pop3mailbox' => 'INBOX',
df997f84 71 'enrol_plugins_enabled' => 'manual,guest,self,cohort',
5f0baa43 72 'theme' => theme_config::DEFAULT_THEME,
5b8fa09b 73 'filter_multilang_converted' => 1,
aa282b10 74 'siteidentifier' => random_string(32).get_host_from_url($CFG->wwwroot),
5b8fa09b 75 'backup_version' => 2008111700,
76 'backup_release' => '2.0 dev',
77 'blocks_version' => 2007081300, // might be removed soon
78 'mnet_dispatcher_mode' => 'off',
79 'sessiontimeout' => 7200, // must be present during roles installation
80 'stringfilters' => '', // These two are managed in a strange way by the filters
81 'filterall' => 0, // setting page, so have to be initialised here.
a5747cf8 82 'texteditors' => 'tinymce,textarea',
5b8fa09b 83 );
1caea91e 84 foreach($defaults as $key => $value) {
85 set_config($key, $value);
86 }
87
88
4f0c2d00 89 /// bootstrap mnet
1caea91e 90 $mnethost = new object();
91 $mnethost->wwwroot = $CFG->wwwroot;
92 $mnethost->name = '';
93 $mnethost->name = '';
94 $mnethost->public_key = '';
95
96 if (empty($_SERVER['SERVER_ADDR'])) {
97 // SERVER_ADDR is only returned by Apache-like webservers
98 preg_match("@^(?:http[s]?://)?([A-Z0-9\-\.]+).*@i", $CFG->wwwroot, $matches);
99 $my_hostname = $matches[1];
100 $my_ip = gethostbyname($my_hostname); // Returns unmodified hostname on failure. DOH!
101 if ($my_ip == $my_hostname) {
102 $mnethost->ip_address = 'UNKNOWN';
103 } else {
104 $mnethost->ip_address = $my_ip;
105 }
106 } else {
107 $mnethost->ip_address = $_SERVER['SERVER_ADDR'];
108 }
109
110 $mnetid = $DB->insert_record('mnet_host', $mnethost);
111 set_config('mnet_localhost_id', $mnetid);
112
c20ce874 113 // Initial insert of mnet applications info
114 $mnet_app = new object();
115 $mnet_app->name = 'moodle';
116 $mnet_app->display_name = 'Moodle';
117 $mnet_app->xmlrpc_server_url = '/mnet/xmlrpc/server.php';
118 $mnet_app->sso_land_url = '/auth/mnet/land.php';
119 $mnet_app->sso_jump_url = '/auth/mnet/land.php';
6f4f82f2 120 $moodleapplicationid = $DB->insert_record('mnet_application', $mnet_app);
c20ce874 121
122 $mnet_app = new object();
123 $mnet_app->name = 'mahara';
124 $mnet_app->display_name = 'Mahara';
125 $mnet_app->xmlrpc_server_url = '/api/xmlrpc/server.php';
126 $mnet_app->sso_land_url = '/auth/xmlrpc/land.php';
127 $mnet_app->sso_jump_url = '/auth/xmlrpc/jump.php';
128 $DB->insert_record('mnet_application', $mnet_app);
129
6f4f82f2
PS
130 // Set up the probably-to-be-removed-soon 'All hosts' record
131 $mnetallhosts = new object();
132 $mnetallhosts->wwwroot = '';
133 $mnetallhosts->ip_address = '';
134 $mnetallhosts->public_key = '';
135 $mnetallhosts->public_key_expires = 0;
136 $mnetallhosts->last_connect_time = 0;
137 $mnetallhosts->last_log_id = 0;
138 $mnetallhosts->deleted = 0;
139 $mnetallhosts->name = 'All Hosts';
140 $mnetallhosts->applicationid = $moodleapplicationid;
141 $mnetallhosts->id = $DB->insert_record('mnet_host', $mnetallhosts, true);
142 set_config('mnet_all_hosts_id', $mnetallhosts->id);
88582df4 143
4f0c2d00 144 /// Create guest record - do not assign any role, guest user get's the default guest role automatically on the fly
88582df4 145 $guest = new object();
146 $guest->auth = 'manual';
147 $guest->username = 'guest';
148 $guest->password = hash_internal_user_password('guest');
149 $guest->firstname = get_string('guestuser');
150 $guest->lastname = ' ';
151 $guest->email = 'root@localhost';
152 $guest->description = get_string('guestuserinfo');
153 $guest->mnethostid = $CFG->mnet_localhost_id;
154 $guest->confirmed = 1;
155 $guest->lang = $CFG->lang;
156 $guest->timemodified= time();
157 $guest->id = $DB->insert_record('user', $guest);
158
159
4f0c2d00 160 /// Now create admin user
88582df4 161 $admin = new object();
162 $admin->auth = 'manual';
163 $admin->firstname = get_string('admin');
164 $admin->lastname = get_string('user');
165 $admin->username = 'admin';
166 $admin->password = 'adminsetuppending';
1deff123 167 $admin->email = '';
88582df4 168 $admin->confirmed = 1;
169 $admin->mnethostid = $CFG->mnet_localhost_id;
170 $admin->lang = $CFG->lang;
171 $admin->maildisplay = 1;
172 $admin->timemodified = time();
aa282b10 173 $admin->lastip = CLI_SCRIPT ? '0.0.0.0' : getremoteaddr(); // installation hijacking prevention
88582df4 174 $admin->id = $DB->insert_record('user', $admin);
4f0c2d00
PS
175 /// Store list of admins
176 set_config('siteadmins', $admin->id);
88582df4 177
1caea91e 178
4f0c2d00
PS
179 /// Install the roles system.
180 $managerrole = create_role(get_string('manager', 'role'), 'manager', get_string('managerdescription', 'role'), 'manager');
181 $coursecreatorrole = create_role(get_string('coursecreators'), 'coursecreator', get_string('coursecreatorsdescription'), 'coursecreator');
182 $editteacherrole = create_role(get_string('defaultcourseteacher'), 'editingteacher', get_string('defaultcourseteacherdescription'), 'editingteacher');
183 $noneditteacherrole = create_role(get_string('noneditingteacher'), 'teacher', get_string('noneditingteacherdescription'), 'teacher');
184 $studentrole = create_role(get_string('defaultcoursestudent'), 'student', get_string('defaultcoursestudentdescription'), 'student');
185 $guestrole = create_role(get_string('guest'), 'guest', get_string('guestdescription'), 'guest');
186 $userrole = create_role(get_string('authenticateduser'), 'user', get_string('authenticateduserdescription'), 'user');
187 $frontpagerole = create_role(get_string('frontpageuser', 'role'), 'frontpage', get_string('frontpageuserdescription', 'role'), 'frontpage');
88582df4 188
189 /// Now is the correct moment to install capabilities - after creation of legacy roles, but before assigning of roles
88582df4 190 update_capabilities('moodle');
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}