]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-12296:
authorthepurpleblob <thepurpleblob>
Wed, 21 Nov 2007 11:06:46 +0000 (11:06 +0000)
committerthepurpleblob <thepurpleblob>
Wed, 21 Nov 2007 11:06:46 +0000 (11:06 +0000)
Added option to prevent database enrolment plugin unenrolling users.

Merged from STABLE_19

enrol/database/config.html
enrol/database/enrol.php
lang/en_utf8/enrol_database.php

index df1ed6d4b0a42ab66ac77fc8fa6c4d47bf3136b8..6d2bea35e92e5e4c1b641ad69f4842816defeb27 100644 (file)
     </td>
 </tr>
 
+<tr>
+    <td align="right">enrol_db_disableunenrol:</td>
+    <td>
+    <?php
+        choose_from_menu($yesno, "enrol_db_disableunenrol", $frm->enrol_db_disableunenrol, "");
+        if (isset($err['enrol_db_disableunenrol'])) {
+            formerr($err['enrol_db_disableunenrol']);
+        }
+    ?>
+    </td>
+    <td>
+        <?php print_string('disableunenrol', 'enrol_database' ); ?>
+    </td>
+</tr>
 </table>
index dbd07282f7355ab5332c6ed00524d95c04d346e0..761e5b285b5d0afe3710e675cb4323cc522b06e4 100644 (file)
@@ -150,10 +150,13 @@ function setup_enrolments(&$user) {
 
             /// We have some courses left that we might need to unenrol from
             /// Note: we only process enrolments that we (ie 'database' plugin) made
-            foreach ($existing as $role_assignment) {
-                if ($role_assignment->enrol == 'database') {
-                    //error_log('[ENROL_DB] Removing user from context '.$role_assignment->contextid);
-                    role_unassign($role_assignment->roleid, $user->id, '', $role_assignment->contextid);
+            /// Do not unenrol anybody if the disableunenrol option is 'yes'
+            if (!$CFG->enrol_db_disableunenrol) {
+                foreach ($existing as $role_assignment) {
+                    if ($role_assignment->enrol == 'database') {
+                        //error_log('[ENROL_DB] Removing user from context '.$role_assignment->contextid);
+                        role_unassign($role_assignment->roleid, $user->id, '', $role_assignment->contextid);
+                    } 
                 }
             }
         } else {
@@ -422,7 +425,8 @@ function config_form($frm) {
                   'enrol_db_autocreate', 'enrol_db_category', 'enrol_db_template',
                   'enrol_db_localrolefield', 'enrol_db_remoterolefield',
                   'enrol_remotecoursefield', 'enrol_remoteuserfield',
-                  'enrol_db_ignorehiddencourse', 'enrol_db_defaultcourseroleid');
+                  'enrol_db_ignorehiddencourse', 'enrol_db_defaultcourseroleid',
+                  'enrol_db_disableunenrol');
 
     foreach ($vars as $var) {
         if (!isset($frm->$var)) {
@@ -520,6 +524,11 @@ function process_config($config) {
     }
     set_config('enrol_db_ignorehiddencourse', $config->enrol_db_ignorehiddencourse );
 
+    if (!isset($config->enrol_db_disableunenrol)) {
+        $config->enrol_db_disableunenrol = '';
+    }
+    set_config('enrol_db_disableunenrol', $config->enrol_db_disableunenrol );
+
     return true;
 }
 
@@ -609,6 +618,14 @@ function create_course ($course,$skip_fix_course_sortorder=0){
     return $newcourseid;
 }
 
+/**
+ * Test the database connection
+ * @return true if it works
+ */
+function test() {
+    return true;
+}
+
 /// DB Connect
 /// NOTE: You MUST remember to disconnect
 /// when you stop using it -- as this call will
index 1d6948af50030dfce7364c9cf71f648024c0e7fd..e0db63b4b729f8632ec54489bfbf6322cd60f717 100644 (file)
@@ -17,6 +17,7 @@ $string['dbname'] = 'Database name';
 $string['dbtable'] = 'Database table';
 $string['defaultcourseroleid'] = 'The role that will be assigned by default if no other role is specified.';
 $string['description'] = 'You can use a external database (of nearly any kind) to control your enrolments. It is assumed your external database contains a field containing a course ID, and a field containing a user ID. These are compared against fields that you choose in the local course and user tables.';
+$string['disableunenrol'] = 'If set to yes users previously enrolled by the external database plugin will not be unenrolled by the same plugin regardless of the database contents.';
 $string['enrolname'] = 'External Database';
 $string['enrol_database_autocreation_settings'] = 'Auto-creation of new courses';
 $string['general_options'] = 'General Options';