Merge branch 'wip-mdl-41413-int' of git://github.com/rajeshtaneja/moodle
This commit is contained in:
@@ -99,4 +99,112 @@ class enrol_meta_observer extends enrol_meta_handler {
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered via role_assigned event.
|
||||
*
|
||||
* @param \core\event\role_assigned $event
|
||||
* @return bool true on success.
|
||||
*/
|
||||
public static function role_assigned(\core\event\role_assigned $event) {
|
||||
if (!enrol_is_enabled('meta')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prevent circular dependencies - we can not sync meta roles recursively.
|
||||
if ($event->other['component'] === 'enrol_meta') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Only course level roles are interesting.
|
||||
if (!$parentcontext = context::instance_by_id($event->contextid, IGNORE_MISSING)) {
|
||||
return true;
|
||||
}
|
||||
if ($parentcontext->contextlevel != CONTEXT_COURSE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
self::sync_course_instances($parentcontext->instanceid, $event->relateduserid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered via role_unassigned event.
|
||||
*
|
||||
* @param \core\event\role_unassigned $event
|
||||
* @return bool true on success
|
||||
*/
|
||||
public static function role_unassigned(\core\event\role_unassigned $event) {
|
||||
if (!enrol_is_enabled('meta')) {
|
||||
// All roles are removed via cron automatically.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Prevent circular dependencies - we can not sync meta roles recursively.
|
||||
if ($event->other['component'] === 'enrol_meta') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// Only course level roles are interesting.
|
||||
if (!$parentcontext = context::instance_by_id($event->contextid, IGNORE_MISSING)) {
|
||||
return true;
|
||||
}
|
||||
if ($parentcontext->contextlevel != CONTEXT_COURSE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
self::sync_course_instances($parentcontext->instanceid, $event->relateduserid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered via course_deleted event.
|
||||
*
|
||||
* @param \core\event\course_deleted $event
|
||||
* @return bool true on success
|
||||
*/
|
||||
public static function course_deleted(\core\event\course_deleted $event) {
|
||||
global $DB;
|
||||
|
||||
if (!enrol_is_enabled('meta')) {
|
||||
// This is slow, let enrol_meta_sync() deal with disabled plugin.
|
||||
return true;
|
||||
}
|
||||
|
||||
// Does anything want to sync with this parent?
|
||||
if (!$enrols = $DB->get_records('enrol', array('customint1' => $event->objectid, 'enrol' => 'meta'),
|
||||
'courseid ASC, id ASC')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$plugin = enrol_get_plugin('meta');
|
||||
$unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
|
||||
|
||||
if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
|
||||
// Simple, just delete this instance which purges all enrolments,
|
||||
// admins were warned that this is risky setting!
|
||||
foreach ($enrols as $enrol) {
|
||||
$plugin->delete_instance($enrol);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($enrols as $enrol) {
|
||||
$enrol->customint = 0;
|
||||
$DB->update_record('enrol', $enrol);
|
||||
|
||||
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
|
||||
// This makes all enrolments suspended very quickly.
|
||||
$plugin->update_status($enrol, ENROL_INSTANCE_DISABLED);
|
||||
}
|
||||
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
|
||||
$context = context_course::instance($enrol->courseid);
|
||||
role_unassign_all(array('contextid'=>$context->id, 'component'=>'enrol_meta', 'itemid'=>$enrol->id));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
+12
-24
@@ -25,30 +25,6 @@
|
||||
|
||||
defined('MOODLE_INTERNAL') || die();
|
||||
|
||||
/* List of handlers */
|
||||
$handlers = array (
|
||||
'role_assigned' => array (
|
||||
'handlerfile' => '/enrol/meta/locallib.php',
|
||||
'handlerfunction' => array('enrol_meta_handler', 'role_assigned'),
|
||||
'schedule' => 'instant',
|
||||
'internal' => 1,
|
||||
),
|
||||
|
||||
'role_unassigned' => array (
|
||||
'handlerfile' => '/enrol/meta/locallib.php',
|
||||
'handlerfunction' => array('enrol_meta_handler', 'role_unassigned'),
|
||||
'schedule' => 'instant',
|
||||
'internal' => 1,
|
||||
),
|
||||
|
||||
'course_deleted' => array (
|
||||
'handlerfile' => '/enrol/meta/locallib.php',
|
||||
'handlerfunction' => array('enrol_meta_handler', 'course_deleted'),
|
||||
'schedule' => 'instant',
|
||||
'internal' => 1,
|
||||
),
|
||||
);
|
||||
|
||||
// List of observers.
|
||||
$observers = array(
|
||||
|
||||
@@ -64,4 +40,16 @@ $observers = array(
|
||||
'eventname' => '\core\event\user_enrolment_updated',
|
||||
'callback' => 'enrol_meta_observer::user_enrolment_updated',
|
||||
),
|
||||
array(
|
||||
'eventname' => '\core\event\role_assigned',
|
||||
'callback' => 'enrol_meta_observer::role_assigned',
|
||||
),
|
||||
array(
|
||||
'eventname' => '\core\event\role_unassigned',
|
||||
'callback' => 'enrol_meta_observer::role_unassigned',
|
||||
),
|
||||
array(
|
||||
'eventname' => '\core\event\course_deleted',
|
||||
'callback' => 'enrol_meta_observer::course_deleted',
|
||||
),
|
||||
);
|
||||
|
||||
@@ -233,116 +233,8 @@ class enrol_meta_handler {
|
||||
debugging('Unknown unenrol action '.$unenrolaction);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered via role assigned event.
|
||||
* @static
|
||||
* @param stdClass $ra
|
||||
* @return bool success
|
||||
*/
|
||||
public static function role_assigned($ra) {
|
||||
if (!enrol_is_enabled('meta')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
// prevent circular dependencies - we can not sync meta roles recursively
|
||||
if ($ra->component === 'enrol_meta') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// only course level roles are interesting
|
||||
if (!$parentcontext = context::instance_by_id($ra->contextid, IGNORE_MISSING)) {
|
||||
return true;
|
||||
}
|
||||
if ($parentcontext->contextlevel != CONTEXT_COURSE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
self::sync_course_instances($parentcontext->instanceid, $ra->userid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered via role unassigned event.
|
||||
* @static
|
||||
* @param stdClass $ra
|
||||
* @return bool success
|
||||
*/
|
||||
public static function role_unassigned($ra) {
|
||||
if (!enrol_is_enabled('meta')) {
|
||||
// all roles are removed via cron automatically
|
||||
return true;
|
||||
}
|
||||
|
||||
// prevent circular dependencies - we can not sync meta roles recursively
|
||||
if ($ra->component === 'enrol_meta') {
|
||||
return true;
|
||||
}
|
||||
|
||||
// only course level roles are interesting
|
||||
if (!$parentcontext = context::instance_by_id($ra->contextid, IGNORE_MISSING)) {
|
||||
return true;
|
||||
}
|
||||
if ($parentcontext->contextlevel != CONTEXT_COURSE) {
|
||||
return true;
|
||||
}
|
||||
|
||||
self::sync_course_instances($parentcontext->instanceid, $ra->userid);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Triggered via course_deleted event.
|
||||
* @static
|
||||
* @param stdClass $course
|
||||
* @return bool success
|
||||
*/
|
||||
public static function course_deleted($course) {
|
||||
global $DB;
|
||||
|
||||
if (!enrol_is_enabled('meta')) {
|
||||
// This is slow, let enrol_meta_sync() deal with disabled plugin.
|
||||
return true;
|
||||
}
|
||||
|
||||
// does anything want to sync with this parent?
|
||||
if (!$enrols = $DB->get_records('enrol', array('customint1'=>$course->id, 'enrol'=>'meta'), 'courseid ASC, id ASC')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$plugin = enrol_get_plugin('meta');
|
||||
$unenrolaction = $plugin->get_config('unenrolaction', ENROL_EXT_REMOVED_SUSPENDNOROLES);
|
||||
|
||||
if ($unenrolaction == ENROL_EXT_REMOVED_UNENROL) {
|
||||
// Simple, just delete this instance which purges all enrolments,
|
||||
// admins were warned that this is risky setting!
|
||||
foreach ($enrols as $enrol) {
|
||||
$plugin->delete_instance($enrol);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
foreach ($enrols as $enrol) {
|
||||
$enrol->customint = 0;
|
||||
$DB->update_record('enrol', $enrol);
|
||||
|
||||
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPEND or $unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
|
||||
// This makes all enrolments suspended very quickly.
|
||||
$plugin->update_status($enrol, ENROL_INSTANCE_DISABLED);
|
||||
}
|
||||
if ($unenrolaction == ENROL_EXT_REMOVED_SUSPENDNOROLES) {
|
||||
$context = context_course::instance($enrol->courseid);
|
||||
role_unassign_all(array('contextid'=>$context->id, 'component'=>'enrol_meta', 'itemid'=>$enrol->id));
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Sync all meta course links.
|
||||
*
|
||||
|
||||
Reference in New Issue
Block a user