Notes for developers

Last updated on
7 December 2021

Services

The basis of the Moodle REST module is two services: 'moodle_rest.rest_ws' and 'moodle_rest.rest_functions'. Yes they could actually be one service, but that's the way it ended up. If you look below you'll see the Migration Source plugin uses the rest_ws directly as it defines the rest function parameters and handling in a migration plugin way in the source.

moodle_rest.rest_ws provides the basic connection to the Moodle Web service. It handles formatting the function calls into the URL, and do things like catching exceptions in the returned HTTP 200 JSON response. You could use this service directly but you are more likely to want to use the functions one. The class also has a requestFile to retrieve files from the non-rest file webservice.

moodle_rest.rest_functions provides, normalizes parameters and responses, and documents, Moodle Web service Functions. Here you will find for example how to get all courses filtered by a field which parameters are required, and get a formatted response that has handled any warnings (commonly access issues).

If you would like to provide additional functions for the RestFunctions class please do open a Pull Request. ** TODO ** notes (and a db dump from Moodle) for how to provide Fixtures for testing additional functions (- ask in the issue queue till this is completed).

Events

The 'User Integration' submodule provides events: 'moodle_rest_user.associate' which is used for searching for users in Moodle to find their ID there; and 'moodle_rest_user.push' and 'moodle_rest_user.pull' which are used to manipulate field data as it is being pushed and pulled from Moodle.

moodle_rest_user.associate can be implemented to associate the user by another field. For example if an external ID is shared and stored in Moodle, in addition to searching by email address, as the event subscriber in the User Integration module does you can search on that field and value.

moodle_rest_user.push and pull send a Migrate Row (so source and destination) and the configuration. The default subscriber just copies from one to the other, but should you need to do any other manipulation you can do that with this event.

Migration

Sample yml and explanation can be found in the Moodle Rest Module readme.

Source Plugin

There is a 'Moodle REST migrate' submodule that provides the base for any migrations based on Moodle Rest Web service functions. The 'Moodle Course Integration' submodule uses the core_course_get_courses_by_field migration source plugin implementation.

File Processor

There is a plugin to handle retrieving files from the described url in summaryfiles and overviewfiles, as well as probably others. The file will be retrived from the moodle end point with your credentials. The user will need core_files_get_files permission.

Help improve this page

Page status: No known problems

You can: