
Data cleaner
- Moodle 1.9–5.1
- 更新 2026-07-07
This local plugin allows you to sanitise data from a production environment for use on testing/dev environments.
DataCleaner Moodle Module
Moodle DataCleaner is an anonymizer of your Moodle data.
Supported versions of Moodle: 2.6 to 3.0 inclusive
How it works
Standard practice when hosting most applications, moodle included, is to have various environments in a ‘pipeline’ leading to production at the end. eg a typical flow might be ‘dev’ > ‘stage’ > ‘prod’ but there could be as many as you want for various reasons, like load testing, penetration testing etc.
To test properly it’s often useful to have real production data in these other environments, but there are downsides:
Usually production can be quite massive, we don’t need or want it all and disk space can be a pain with multiple copies.
There may be sensitive data we don’t want to expose to developers or testers, eg personal data, grades, uploaded assignments etc
Moodle is integrated with 3rd party systems and we don’t want test systems interacting with real systems, eg sending emails, or touching assignments in Turnitin etc, ie we want to remove any API keys and other related config
So we need a way to ‘clean’ the database after a refresh, to reduce the size of the data, to remove anything sensitive, and to ensure it’s not going to touch any other real system. This also needs to be configurable because every moodle instance has different needs and there is no one-size-fits all approach. This could be configured outside moodle in the deployments tools, but over time we have found the most flexible and easiest approach is to have this configuration inside moodle itself, so our clients can directly make these decisions, and not be exposed to any of the complexity of our internal processes around continuous integration and deployment.
Practically this means the cleaning configuration needs to be added into the production system (which initially sounds scary but isn’t), then you refresh the database to another environment where it can be washed. There are multiple levels of safeguards in place to ensure this never gets run in production, which would of course be catastrophic:
It can only be run from the CLI. There is no GUI.
We store the hostname in the cleaning configuration data. If the hostname matches production, DataCleaner will not run. If this data is missing then it will not run.
Typically a refreshed database will be from a nightly snapshot and so the data should be slightly stale. If a non admin user has logged in recently, that’s a sign this moodle is being used, and the DataCleaner will not run.
If cron has run recently, DataCleaner will not run. This should only be run on a data washing instance, cron should not be needed here.
It can only be run if and only if a ‘local_datacleaner_allowexecution = true;’ has been added to config.php
Installation
The simplest method of installing the plugin is to choose “Download ZIP” on the right hand side of the Github page. Once you’ve done this, unzip the DataCleaner code and copy it to the local/datacleaner directory within your Moodle codebase. On most modern Linux systems, this can be accomplished with:
unzip ./mdl-local_datacleaner-master.zip