From 3d49005f20316c023b970d32d935968ff001536b Mon Sep 17 00:00:00 2001 From: thepurpleblob Date: Wed, 21 Nov 2007 11:06:46 +0000 Subject: [PATCH] MDL-12296: Added option to prevent database enrolment plugin unenrolling users. Merged from STABLE_19 --- enrol/database/config.html | 14 ++++++++++++++ enrol/database/enrol.php | 27 ++++++++++++++++++++++----- lang/en_utf8/enrol_database.php | 1 + 3 files changed, 37 insertions(+), 5 deletions(-) diff --git a/enrol/database/config.html b/enrol/database/config.html index df1ed6d4b0..6d2bea35e9 100644 --- a/enrol/database/config.html +++ b/enrol/database/config.html @@ -234,4 +234,18 @@ + + enrol_db_disableunenrol: + + enrol_db_disableunenrol, ""); + if (isset($err['enrol_db_disableunenrol'])) { + formerr($err['enrol_db_disableunenrol']); + } + ?> + + + + + diff --git a/enrol/database/enrol.php b/enrol/database/enrol.php index dbd07282f7..761e5b285b 100644 --- a/enrol/database/enrol.php +++ b/enrol/database/enrol.php @@ -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 diff --git a/lang/en_utf8/enrol_database.php b/lang/en_utf8/enrol_database.php index 1d6948af50..e0db63b4b7 100644 --- a/lang/en_utf8/enrol_database.php +++ b/lang/en_utf8/enrol_database.php @@ -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'; -- 2.39.5