I think there is some correction needed in the sync implementation. For the external database enrolment right now the synconization happens on user login, instead of that can we execute on course access?
The problem is lets say I have another application for the enrolment, and a user have enrolled for a course so data is saved in the external DB table. Now when user goes to Moodle, it asks for login and everything is perfect.
Now in the same login session user goes back to my another application (for enrolment) and enrols for another course, again the data is getting saved in the external database table. But when user goes to Moodle, Moodle does not sync the enrolment as user is already logged in. Therefore for user its still single course accessible not the new course.
Cant we synchronize the enrolments on course access (course/view.php)? I think that will be better, your thoughts please.