Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

Data Model Questions /

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

Implementing a logical/soft delete in CMS. Possible on SS?


Go to End


1273 Views

Avatar
capsula4

Community Member, 4 Posts

4 July 2014 at 3:42pm

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';
      $this->write();
      exit(); //breaks the flow!!
   }
   
   
   public function onBeforeWrite() {
      $one = CustomUser::get_one('CustomUser','"IDUserLogical" = '.$this->IDUserLogical);
      if($one){
         $this->ID = $one->ID;
         $this->Status = 'A';
      } //this if breaks the whole code!
      parent::onBeforeWrite();
   }

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