Schedule database update

Schedule database update

โดย Ulrik Sandgren -
Number of replies: 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?


การประเมินโดยเฉลี่ย: -
In reply to Ulrik Sandgren

Re: Schedule database update

โดย Dan Marsden -
รูปภาพของCore developers รูปภาพของParticularly helpful Moodlers รูปภาพของPeer reviewers รูปภาพของPlugin developers รูปภาพของPlugins guardians รูปภาพของTesters รูปภาพของ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)

การประเมินโดยเฉลี่ย: -