Mnet remote enroll problem

Mnet remote enroll problem

by Pedro Miguel Monteiro Galvão -
Number of replies: 3

Hi,

I tried to configure MNet and get remote enrollments work, but when i enroll an user in two courses of the same host(peer) it deletes the record of the previous course enrolled in that host.

Delete record is on mdl_mnetservice_enrol_enrolments.

I made an slight debug on the php files and was able to get one line (signed with an arrow by me).

The file is /mnet/service/enrol/locallib.php, function req_course_enrolments.

// prune stale enrolment records
if (empty($list)) {
$DB->delete_records('mnetservice_enrol_enrolments',    array('hostid'=>$mnethostid));
} else {
list($isql, $params) = $DB->get_in_or_equal(array_keys($list), SQL_PARAMS_NAMED, 'param0000', false);
$params['hostid'] = $mnethostid;
$select = "hostid = :hostid AND id $isql";
-> $DB->delete_records_select('mnetservice_enrol_enrolments',    $select, $params);

}

I get this by debug the /mnet/service/enrol/course.php file.

If i comment this line, everything works fine, but i wish to know detailed information about this line, to know the problems that i can get if i comment it.

If someone have more information about it, TIA.

Best regards,

Pedro Galvão

Average of ratings: Useful (1)
In reply to Pedro Miguel Monteiro Galvão

Re: Mnet remote enroll problem

by David Mudrák -
Picture of Core developers Picture of Documentation writers Picture of Moodle HQ Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers Picture of Plugins guardians Picture of Testers Picture of Translators

Ay caramba! Good catch. There is a nasty bug in SQL that clears stale enrolment records. I just created MDL-25980 to track this. A patch to fix this follows. I am going to submit it for the next weekly build. Thanks for reporting this!

diff --git a/mnet/service/enrol/locallib.php b/mnet/service/enrol/locallib.php
index f5adbfc..b0c260a 100644
--- a/mnet/service/enrol/locallib.php
+++ b/mnet/service/enrol/locallib.php
@@ -334,11 +334,12 @@ class mnetservice_enrol {
 
             // prune stale enrolment records
             if (empty($list)) {
-                $DB->delete_records('mnetservice_enrol_enrolments', array('hostid'=>$mnethostid));
+                $DB->delete_records('mnetservice_enrol_enrolments', array('hostid'=>$mnethostid, 'remotecourseid'=>$remotecourseid));
             } else {
                 list($isql, $params) = $DB->get_in_or_equal(array_keys($list), SQL_PARAMS_NAMED, 'param0000', false);
                 $params['hostid'] = $mnethostid;
-                $select = "hostid = :hostid AND id $isql";
+                $params['remotecourseid'] = $remotecourseid;
+                $select = "hostid = :hostid AND remotecourseid = :remotecourseid AND id $isql";
                 $DB->delete_records_select('mnetservice_enrol_enrolments', $select, $params);
             }

In reply to David Mudrák

Re: Mnet remote enroll problem

by Pedro Miguel Monteiro Galvão -
thks for the quick analyse and for solve the problem. Good work ;)
In reply to Pedro Miguel Monteiro Galvão

Re: Mnet remote enroll problem

by Pedro Miguel Monteiro Galvão -

Hi again,

After some tests after the code change now it's having another problem.
When you enroll a user to a course and bet back there to enroll other again the previous enrolled users are unenroled from it making the course with no enrolles. this line on the previous file

//$DB->delete_records('mnetservice_enrol_enrolments',array('hostid'=>$mnethostid));

$DB->delete_records('mnetservice_enrol_enrolments',array('hostid'=>$mnethostid, 'remotecourseid'=>$remotecourseid));

I hope to get nice news,TIA