Question

I need to be able to delete messages and to restore them until the page is not reloaded. So I have a field 'is_deleted' in my 'messages' table. What I want is to delete these 'deleted' records after it. What would be the best solution for this?

Was it helpful?

Solution

It depends on your needs, a "purge" button may be what you want or a lot of times people will use a cron job and set the is_deleted to be a Nullable DATETIME field, if after x days, it still shows as being deleted, it is automatically deleted from the database.

So if the automatic way appeals to you and you are on linux look at Cron jobs or if on windows Task Scheduler. If you would like an example of the cron, I need to know how frequently you would want the records purged from the system and I will provide you with an example of one.

For example, to run the delete script every 5 minutes:

*/5 * * * * /usr/bin/php -f /path/to/script/purgeDeleted.php > /dev/null

You will still have to write the purgeDeleted.php script, but that is the setup for running a php cli script via a cron job in Linux.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top