Prune records from configured DataObject classes
Removes records from the database attached to a Silverstripe project, using a queued job with configurable options.
It can be applied to any
SilverStripe\ORM\DataObject record and is useful for records in tables that can continue to grow, like form submissions.
composer require nswdpc/silverstripe-pruner
nswdpc/silverstripe-pruner-userforms module for silverstripe/userforms support.
Configure a project .yml file like so:
--- Name: prunerconfiglocal After: - '#nswdpc-pruner' --- NSWDPC\Pruner\Pruner: # sample target_models target_models: # remove/backup submitted forms from the userforms module - 'SilverStripe\UserForms\Model\Submission\SubmittedForm' # a namespaced DataObject - 'Some\Namespaced\DataObject'
When adding a
SilverStripe\ORM\DataObject to the list of
target_models, these DataObjects must:
- implement the interface
- have an extension that implements that Interface
The module will ignore models passed to it that do not implement this interface.
PrunerInterface for documentation.
PruneJob exists to remove the relevant records from the target models.
You can pass in the following constructor arguments:
$days_ago- the minimum number of days in the past records should be truncated. Older records are removed first. Default = 30
$limit- the maximum number of records to remove at one time. Default = 50 (in the case of SubmittedForm records this is a limit per parent class)
$targets- a comma separated model of DataObject classnames (namespace). If left empty the configured names will be used, if any. This allow you to schedule removal of a certain class of records at a certain time.
$report_only- 0|1 - pass in 1 to only report on what would be removed.
While the most common list to return would be records older than the
days_ago age parameter, you are in control of how records are filtered as returned from
You can add extra filters to the query or modify/ignore the age parameter entirely. For instance, you could remove records older than a certain date and not authored by members in a specific domain.
In addition to the usual onBeforeDelete/onAfterDelete Silverstripe methods, the module calls onBeforePrune and onAfterPrune before/after record deletion, respectively.
The order of operation for each record removal is:
- delete action:
You must implement these methods, even if you are not carrying out any actions pre/post record pruning.
A task exists to provide quick report showing what would be removed based on the arguments provided:
Report for the targeted models, older than 15 days, limit 50 records removed per model
./vendor/bin/sake dev/tasks/ReportOnlyPrunerTask age=15 limit=50 targets=SilverStripe\\UserForms\\Model\\Submission\\SubmittedForm
Multiple targets can be separated by a comma. If not targets are provided, the configured value of
NSWDPC\Pruner\Pruner.target_models is used.
If you have found a security issue with this module, please email digital[@]dpc.nsw.gov.au in the first instance, detailing your findings.
We welcome bug reports, pull requests and feature requests on the Github Issue tracker for this project.
Please review the code of conduct prior to opening a new issue.
If you would like to make contributions to the module please ensure you raise a pull request and discuss with the module maintainers.
Please review the code of conduct prior to completing a pull request.