Moodle  2.2.1
http://www.collinsharper.com
C:/xampp/htdocs/moodle/enrol/ldap/db/install.php
Go to the documentation of this file.
00001 <?php
00002 
00003 // This file is part of Moodle - http://moodle.org/
00004 //
00005 // Moodle is free software: you can redistribute it and/or modify
00006 // it under the terms of the GNU General Public License as published by
00007 // the Free Software Foundation, either version 3 of the License, or
00008 // (at your option) any later version.
00009 //
00010 // Moodle is distributed in the hope that it will be useful,
00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 // GNU General Public License for more details.
00014 //
00015 // You should have received a copy of the GNU General Public License
00016 // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
00017 
00028 defined('MOODLE_INTERNAL') || die();
00029 
00030 function xmldb_enrol_ldap_install() {
00031     global $CFG, $DB;
00032 
00033     // Check for the presence of old 'legacy' config settings. If they
00034     // exist, correct them.
00035     if (isset($CFG->enrol_ldap_student_contexts)) {
00036         if ($student_role = $DB->get_record('role', array('shortname' => 'student'))) {
00037             set_config('enrol_ldap_contexts_role'.$student_role->id, $CFG->enrol_ldap_student_contexts);
00038         }
00039         unset_config('enrol_ldap_student_contexts');
00040     }
00041 
00042     if (isset($CFG->enrol_ldap_student_memberattribute)) {
00043         if (isset($student_role) or $student_role = $DB->get_record('role', array('shortname' => 'student'))) {
00044             set_config('enrol_ldap_memberattribute_role'.$student_role->id, $CFG->enrol_ldap_student_memberattribute);
00045         }
00046         unset_config('enrol_ldap_student_memberattribute');
00047     }
00048 
00049     if (isset($CFG->enrol_ldap_teacher_contexts)) {
00050         if ($teacher_role = $DB->get_record('role', array('shortname' => 'editingteacher'))) {
00051             set_config('enrol_ldap_contexts_role'.$teacher_role->id, $CFG->enrol_ldap_student_contexts);
00052         }
00053         unset_config('enrol_ldap_teacher_contexts');
00054     }
00055 
00056     if (isset($CFG->enrol_ldap_teacher_memberattribute)) {
00057         if (isset($teacher_role) or $teacher_role = $DB->get_record('role', array('shortname' => 'teacher'))) {
00058             set_config('enrol_ldap_memberattribute_role'.$teacher_role->id, $CFG->enrol_ldap_teacher_memberattribute);
00059         }
00060 
00061         unset_config('enrol_ldap_teacher_memberattribute');
00062     }
00063 
00064     // Now migrate the real plugin settings. 'enrol_ldap_version' is the only
00065     // setting that cannot be migrated like the rest, as it clashes with the
00066     // plugin version number once we strip the 'enrol_ldap_' prefix.
00067     if (isset($CFG->enrol_ldap_version)) {
00068         set_config('ldap_version', $CFG->enrol_ldap_version, 'enrol_ldap');
00069         unset_config('enrol_ldap_version');
00070     }
00071 
00072     $settings = array ('host_url', 'bind_dn', 'bind_pw', 'objectclass', 'course_idnumber',
00073                        'course_shortname', 'course_fullname', 'course_summary',
00074                        'course_shortname_updatelocal', 'course_fullname_updatelocal', 'course_summary_updatelocal',
00075                        'course_shortname_editlock', 'course_fullname_editlock', 'course_summary_editlock',
00076                        'autocreate', 'category', 'template');
00077 
00078     // Add roles settings to the array of settings to migrate.
00079     $roles = $DB->get_records('role');
00080     foreach($roles as $role) {
00081         array_push($settings, 'contexts_role'.$role->id);
00082         array_push($settings, 'memberattribute_role'.$role->id);
00083     }
00084 
00085     // Migrate all the settings from $CFG->enrol_ldap_XXXXX to the
00086     // plugin configuration in mdl_config_plugin, stripping the 'enrol_ldap_' prefix.
00087     foreach ($settings as $setting) {
00088         if (isset($CFG->{'enrol_ldap_'.$setting})) {
00089             set_config($setting, $CFG->{'enrol_ldap_'.$setting}, 'enrol_ldap');
00090             unset_config('enrol_ldap_'.$setting);
00091         }
00092     }
00093 
00094     // $CFG->enrol_ldap_search_sub is special, as we need to rename it to
00095     // course_search_sub' (there is also a new search_sub for users)
00096     if (isset($CFG->enrol_ldap_search_sub)) {
00097         set_config('course_search_sub', $CFG->enrol_ldap_search_sub, 'enrol_ldap');
00098         unset_config('enrol_ldap_search_sub');
00099     }
00100 
00101     // Remove a setting that's never been used at all
00102     if (isset($CFG->enrol_ldap_user_memberfield)) {
00103         unset_config('enrol_ldap_user_memberfield');
00104     }
00105 }
 All Data Structures Namespaces Files Functions Variables Enumerations