‘llms_unenroll_student’ Unexpected Logic
-
We phased out a membership and transferred users who were in that membership to a different one. It was a large amount of users so it was necessary to do the transfer through a script.
Some users were already in the destination membership, so in my script I simply unenrolled those users from the phased out membership and took no further action. However, there was course overlap between these two memberships and it turns out that the unenroll action unenrolled those users from overlapping courses even though they should have maintained access through their other membership.
To me this was unexpected logic. I’ve already developed the script to toggle the membership off and on to get their access back. Just reporting for awareness. Here’s the core of the script:
$old_membership_id = 123;
$new_membership_id = 456;
// get students that are enrolled in the old membership
$old_membership = new LLMS_Membership($old_membership_id);
$students = $old_membership->get_students('enrolled', 9999);
foreach ($students as $student_id) {
// Unenroll from the old membership
llms_unenroll_student($student_id, $old_membership_id);
if (!llms_is_user_enrolled($student_id, $new_membership_id)) {
// Enroll in the new membership
llms_enroll_student($student_id, $new_membership_id, 'old-membership-migration');
}
}The page I need help with: [log in to see the link]
- You must be logged in to reply to this topic.