Jump to content

Clean up To Do list: Automatically complete 'Pending Domain Transfers' when domain is transferred


Recommended Posts

I simply can't comprehend why WHMCS doesn't do this automatically. Dealing with multiple transfers each day, the To Do list becomes cluttered really fast.

The following hook will execute on 'DomainTransferCompleted', look for Pending Domain Transfers that are In Progress containing the domain name and set all of them to Completed (in case there are multiple entries).

<?php
use WHMCS\Database\Capsule;
add_hook('DomainTransferCompleted', 1, function($vars) {
    //This hook will complete to do items for transfers when the transfer is completed.
	$toDoID = Capsule::table('tbltodolist')
		->where('status', 'In Progress')
		->where('title', 'Domain Pending Transfer')
		->where('description', 'LIKE', '% ' . $vars["domain"] . ' %')
		->get();
	
	//Loop through the ID's and set them as completed.
	foreach ($toDoID as $entry) {
		$command = 'UpdateToDoItem';
		$postData = array(
		'itemid' => $entry->id,
		'adminid' => '1',
		'status' => 'Completed',
	);

	$results = localAPI($command, $postData);
	print_r($results);
	}

});

Place the file in /includes/hooks/.

UpdateToDo.php

Edited by DennisMidjord
Link to comment
Share on other sites

Made a very small typo in the first. Use this instead:

<?php
use WHMCS\Database\Capsule;
add_hook('DomainTransferCompleted', 1, function($vars) {
    //This hook will complete to do items for transfers when the transfer is completed.
	$toDoID = Capsule::table('tbltodolist')
		->where('status', 'In Progress')
		->where('title', 'Domain Pending Transfer')
		->where('description', 'LIKE', '% ' . $vars["domain"] . '%')
		->get();
	
	//Loop through the ID's and set them as completed.
	foreach ($toDoID as $entry) {
		$command = 'UpdateToDoItem';
		$postData = array(
		'itemid' => $entry->id,
		'adminid' => '1',
		'status' => 'Completed',
	);

	$results = localAPI($command, $postData);
	}

});

Remember to update 'adminid' with the actual ID of an admin.

UpdateToDo.php

Link to comment
Share on other sites

  • 4 weeks later...

I've expanded this hook a bit to also cover failed transfers and log everything it does to the activity log.

<?php
use WHMCS\Database\Capsule;
add_hook('DomainTransferCompleted', 1, function($vars) {
    //This hook will complete to-do items for transfers when the transfer is completed.
	$toDoID = Capsule::table('tbltodolist')
		->where('status', 'In Progress')
		->where('title', 'Domain Pending Transfer')
		->where('description', 'LIKE', '% ' . $vars['domain'] . '%')
		->get();
	
	//Loop through the ID's and set them as completed.
	foreach ($toDoID as $entry) {
		$command = 'UpdateToDoItem';
		$postData = array(
		'itemid' => $entry->id,
		'adminid' => '1', //Update this ID to an admin ID
		'status' => 'Completed', 
		);
		
		localAPI($command, $postData);
		logActivity('Clean-up To-do List: ID ' . $entry->id . ' has been set as complete as the transfer completed successfully - Domain ID: ' . $vars['domainid'] . ' - Domain: ' . $vars['domain']);
	}

});

add_hook('DomainTransferFailed', 1, function($vars) {
    //This hook will update to-do items for ttransfer that fails.
	$toDoID = Capsule::table('tbltodolist')
		->where('status', 'In Progress')
		->where('title', 'Domain Pending Transfer')
		->where('description', 'LIKE', '% ' . $vars['domain'] . '%')
		->get();

	foreach ($toDoID as $entry) {
		$description = Capsule::table('tbltodolist')
		->where('id', $entry->id)
		->value('description');
		
		$command = 'UpdateToDoItem';
		$postData = array(
		'itemid' => $entry->id,
		'adminid' => '1', //Update this ID to an admin ID
		'status' => 'Incomplete', 
		'description' => '*FAILED* '.$description,
		);
		localAPI($command, $postData);
		logActivity('Clean-up To-do List: ID ' . $entry->id . ' has been set as incomplete as the transfer has failed - Domain ID: ' . $vars['domainid'] . ' - Domain: ' . $vars['domain']);
	}
});

 

Edited by DennisHermannsen
Typos
Link to comment
Share on other sites

  • 5 months later...
  • 1 month later...
  • 5 months later...
  • 6 months later...

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