Schedule database update

Schedule database update

deur Ulrik Sandgren -
Getal antwoorde: 2

Whats the best way to get a scheduled job (once a day) that makes a update in the database? My first idea was to use "Ad-hoc database queries" but it was not possible because db writing is not allowed.

The use case is that we would add a role (insert a new post in mdl_role_assignments) for users that fullfils some preconditions and have this done every night.

Do I need to use the Task API and create a new class for this?


Gemiddeld van beoordelings: -
In antwoord op Ulrik Sandgren

Re: Schedule database update

deur Tim Hunt -
Prentjie van Core developers Prentjie van Documentation writers Prentjie van Particularly helpful Moodlers Prentjie van Peer reviewers Prentjie van Plugin developers
Using the Task API would be the normal way to do this sort of thing.
Gemiddeld van beoordelings: -
In antwoord op Ulrik Sandgren

Re: Schedule database update

deur Dan Marsden -
Prentjie van Core developers Prentjie van Particularly helpful Moodlers Prentjie van Peer reviewers Prentjie van Plugin developers Prentjie van Plugins guardians Prentjie van Testers Prentjie van Translators

you shouldn't insert directly to the mdl_role_assignments and should really be using the standard API functions to do this. Ideally you should be calling "role_assign" from accesslib.php or the webservice core_role_assign_roles to do this.

If the pre-conditions involve moodle events, eg "course completion" etc - you might even be able to use the tool_trigger plugin to listen to course_completion events, and then based on the data you receive you could make a webservice call to the core_role_assign_roles function. It might take a bit to understand how the tool_trigger plugin works and if this will suit your requirements..

alternatively you could just create a plugin that implements the Moodle task api, and triggers this for you (like Tim says)

Gemiddeld van beoordelings: -