plasticstudio / form-submission-cleanup
Configurable queued-job cleanup for SilverStripe form submission DataObjects.
Package info
github.com/PlasticStudio/form-submission-cleanup
Type:silverstripe-vendormodule
pkg:composer/plasticstudio/form-submission-cleanup
README
A Silverstripe module that provides a single queued job to delete old form submission DataObjects on a daily schedule. Target classes, retention periods, and exclude rules are all defined in YAML config.
Requirements
- silverstripe/framework ^6
- symbiote/silverstripe-queuedjobs ^6.2
- silverstripe/userforms ^7 (optional — only required if targeting
SubmittedFormrecords)
Installation
composer require plasticstudio/form-submission-cleanup
Setup a cron job:
*/1 * * * * /path/to/silverstripe/vendor/bin/sake tasks:ProcessJobQueueTask
Configuration
Copy the relevant blocks into your project's _config/config.yml.
Globals
PlasticStudio\FormSubmissionCleanup\Jobs\FormSubmissionCleanupJob: default_retention_days: 365 # applied to any target without its own retention_days default_date_field: Created # field used to determine record age
Targets
Add one entry per DataObject class to clean up. UserForms is shown as an example; omit it if the module is not installed.
PlasticStudio\FormSubmissionCleanup\Jobs\FormSubmissionCleanupJob: targets: 'SilverStripe\UserForms\Model\Submission\SubmittedForm': retention_days: 365 # optional — overrides default_retention_days date_field: Created # optional — overrides default_date_field exclude: # optional — ORM exclude filter (same syntax as DataList::exclude) IsArchived: true 'App\Model\AnotherSubmission': retention_days: 90
Per-target options
| Key | Type | Description |
|---|---|---|
retention_days |
int | Overrides the global default for this class only |
date_field |
string | DataObject field to measure age against (default Created) |
exclude |
map | ORM filter passed to DataList::exclude() — matching records are kept |
Daily scheduling (default jobs)
Register the job as a QueuedJobs default job so it is automatically re-queued after each run.
SilverStripe\Core\Injector\Injector: Symbiote\QueuedJobs\Services\QueuedJobService: properties: defaultJobs: FormSubmissionCleanup: type: 'PlasticStudio\FormSubmissionCleanup\Jobs\FormSubmissionCleanupJob' filter: JobTitle: 'Form Submission Cleanup' recreate: 1 startDateFormat: 'Y-m-d H:i:s' startTimeString: 'tomorrow 02:00'
Run a dev/build, then queue the first instance manually via the CMS (Admin > Jobs). Subsequent runs are scheduled automatically.
How it works
setup()iterates every configured target class, applies the retention cutoff and any exclude filter, and collects matching record IDs.process()deletes one record per step. Cascade-delete rules on each DataObject handle any related records (e.g.SubmittedFormFieldchildren onSubmittedForm).- After the job completes, the default jobs feature re-queues it for the next scheduled run.