I am creating forum using PHP / MySQL. A function I am adding to it is to be able to delete Categories and I was wondering the best way to backup the topics & replies inside the category being deleted.
I know of way to do it but I have a feeling it's not the proper way of doing it, so I am looking for other options.
I have tried searching for ways other people do it but I haven't come up with any results.
Thank you.
2 solutions:
create a post_active field defaulting to true. if the row is active, show it, if not consider it deleted
create a duplicate table of deleted stuff. Every time you delete a row, add to the log
if you want, you can implement a version history feature by storing the data into 2 tables - one containing the hierarchy of data [table a], the other the actual information [table b]. each time an entry is modified, create a duplicate row in table B with the new data, and update the hierarchy in table A to link to the new record in table B. If the new record has a field linking to the old record, you can implement an undo feature
While it may require rewriting some queries, the preferred approach is to add e.g. a post_deleted
column and only display posts that where post_deleted=0
on the live site. Instead of actually deleting a post, set post_deleted=1
and review it later. You can then periodically really delete these posts if needed. The end result is a very detailed audit trail.