I asked a question earlier on how would I go about deleting a users account and I got a suggestion that I should flag my database that the user has deleted their account but not actually delete the account until after two weeks or so.
So my question is now how would I flag my database and then hav开发者_开发知识库e the account deleted after two weeks if the user has not logged in using PHP & MySQL?
Maybe you could create a SQL Table which contains the users requests.
When a user want to delete his account, you add a request to this table (like wich user_id, date_request etc). And everyday, you check this table to delete (or not) accounts. To check everyday you should use a crontab.
Good Luck !
run a cron job on a 2 week or whatever interval that searches the DB for something like
$timestamp=strtotime($date); // this should be the users last logged in date.
$twoweeks = mktime(0, 0, 0, date("m"), date("d")-14, date("Y"));
// timestamp for 2 weeks ago
if ($timestamp<$twoweeks) { //if they havent logged in for at least 2 weeks..
DELETE * FROM `table` WHERE deleted=1 // query ~like~ that
}
i'm no SQL guru so theres probably a way of doing it directly in the query.
Regarding the flagging for deletion.. In my apps I use a boolean tombstone field in the database. This way you can disable / hide rows if they are tombstoned but not actually delete them:
select [whatever] from table where tombstone = 0
As others have said you can then delete where tombstone = 1
via a cronjob or similar.
It is NOT a good idea to delete all the inactive user account, because you may have refferences in other tables with this ids. Just flag the user as inactive and delete only the ones that has no actions at all.
To delete this accounts, you can create a cron job to run every day and check any inactive users for 2 weeks behind and with no refferences in other tables.
精彩评论