Call function outside moodle

Call function outside moodle

by Kritika Sood -
Number of replies: 2
Hi Everyone

In my custom plug in I want to update a database outside moodle when any unenrolments happens. For this I have used the user_enrollment_deleted event in my plug in. So I want to call a function outside moodle when any enrollment happens.
I have just read the web services. But web services are used when we want to call moodle functions from outside the moodle.
But in my case I want the vice versa i.e call some external function from moodle.
How can I achieve this ?
Please help me out.

Average of ratings: -
In reply to Kritika Sood

Re: Call function outside moodle

by Mark Johnson -
Picture of Core developers Picture of Particularly helpful Moodlers Picture of Peer reviewers Picture of Plugin developers

If you can connect to your external database in PHP, your custom plugin could just do that and update the database directly from a function triggered by the user_enrolment_deleted event.

If you can't do that, then you're reliant on the external system implementing some sort of API (e.g. a web service) that you can call from Moodle code. Alternatively, you can log the deletions within Moodle, and have a web service function in your plugin to provide a list of the logged deletions.  You'll then need an external tool that can connect to both Moodle and the external database to call the web service function and make the required database updates.

In reply to Mark Johnson

Re: Call function outside moodle

by Luis Ibhiabor -

Hello Mark,

I was just reading your response and I found out that you were also addressing an issue that I am currently trying to solve. Could you say more on this 'external tool' if possible with some examples, please? I mean what you said below.

"You'll then need an external tool that can connect to both Moodle and the external database to call the web service function and make the required database updates."

Thanks