Chris74 Posted April 1, 2023 Share Posted April 1, 2023 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. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted April 1, 2023 Share Posted April 1, 2023 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). 0 Quote Link to comment Share on other sites More sharing options...
Chris74 Posted April 2, 2023 Author Share Posted April 2, 2023 (edited) 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 April 2, 2023 by Chris74 0 Quote Link to comment Share on other sites More sharing options...
Chris74 Posted April 2, 2023 Author Share Posted April 2, 2023 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? 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted April 2, 2023 Share Posted April 2, 2023 (edited) 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 April 2, 2023 by DennisHermannsen 0 Quote Link to comment Share on other sites More sharing options...
Chris74 Posted April 2, 2023 Author Share Posted April 2, 2023 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. 0 Quote Link to comment Share on other sites More sharing options...
DennisHermannsen Posted April 2, 2023 Share Posted April 2, 2023 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. 1 Quote Link to comment Share on other sites More sharing options...
Chris74 Posted April 2, 2023 Author Share Posted April 2, 2023 Ok thanks. Appreciate your help. 0 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.