Skip to content
Browse files

Merge branch 'w28_MDL-28348_m20_meta' of git://github.com/skodak/mood…

…le into MOODLE_20_STABLE
  • Loading branch information...
2 parents e3f6f30 + 768dd79 commit a3fe5348ab2c07316091d8c64c0e33afccdd55d3 @samhemelryk samhemelryk committed Jul 18, 2011
Showing with 14 additions and 9 deletions.
  1. +14 −9 enrol/meta/locallib.php
View
23 enrol/meta/locallib.php
@@ -1,5 +1,4 @@
<?php
-
// This file is part of Moodle - http://moodle.org/
//
// Moodle is free software: you can redistribute it and/or modify
@@ -45,7 +44,7 @@ public function role_assigned($ra) {
return true;
}
- //only course level roles are interesting
+ // only course level roles are interesting
$parentcontext = get_context_instance_by_id($ra->contextid);
if ($parentcontext->contextlevel != CONTEXT_COURSE) {
return true;
@@ -81,7 +80,7 @@ public function role_assigned($ra) {
public function role_unassigned($ra) {
global $DB;
- //note: do not test if plugin enabled, we want to keep removing previous roles
+ // note: do not test if plugin enabled, we want to keep removing previous roles
// prevent circular dependencies - we can not sync meta roles recursively
if ($ra->component === 'enrol_meta') {
@@ -99,7 +98,7 @@ public function role_unassigned($ra) {
return true;
}
- //note: do not check 'nosyncroleids', somebody might have just enabled it, we want to get rid of nosync roles gradually
+ // note: do not check 'nosyncroleids', somebody might have just enabled it, we want to get rid of nosync roles gradually
foreach ($enrols as $enrol) {
// Is the user enrolled? We want to sync only really enrolled users
@@ -114,8 +113,8 @@ public function role_unassigned($ra) {
continue;
}
- // unassing role, there is no other role assignment in parent course
- role_unassign($ra->roleid, $ra->userid, $ra->contextid, 'enrol_meta', $enrol->id);
+ // unassign role, there is no other role assignment in parent course
+ role_unassign($ra->roleid, $ra->userid, $context->id, 'enrol_meta', $enrol->id);
}
return true;
@@ -128,6 +127,11 @@ public function user_enrolled($ue) {
return true;
}
+ if ($ue->enrol === 'meta') {
+ // prevent circular dependencies - we can not sync meta enrolments recursively
+ return true;
+ }
+
// does anything want to sync with this parent?
if (!$enrols = $DB->get_records('enrol', array('customint1'=>$ue->courseid, 'enrol'=>'meta'), 'id ASC')) {
return true;
@@ -153,7 +157,7 @@ public function user_unenrolled($ue) {
JOIN {user_enrolments} ue ON (ue.enrolid = e.id AND ue.userid = :userid)
JOIN {enrol} pe ON (pe.courseid = e.customint1 AND pe.enrol <> 'meta' AND pe.courseid = :courseid)
LEFT JOIN {user_enrolments} pue ON (pue.enrolid = pe.id AND pue.userid = ue.userid)
- WHERE pue.id IS NULL";
+ WHERE pue.id IS NULL AND e.enrol = 'meta'";
$params = array('courseid'=>$ue->courseid, 'userid'=>$ue->userid);
$rs = $DB->get_recordset_sql($sql, $params);
@@ -170,7 +174,7 @@ public function user_unenrolled($ue) {
public function course_deleted($course) {
global $DB;
- //note: do not test if plugin enabled, we want to keep removing previously linked courses
+ // note: do not test if plugin enabled, we want to keep removing previously linked courses
// does anything want to sync with this parent?
if (!$enrols = $DB->get_records('enrol', array('customint1'=>$course->id, 'enrol'=>'meta'), 'id ASC')) {
@@ -179,7 +183,7 @@ public function course_deleted($course) {
$plugin = enrol_get_plugin('meta');
foreach ($enrols as $enrol) {
- //unenrol all users
+ // unenrol all users
$ues = $DB->get_recordset('user_enrolments', array('enrolid'=>$enrol->id));
foreach ($ues as $ue) {
$plugin->unenrol_user($enrol, $ue->userid);
@@ -191,6 +195,7 @@ public function course_deleted($course) {
}
}
+
/**
* Sync all meta course links.
* @param int $courseid one course, empty mean all

0 comments on commit a3fe534

Please sign in to comment.
Something went wrong with that request. Please try again.