-
Resolve service context — at the top of doEnable/doDisable:
$serviceInfo = $serviceOrder->getServiceInfo();
$settings = get_module_settings(self::$module);
function_requirements('get_service_master');
$serverdata = get_service_master($serviceInfo[$settings['PREFIX'].'_server'], self::$module);
Verify $settings['PREFIX'], $settings['TABLE'], $settings['TBLNAME'], and $settings['TITLE_FIELD'] are available before proceeding.
-
Guard non-WHM service types — wrap all WHM logic in the else branch of the type check shown in Critical above. No return inside the empty if body — leave it empty per existing convention.
-
Load and init \xmlapi:
function_requirements('whm_api');
$whm = new \xmlapi($serverdata[$settings['PREFIX'].'_ip']);
$whm->set_port('2087');
$whm->set_protocol('https');
$whm->set_output('json');
$whm->set_auth_type('hash');
$whm->set_user('root');
$whm->set_hash($serverdata[$settings['PREFIX'].'_key']);
Leave the commented-out set_debug line in place — it matches the existing codebase style.
-
Make the WHM API call and log the raw response (uses output from step 3):
$response = $whm->setsiteip($newIp, $serviceInfo[$settings['PREFIX'].'_username']);
myadmin_log(self::$module, 'info', "WHM setsiteip({$newIp}, {$serviceInfo[$settings['PREFIX'].'_username']}) Response: {$response}", __LINE__, __FILE__, self::$module, $serviceInfo[$settings['PREFIX'].'_id']);
$response = json_decode($response);
Replace setsiteip with the actual WHM API method name for your operation.
-
Branch on $response->result[0]->status (uses output from step 4):
if ($response->result[0]->status == 1) {
$db = get_module_db(self::$module);
$db->query("update {$settings['TABLE']} set {$settings['PREFIX']}_ip='{$newIp}' where {$settings['PREFIX']}_id={$serviceInfo[$settings['PREFIX'].'_id']}", __LINE__, __FILE__);
myadmin_log(self::$module, 'info', "Success message", __LINE__, __FILE__, self::$module, $serviceInfo[$settings['PREFIX'].'_id']);
} else {
myadmin_log(self::$module, 'info', "Error message", __LINE__, __FILE__, self::$module, $serviceInfo[$settings['PREFIX'].'_id']);
$subject = 'Error Setting IP '.$serviceInfo[$settings['PREFIX'].'_ip'].' on '.$settings['TBLNAME'].' '.$serviceInfo[$settings['TITLE_FIELD']];
(new \MyAdmin\Mail())->adminMail($subject, $subject, false, 'admin/website_no_ips.tpl');
}
-
Handle resource exhaustion (e.g., no free IPs) before making the API call:
if (count($ips['free']) > 0) {
} else {
$subject = "0 Free IPs On {$settings['TBLNAME']} Server {$serverdata[$settings['PREFIX'].'_name']}";
(new \MyAdmin\Mail())->adminMail($subject, "webserver {$serviceInfo[$settings['PREFIX'].'_id']} Has Pending IPS<br>\n".$subject, false, 'admin/website_no_ips.tpl');
myadmin_log(self::$module, 'info', $subject, __LINE__, __FILE__, self::$module, $serviceInfo[$settings['PREFIX'].'_id']);
}
-
Verify by running: vendor/bin/phpunit tests/ -v