Closed jas8522 closed 4 years ago
I've written most of this code, only to realize that switching to referencing by client usernames then results in problems when there are multiple subscriptions on the same server. The code would then return either the last subscription the XML-API returns (default), or the summation of all if we switch the usage[$username] = to usage[$username] +=
Neither of these are optimal.
As far as I can gather, the only good solution here is to find a way to detect when there is a primary domain mismatch between WHMCS and Plesk and correct it.
Anyone else have any ideas?
I created this WHMCS widget to notify me of hosting plans which have not updated their usage stats, which (so far) always means a primary domain mismatch, then I simply manually correct it when it's reported on my dashboard:
add_hook('AdminHomeWidgets', 6, function() {
return new ProductStatsUpdateFailures();
});
/**
* Product failing to update stats (indicates a domain mismatch with Plesk)
*/
class ProductStatsUpdateFailures extends \WHMCS\Module\AbstractWidget {
protected $title = 'Primary Domain Mismatches';
protected $description = 'When the domain for a hosting plan in WHMCS does not match the primary domain in Plesk, many things can go awry. This will show you any such mismatches for you to correct.';
protected $weight = 150;
protected $columns = 1;
protected $cache = true;
protected $cacheExpiry = 360;
protected $requiredPermission = '';
public function getData(){
// Get plans that haven't updated their status successfully
return Capsule::table('tblhosting')
->select( 'tblhosting.id', 'tblhosting.userid', 'tblhosting.domain', 'tblhosting.username' )
->leftJoin('tblservers', function($join)
{
$join->on('tblservers.id', '=', 'tblhosting.server');
})
->where('tblservers.type', '=', 'plesk')
->where('tblhosting.domainstatus', 'Active')
->where( 'tblhosting.lastupdate', '<', Carbon::now()->subDay() ) //yesterday
->get();
}
public function generateOutput($data){
$output = '<div class="widget-content-padded" style="padding-top:0;padding-bottom:0">';
foreach ($data as $plan){
$output .= '<div class="feed-element" style="padding: 10px 0; border-bottom: 1px solid #eee;">';
$output .= "<div class='pull-right'><i class='fas fa-times-circle fa-lg text-danger'></i></div>";
$output .= "<a href='clientsservices.php?userid={$plan->userid}&id={$plan->id}'>";
$output .= ($plan->domain)? $plan->domain : $plan->username;
$output .= '</a>';
$output .= '</div>';
}
$output .= '</div>';
//$output .= '<div class="footer text-center" style="padding: 6px 12px;font-size:12px"><a href="reports.php?report=disk_usage_summary&action=updatestats">Update Resource Stats</a></div>';
return $output;
}
}
This repository is no longer maintained. All questions regarding the WHMCS Plesk Provisioning Module should be addressed to WHMCS Technical Support. https://www.whmcs.com/submit-a-ticket/
If a client changes their primary domain name in Plesk, WHMCS is not informed of this. Since this usage updating code uses the primary domain supplied from the WHMCS DB to update the usage stats, the usage stats for the subscription do not get updated because it never matches the domain in WHMCS to the domain for the subscription in Plesk.
I suggest switching to using the username for the plan as the reference point. Since Plesk users cannot change their own username, they should never get out of sync. We get a number of clients each year that change their primary domain.
The code that I added for updating resellers could be adapted to work for shared hosting accounts as well, since it already uses the username as the cross-reference between WHMCS and Plesk.
Ultimately it would be great if somewhere in the code, this module could detect a primary domain name change and either provide an admin warning or simply change it in WHMCS's database. One possible downside of auto-changing the domain in WHMCS is that those with configured free domains alongside the hosting plan will need to adjust which domain is free. But presumably that would need to happen anyway.