Need help with deleting user feature

Hi guys, i have a button that a user presses to delete their account. i currently just have it delete the user, but this is a problem because after they delete themselves, their data still lives on causing problems (e.g. i have a feature that regularly does a database wide tally to update an “average user score” and it will still see this “ghost data”. There are various data types entries for a user that i need to delete. Then there’s the various scheduled backend workflow that need to be cancelled.

I could just add a delete this and this and that action each of the things i want deleted/cancel one-by-one. But there’s two problems with that: (1) it doesn’t take into account things (data types and schedules) that i might add later and so i might forget to also add these the cancel/delete workflow. I basically need to figure out how to build a “delete all this guys stuff and cancel all his workflows” action. That way i don’t have to worry about missing anything.

Any ideas?

Should i just delete the user then in the next action(s) do something that searches and destroys scheduled things with an empty user and any data entries with “deleted user” (across all data types). And if this is what i should do, how would it do it?

Any ideas?

Delete all of the User-dependent things first and then delete the User object.

If your database structure is hopelessly complex (it’s not) and you can’t possibly manage this (you can), I have a private plugin that can crawl arbitrarily complex objects to some specified depth and return the UIDs of everything found, but it’s $2000 (pay me anyway).

1 Like

Ok but is there a way to delete all things that belong to a user rather than building an action step for each of the things? (so i can future proof deleting things i might add in the future)

When i delete a user they leave behind their scheduled workflows (with a blank user name). Is it bad practice to just leave these here?

No, there is not a way to do that.

It depends on how you define bad practice, but I certainly wouldn’t leave them there. When you schedule workflows for a user, store the ids of the scheduled workflows somewhere, and when a user is deleted, cancel the scheduled workflows before deleting the user. Or don’t, but again, I wouldn’t leave them there when a user is deleted.

Ok thanks. I’ll keep having a think about this.