From 341217658e5ccaeb4d39a96f341df81d1fefb3af Mon Sep 17 00:00:00 2001 From: Petr Skoda Date: Thu, 8 Jul 2010 10:57:23 +0000 Subject: [PATCH] MDL-23151 new ext sync option and minor refactoring --- enrol/database/lang/en/enrol_database.php | 5 ----- enrol/database/lib.php | 9 ++++++--- enrol/database/settings.php | 7 +++++-- enrol/database/version.php | 2 +- lang/en/enrol.php | 8 +++++++- lib/enrollib.php | 19 +++++++++++++++++++ 6 files changed, 38 insertions(+), 12 deletions(-) diff --git a/enrol/database/lang/en/enrol_database.php b/enrol/database/lang/en/enrol_database.php index 2f65c805874..1b146322982 100644 --- a/enrol/database/lang/en/enrol_database.php +++ b/enrol/database/lang/en/enrol_database.php @@ -70,8 +70,3 @@ $string['settingsheadernewcourses'] = 'Creation of new courses'; $string['remoteuserfield_desc'] = 'The name of the field in the remote table that we are using to match entries in the user table.'; $string['templatecourse'] = 'New course template'; $string['templatecourse_desc'] = 'Optional: auto-created courses can copy their settings from a template course. Type here the shortname of the template course.'; -$string['unenrolaction'] = 'External unenrol action'; -$string['unenrolaction_desc'] = 'Select action to carry our when user enrolment disappears from external enrolment table. Please note that some user data and settings are purged from course during course unenrolment.'; -$string['unenrolactiondisable'] = 'Disable course enrolment'; -$string['unenrolactionkeep'] = 'Keep user enrolled'; -$string['unenrolactionunenrol'] = 'Unenrol user from course'; diff --git a/enrol/database/lib.php b/enrol/database/lib.php index 07b4fd49795..7f30eafc566 100644 --- a/enrol/database/lib.php +++ b/enrol/database/lib.php @@ -255,7 +255,7 @@ class enrol_database_plugin extends enrol_plugin { } // deal with enrolments removed from external table - if ($unenrolaction == 0) { + if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) { // unenrol if (!empty($requested_roles)) { // we might get some error or connection problem, better not unenrol everybody @@ -267,10 +267,10 @@ class enrol_database_plugin extends enrol_plugin { } } - } else if ($unenrolaction == 1) { + } else if ($unenrolaction == ENROL_EXT_REMOVED_KEEP) { // keep - only adding enrolments - } else if ($unenrolaction == 2) { + } else if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) { // disable foreach ($current_status as $userid=>$status) { if (isset($requested_roles[$userid])) { @@ -279,6 +279,9 @@ class enrol_database_plugin extends enrol_plugin { if ($status != ENROL_USER_SUSPENDED) { $DB->set_field('user_enrolments', 'status', ENROL_USER_SUSPENDED, array('enrolid'=>$instance->id, 'userid'=>$userid)); } + if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) { + role_unassign_all(array('contextid'=>$context->id, 'userid'=>$userid, 'component'=>'enrol_database', 'itemid'=>$instance->id)); + } } } } diff --git a/enrol/database/settings.php b/enrol/database/settings.php index f776956d9e3..5eeb9e4f01b 100644 --- a/enrol/database/settings.php +++ b/enrol/database/settings.php @@ -86,8 +86,11 @@ if ($ADMIN->fulltree) { $settings->add(new admin_setting_configcheckbox('enrol_database/ignorehiddencourses', get_string('ignorehiddencourses', 'enrol_database'), get_string('ignorehiddencourses_desc', 'enrol_database'), 0)); - $options = array(0=>get_string('unenrolactionunenrol', 'enrol_database'), 1=>get_string('unenrolactionkeep', 'enrol_database'), 2=>get_string('unenrolactiondisable', 'enrol_database')); - $settings->add(new admin_setting_configselect('enrol_database/unenrolaction', get_string('unenrolaction', 'enrol_database'), get_string('unenrolaction_desc', 'enrol_database'), 0, $options)); + $options = array(ENROL_EXT_REMOVED_UNENROL => get_string('extremovedunenrol', 'enrol'), + ENROL_EXT_REMOVED_KEEP => get_string('extremovedkeep', 'enrol'), + ENROL_EXT_REMOVED_SUSPEND => get_string('extremovedsuspend', 'enrol'), + ENROL_EXT_REMOVED_SUSPENDNOROLES => get_string('extremovedsuspendnoroles', 'enrol')); + $settings->add(new admin_setting_configselect('enrol_database/unenrolaction', get_string('extremovedaction', 'enrol'), get_string('extremovedaction_help', 'enrol'), ENROL_EXT_REMOVED_UNENROL, $options)); diff --git a/enrol/database/version.php b/enrol/database/version.php index 1b8e1c60a5f..23708a69b6e 100644 --- a/enrol/database/version.php +++ b/enrol/database/version.php @@ -23,5 +23,5 @@ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later */ -$plugin->version = 2010061500; +$plugin->version = 2010070800; //TODO: should we add cron sync? \ No newline at end of file diff --git a/lang/en/enrol.php b/lang/en/enrol.php index 6bdc427f961..a37ebc6baa7 100644 --- a/lang/en/enrol.php +++ b/lang/en/enrol.php @@ -72,5 +72,11 @@ $string['unenrolme'] = 'Unenrol me from {$a}'; $string['unenrolroleusers'] = 'Unenrol users'; $string['uninstallconfirm'] = 'You are about to completely delete the enrol plugin \'{$a}\'. This will completely delete everything in the database associated with this enrolment type. Are you SURE you want to continue?'; $string['uninstalldeletefiles'] = 'All data associated with the enrol plugin \'{$a->plugin}\' has been deleted from the database. To complete the deletion (and prevent the plugin re-installing itself), you should now delete this directory from your server: {$a->directory}'; -$string['unlimitedduration'] = 'Unlmited'; +$string['unlimitedduration'] = 'Unlimited'; $string['usersearch'] = 'Search '; +$string['extremovedaction'] = 'External unenrol action'; +$string['extremovedaction_help'] = 'Select action to carry our when user enrolment disappears from external enrolment source. Please note that some user data and settings are purged from course during course unenrolment.'; +$string['extremovedsuspend'] = 'Disable course enrolment'; +$string['extremovedsuspendnoroles'] = 'Disable course enrolment and remove roles'; +$string['extremovedkeep'] = 'Keep user enrolled'; +$string['extremovedunenrol'] = 'Unenrol user from course'; diff --git a/lib/enrollib.php b/lib/enrollib.php index 44aae7ec34a..6e4727fb920 100644 --- a/lib/enrollib.php +++ b/lib/enrollib.php @@ -40,6 +40,25 @@ define('ENROL_USER_SUSPENDED', 1); /** Enrol info is cached for this number of seconds in require_login() */ define('ENROL_REQUIRE_LOGIN_CACHE_PERIOD', 1800); +/** When user disappears from external source, the enrolment is completely removed */ +define('ENROL_EXT_REMOVED_UNENROL', 0); + +/** When user disappears from external source, the enrolment is kept as is - one way sync */ +define('ENROL_EXT_REMOVED_KEEP', 1); + +/** + * When user disappears from external source, user enrolment is suspended, roles are kept as is. + * In some cases user needs a role with some capability to be visible in UI - suc has in gradebook, + * assignments, etc. + */ +define('ENROL_EXT_REMOVED_SUSPEND', 2); + +/** + * When user disappears from external source, the enrolment is suspended and roles assigned + * by enrol instance are removed. Please note that user may "disappear" from gradebook and other areas. + * */ +define('ENROL_EXT_REMOVED_SUSPENDNOROLES', 3); + /** * Returns instances of enrol plugins * @param bool $enable return enabled only