https://github.com/lekoala/silverstripe-softdelete
Add SoftDelete behaviour to your SilverStripe models
https://github.com/lekoala/silverstripe-softdelete
silverstripe softdelete
Last synced: about 1 year ago
JSON representation
Add SoftDelete behaviour to your SilverStripe models
- Host: GitHub
- URL: https://github.com/lekoala/silverstripe-softdelete
- Owner: lekoala
- License: mit
- Created: 2016-07-13T09:32:31.000Z (almost 10 years ago)
- Default Branch: master
- Last Pushed: 2024-05-14T23:12:13.000Z (about 2 years ago)
- Last Synced: 2025-03-29T12:11:23.859Z (about 1 year ago)
- Topics: silverstripe, softdelete
- Language: PHP
- Homepage:
- Size: 69.3 KB
- Stars: 12
- Watchers: 3
- Forks: 7
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# SilverStripe Soft Delete Module
Add a soft delete behaviour to your dataobjects. Objects are simply marked as deleted and kept in the database.
Soft delete will follow the same permissions patterns as delete.
ModelAdmin and SecurityAdmin are extended to add a new GridField action that replace the default delete action
This module depends on [lekoala/silverstripe-cms-actions](https://github.com/lekoala/silverstripe-cms-actions) for displaying delete buttons
# How to use
Simply replace your calls from delete to softDelete.
New extensions hooks are provided to avoid side effects (onBeforeSoftDelete, onAfterSoftDelete).
These are ideals if you have child records that need to be soft deleted with their parent.
# Config options
```yml
SilverStripe\Admin\ModelAdmin:
softdelete_from_list: true
softdelete_from_list_exclude: []
extensions:
- SoftDeleteModelAdmin
SilverStripe\Admin\SecurityAdmin:
softdelete_from_list: true
softdelete_from_list_exclude: []
extensions:
- SoftDeleteSecurityAdmin
```
You can configure:
- softdelete_from_list: show delete button on a line. Enabled by default.
- softdelete_from_list_exclude: hide the delete button for these classes even if enabled globally
# Prevent accidental deletion
By default, the module will prevent any delete from happening. To allow deletion, you must set
```php
SoftDeletable:$prevent_delete = false
```
The only way from the CMS UI to delete a record is to go to a soft deleted record
and click "Really delete" which will call "forceDelete" on the record.
# Disable filtering
You can disable filtering globally, using
```php
SoftDeletable::$disable = true
```
Or at query level
```php
$dataQuery->setQueryParam('SoftDeletable.filter',false)
```
# Filtering on ids
By default, this module will let you return soft deleted records if you
ask them specifically by ID. This is by design to prevent things breaking accidentally.
If you want to make sure you don't display soft deleted records, make
sure to implement a proper canView() method that fits your usage.
An alternative option, is to disable that feature:
```yml
SoftDeletable:
check_filters_on_id: false
```
Keep in mind that `DataObject::get_by_id();` can get cached and it can lead to tricky scenarios.
# Compatibility
Tested with 4.4+
# Maintainer
LeKoala - thomas@lekoala.be