Jump to content

Delete expired domains


ServWise.com

Recommended Posts

I've got about 1500 expired domains accumulated from many years of service which I don't want to manually delete.

 

No way to bulk delete them so I am thinking to write my own SQL script to do it.

 

This is what I have so far, anyone want to sanity check it for me. Yes I know it is a select not a delete statement, I will change to a delete statement once I have it fullproof :)

 

 

It should delete all domain records that have status expired and have been expired for more than 3 months.

 

SELECT * FROM tbldomains td LEFT JOIN tbldomainsadditionalfields tdaf ON td.id=tdaf.domainid WHERE td.status="expired" AND DATE(expirydate) < DATE_ADD(CURDATE(), INTERVAL -3 MONTH);

Should convert to this as a delete statement

DELETE tbldomains td, tbldomainsadditionalfields tdaf FROM td LEFT JOIN tbldomainsadditionalfields tdaf ON td.id=tdaf.domainid WHERE td.status="expired" AND DATE(expirydate) < DATE_ADD(CURDATE(), INTERVAL -3 MONTH);

 

I just want to know that I am not missing something obvious, is there other linked data? is my SQL going to delete everything I need to delete an no more?

Link to comment
Share on other sites

  • 1 month later...

Why use raw SQL? Just use a hook to get this straightened out on your cron runs? Save as something.php in includes/hooks/

<?php
//delete expired domains on cron
//provided by https://www.whmcs.guru
//version 1.0.0
use Illuminate\Database\Capsule\Manager as Capsule;
function check_domain_expiry($vars)
{

//how long do we wait before it's deleted?
$howlong = "90";

//set a base time
$time = time();

//really delete?
$reallydelete = TRUE;

if (!empty($graceperiod))
{
	//get the corrected date
	$graceperiod = $graceperiod  * 24 * 60 * 60;
	$todelete = $time - $graceperiod;
}
logActivity("Checking domains\n");
foreach (Capsule::table('tbldomains')->WHERE ('status', '=', 'Expired') ->get() as $domainrow) {
	$domid = $domainrow->id;
	$domname = $domainrow->domain;
	$expirydate = $domainrow->expirydate;
	if ($expirydate > $todelete)
	{
		if (!$reallydelete)
		{
			logActivity("I would delete $domname [$expirydate]\n");
		}
		if ($reallydelete)
		{
			Capsule::table('tbldomains')->where('id', '=', $domid)->delete();
			logActivity("Cron deleted $domname [$expirydate]\n");
		}
	}
}

logActivity ("Done checking domains\n");

}



//add the cron to run daily
add_hook('DailyCronJob', 1, check_domain_expiry );

 

This will check automatically every day if your domain is over 90 days expired and if so, delete it. Of course, it's going to log as well.

Change $reallytrue to FALSE to just get a log output :)

Link to comment
Share on other sites

Why use raw SQL? Just use a hook to get this straightened out on your cron runs? Save as something.php in includes/hooks/

This will check automatically every day if your domain is over 90 days expired and if so, delete it. Of course, it's going to log as well.

Change $reallytrue to FALSE to just get a log output :)

 

I've done the same, but I transfer the domains table data to a backup table, for client/domain history & future company reports.

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