It’s really easy to find inspiration when you developing on CakePHP. For the current project I need to create global (for all models) behavior which stores creator and modifier as well as deleter and deleted (for soft-delete).
What are the requirements
1. For every table (or at least the most of them) there are fields 6 fields:
- creator (int) – user who create the the record
- created (datetime) – date when the record was created
- modifier (int) – user who modified the the record
- modified (datetime) – date when the record was modified
- deleter (int) – user who delete the the record
- deleted (datetime) – date when the record was modified
2. Some tables doesn’t have such fields (like aros, acos, settings etc), so it should update tables which has such fields.
I’ve seen Soft Deletable Behavior as well as recently added WhoDidIt behavior, but I don’t like the approach of using _SESSION. I’ve also decided to use datetime field to determine if the record is active (field deleted is NULL) or deleted (if the field is set with date).
So the result was – I’ve write my own behavior who serves this.