Jump to content

Mass delete clients


Recommended Posts

Hi I've been looking for a way to mass delete clients and I came across two addon modules in the marketplace. Unfortunately neither of those modules appear to be available.

I could do this via a database query but I'm not sure exactly what needs to be removed to do it cleanly.

Essentially I want to delete all clients and anything associated with them - i.e their products, domains, invoices, tickets etc.

I don't want to scrap the entire database - i want to keep the configuration, addon modules, products, payment gateways etc. - but clear out all the clients.

Any help greatly appreciated.

Link to comment
Share on other sites

If you want to delete all clients, it can be done using the API or using  models. This should do the trick: https://pastebin.com/cfECu0Lm

Upload the file as something.php in the root of your WHMCS (or somewhere else, just update the path the 'init.php') and run the file.

It will delete all clients. It will not terminate any active services.

The only thing it won't delete is user invites (stored in tbluser_invites).

Link to comment
Share on other sites

Ok thank you that looks very straightforward.

I think with there being so many clients it might overload the server. I wonder if there is a way to do it in stages?

Is there a similar call to remove all services?

 

Edited by Chris74
Link to comment
Share on other sites

I think another way to do it would be to set all domains and products to inactive - then use the automation task to delete inactive users.

Is there a way to set all clients, products and domains to inactive / cancelled? maybe an SQL query?

Link to comment
Share on other sites

Yes, you can use the ModuleTerminate API command: https://developers.whmcs.com/api-reference/moduleterminate/

When doing that, you should grab the value of $results['result'] to make sure that the service was terminated correctly.

If you basically just want to nuke everything in your WHMCS related to clients, transactions, services, tickets and what not, you can empty the following tables:

  • tblaccounts
  • tblactivitylog
  • tblaffiliates
  • tblaffiliatesaccounts
  • tblaffiliateshistory
  • tblaffiliatespending
  • tblaffiliateswithdrawals
  • tblaffiliates_hits
  • tblaffiliates_referrers
  • tblapplinks
  • tblapplinks_links
  • tblapplinks_log
  • tblbankaccts
  • tblbillableitems
  • tblcancelrequests
  • tblcarts
  • tblclients
  • tblclientsfiles
  • tblcontacts
  • tblcredit
  • tblcreditcards
  • tblcustomfieldsvalues
  • tbldomainreminders
  • tbldomains
  • tbldomainsadditionalfields
  • tbldomains_extra
  • tblemails
  • tblfraud
  • tblgatewaylog
  • tblhosting
  • tblhostingaddons
  • tblhostingconfigoptions
  • tblinvoicedata
  • tblinvoiceitems
  • tblinvoices
  • tblmarketing_consent
  • tblmetric_usage
  • tblmodulelog
  • tblmodulequeue
  • tblnotes
  • tblorders
  • tblpaymethods
  • tblquoteitems
  • tblquotes
  • tblrsakeypairs
  • tblserver_tenants
  • tblsessions
  • tblsslorders
  • tblsslstatus
  • tbltenant_stats
  • tblticketbreaklines
  • tblticketfeedback
  • tblticketlog
  • tblticketmaillog
  • tblticketnotes
  • tblticketpendingimports
  • tblticketreplies
  • tbltickets
  • tblticket_watchers
  • tbltransaction_history
  • tblupgrades
  • tblusage_items
  • tblusers
  • tblusers_clients
  • tbluser_invites
  • tbluser_validation

Some of the tables might already be empty and some of them you might still want to keep the data from - but that's up to you 😉

Edited by DennisHermannsen
Link to comment
Share on other sites

Can I maybe just do this...

UPDATE tblhosting SET tblhosting.domainstatus = 'Cancelled'

UPDATE tbldomains SET tbldomains.status = 'Cancelled'

UPDATE tblinvoices SET tblinvoices.status = 'Cancelled'

UPDATE tblclients SET tblclients.status = 'Inactive'

Set the data retention automation in WHMCS to 1 month

Set the date on the server to 1 month in the future

Run the cron job with do --DataRetentionPruning

Set the server date back again.

 

Link to comment
Share on other sites

You could, the only problem is that WHMCS' Data Retention isn't perfect. Their documentation doesn't even say that it's GDPR compliant - it just says that it can "help with GDPR compliance". It does not delete all user data.

A few examples are tickets that aren't assigned to a user and user invites.

I would probably just use the script I provided above and then go through the database afterwards, sorting the tables by amount of rows. Go through the tables that has at least one row and see if it's client related - if it is, empty the table.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use & Guidelines and understand your posts will initially be pre-moderated