Skip to content

Commit

Permalink
MDL-25623 fix incorrect use of DISTINCT on text fields
Browse files Browse the repository at this point in the history
  • Loading branch information
skodak committed Dec 9, 2010
1 parent a290625 commit 424d60d
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions enrol/meta/locallib.php
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,21 @@ public function user_unenrolled($ue) {
//note: do not test if plugin enabled, we want to keep removing previously linked courses

// look for unenrolment candidates - it may be possible that user has multiple enrolments...
$sql = "SELECT DISTINCT e.*
$sql = "SELECT e.*
FROM {enrol} e
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";
$params = array('courseid'=>$ue->courseid, 'userid'=>$ue->userid);

if (!$enrols = $DB->get_records_sql($sql, $params)) {
return true;
}
$rs = $DB->get_recordset_sql($sql, $params);

$plugin = enrol_get_plugin('meta');
foreach ($enrols as $enrol) {
foreach ($rs as $enrol) {
$plugin->unenrol_user($enrol, $ue->userid);
}
$rs->close();

return true;
}
Expand Down

0 comments on commit 424d60d

Please sign in to comment.