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.

Data Model Questions /

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


Reply


192 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\'');
}