Jump to:

3461 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » Implementing a logical/soft delete in CMS. Possible on SS?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 141 Views
  • capsula4
    Community Member
    4 Posts

    Implementing a logical/soft delete in CMS. Possible on SS? Link to this post

    Hi, I have a DB table and for specific reasons I don't want users to delete records there, instead just "flag" them as deleted and hide those records to the admins.

    I tried putting some logic on the "onBeforeDelete" and I would like to simply return false for not performing the delete, the only way I found it possible is by calling "exit()" which breaks the flow and makes the user get an empty page.

    I want to perform some logic "onBeforeWrite", saying that if the username already exists, instead of creating a new one, it should unflag the 'deleted' one but it doesnt seem possible.

    Any ideas on how to achieve this?

    public function onBeforeDelete() {
    $this->Status = 'D';
    exit(); //breaks the flow!!

    public function onBeforeWrite() {
    $one = CustomUser::get_one('CustomUser','"IDUserLogical" = '.$this->IDUserLogical);
    $this->ID = $one->ID;
    $this->Status = 'A';
    } //this if breaks the whole code!

    //this works fine!
    public function getList() {
    $list = parent::getList();
    return $list->where('"Status" = \'A\'');

Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.