Coder Social home page Coder Social logo

silverstripe-softdelete's Introduction

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 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

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

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

SoftDeletable::$disable = true

Or at query level

$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:

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 - [email protected]

silverstripe-softdelete's People

Contributors

lekoala avatar scottburfieldmills avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

silverstripe-softdelete's Issues

Why do you check if query filters on ID and then stop the query?

We had a problem that we were querying by ID and it would find the deleted items. It would make sense to me that default it shouldn't find anything that is soft deleted. And if you do, you can use SoftDeletable.filter to make sure you can find it. It breaks our code now and we have to do extra checks to make sure it doesn't get a deleted object.

Override delete() instead of adding softDelete()

It would be better, to override the actual delete() method, instead of having to rely on replacing all occurences of delete() with softDelete();

forceDelete is already in place to handle the hard deletions.

No change....

There is no change on my dataobject after implement this addon...

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.