Merge branch 'MDL-30966-print-object_21_STABLE' of git://github.com/mudrd8mz/moodle...
[moodle.git] / enrol / ldap / db / install.php
blobbb559a2ba862b3deb66a25c2fccab1f81ad3eef3
1 <?php
3 // This file is part of Moodle - http://moodle.org/
4 //
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.
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/>.
18 /**
19 * LDAP enrolment plugin installation.
21 * @package enrol
22 * @subpackage ldap
23 * @author Iñaki Arenaza
24 * @copyright 2010 Iñaki Arenaza <iarenaza@eps.mondragon.edu>
25 * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
28 defined('MOODLE_INTERNAL') || die();
30 function xmldb_enrol_ldap_install() {
31 global $CFG, $DB;
33 // Check for the presence of old 'legacy' config settings. If they
34 // exist, correct them.
35 if (isset($CFG->enrol_ldap_student_contexts)) {
36 if ($student_role = $DB->get_record('role', array('shortname' => 'student'))) {
37 set_config('enrol_ldap_contexts_role'.$student_role->id, $CFG->enrol_ldap_student_contexts);
39 unset_config('enrol_ldap_student_contexts');
42 if (isset($CFG->enrol_ldap_student_memberattribute)) {
43 if (isset($student_role) or $student_role = $DB->get_record('role', array('shortname' => 'student'))) {
44 set_config('enrol_ldap_memberattribute_role'.$student_role->id, $CFG->enrol_ldap_student_memberattribute);
46 unset_config('enrol_ldap_student_memberattribute');
49 if (isset($CFG->enrol_ldap_teacher_contexts)) {
50 if ($teacher_role = $DB->get_record('role', array('shortname' => 'editingteacher'))) {
51 set_config('enrol_ldap_contexts_role'.$teacher_role->id, $CFG->enrol_ldap_student_contexts);
53 unset_config('enrol_ldap_teacher_contexts');
56 if (isset($CFG->enrol_ldap_teacher_memberattribute)) {
57 if (isset($teacher_role) or $teacher_role = $DB->get_record('role', array('shortname' => 'teacher'))) {
58 set_config('enrol_ldap_memberattribute_role'.$teacher_role->id, $CFG->enrol_ldap_teacher_memberattribute);
61 unset_config('enrol_ldap_teacher_memberattribute');
64 // Now migrate the real plugin settings. 'enrol_ldap_version' is the only
65 // setting that cannot be migrated like the rest, as it clashes with the
66 // plugin version number once we strip the 'enrol_ldap_' prefix.
67 if (isset($CFG->enrol_ldap_version)) {
68 set_config('ldap_version', $CFG->enrol_ldap_version, 'enrol_ldap');
69 unset_config('enrol_ldap_version');
72 $settings = array ('host_url', 'bind_dn', 'bind_pw', 'objectclass', 'course_idnumber',
73 'course_shortname', 'course_fullname', 'course_summary',
74 'course_shortname_updatelocal', 'course_fullname_updatelocal', 'course_summary_updatelocal',
75 'course_shortname_editlock', 'course_fullname_editlock', 'course_summary_editlock',
76 'autocreate', 'category', 'template');
78 // Add roles settings to the array of settings to migrate.
79 $roles = $DB->get_records('role');
80 foreach($roles as $role) {
81 array_push($settings, 'contexts_role'.$role->id);
82 array_push($settings, 'memberattribute_role'.$role->id);
85 // Migrate all the settings from $CFG->enrol_ldap_XXXXX to the
86 // plugin configuration in mdl_config_plugin, stripping the 'enrol_ldap_' prefix.
87 foreach ($settings as $setting) {
88 if (isset($CFG->{'enrol_ldap_'.$setting})) {
89 set_config($setting, $CFG->{'enrol_ldap_'.$setting}, 'enrol_ldap');
90 unset_config('enrol_ldap_'.$setting);
94 // $CFG->enrol_ldap_search_sub is special, as we need to rename it to
95 // course_search_sub' (there is also a new search_sub for users)
96 if (isset($CFG->enrol_ldap_search_sub)) {
97 set_config('course_search_sub', $CFG->enrol_ldap_search_sub, 'enrol_ldap');
98 unset_config('enrol_ldap_search_sub');
101 // Remove a setting that's never been used at all
102 if (isset($CFG->enrol_ldap_user_memberfield)) {
103 unset_config('enrol_ldap_user_memberfield');