MDL-40127 Enrolments: Abstracted self_enrolment code so as to be used by webservices