This simple WHMCS hook adds few details about services managed by the WHMCS auto-release module.
Auto-release is a handy way to manage in WHMCS external services manually, and it's useful for services that have no full integration modules available.
But if you set to manage them using internal to-do utility, it may be annoying because WHMCS will report just the service ID and a short description of action required (renew, suspend, etc.)
This simple hook will add also service name, making the following job easier faster, and even more safe (it may happen that you open the service with a wrong ID, so i.e. you go on renewing the wrong service...)
This hook is available also on GitHub repository: https://github.com/DomainRegister/WHMCS-enhanced-auto-release
<?php
//
// enhanced to-do
// WHMCS hook to enrich details about services managed by auto-release module
//
// https://domainregister.international/
//
add_hook('AfterCronJob', 100, function($vars) {
try {
$todoitem = Capsule::table('tbltodolist')
->where('status', '!=', 'Completed')
->where('description', 'like', 'Service ID # %')
->select('id','description')
->first();
} catch (\Exception $e) {
echo "error {$e->getMessage()}";
}
$descr2=substr($todoitem->description,12);
$serviceid=intval($descr2);
$descr3=preg_replace( '/Service ID # \d+/', '', $todoitem->description );
try {
$servicename = Capsule::table('tblhosting')
->where("id", $serviceid)
->select('domain')
->first();
echo "<pre>"; print_r($servicename);
} catch(\Illuminate\Database\QueryException $ex){
echo $ex->getMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
$newdescription = 'Service ID #'.$serviceid.' ( '.$servicename->domain.' ) '.$descr3.PHP_EOL;
try {
$update_data = [
'description' => $newdescription
];
Capsule::table('tbltodolist')
->where('id', '=', $todoitem->id)
->update($update_data);
} catch(\Illuminate\Database\QueryException $ex){
echo $ex->getMessage();
} catch (Exception $e) {
echo $e->getMessage();
}
});