Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,95 @@ private function getContactDetails($params): array
unset($contacts['Reseller']);
unset($contacts['reseller']);

$this->syncHandlesWithWhmcs($params, $handlesToFetch, $contacts);
Comment thread
avishka-ra marked this conversation as resolved.

return $contacts;
}

/**
* Sync wHandles and wDomain_handle for the fetched OP contact handles.
* Creates missing rows and updates the data field when it has changed.
*/
Comment thread
avishka-ra marked this conversation as resolved.
private function syncHandlesWithWhmcs(array $params, array $handlesToFetch, array $contacts): void
{
try {
$domainName = ($params['sld'] ?? '') . '.' . ($params['tld'] ?? '');
$whmcsDomain = Capsule::table('tbldomains')
->where('domain', $domainName)
->first(['id', 'userid']);
Comment thread
avishka-ra marked this conversation as resolved.

if (!$whmcsDomain) {
return;
}

$domainId = (int) $whmcsDomain->id;
$userId = (int) $whmcsDomain->userid;

$roleToType = [
'Owner' => 'registrant',
'Admin' => 'admin',
'Tech' => 'tech',
'Billing' => 'billing',
];

foreach ($handlesToFetch as $roleName => $handleId) {
if (empty($handleId)) {
continue;
}

$type = $roleToType[$roleName] ?? strtolower($roleName);

if (empty($contacts[$roleName])) {
continue;
}

// Build a Customer object the same way prepareHandle does, using the contactdetails path
$customerParams = [
'contactdetails' => [ucfirst($roleName) => $contacts[$roleName]],
];
$row = Capsule::table('wHandles')
->where('handle', $handleId)
->where('user_id', $userId)
->where('registrar', 'openprovider')
->first();
Comment thread
avishka-ra marked this conversation as resolved.
Outdated

if (!$row) {
$customerObj = new \OpenProvider\API\Customer($customerParams, strtolower($roleName));
$handleDbId = Capsule::table('wHandles')->insertGetId([
'handle' => $handleId,
'user_id' => $userId,
'registrar' => 'openprovider',
'type' => $type,
'data' => serialize($customerObj),
]);
Comment thread
avishka-ra marked this conversation as resolved.
Outdated
} else {
// Not overwriting data on an existing row — it may have been written by
// prepareHandle with extensionAdditionalData set. Overwriting with our
// partial Customer (extensionAdditionalData = null) would break findExisting's
// exact-match lookup and cause duplicate handles on OP during register/transfer.
$handleDbId = $row->id;
}

$existingLink = Capsule::table('wDomain_handle')
->where('domain_id', $domainId)
->where('type', $type)
->first();

if (!$existingLink) {
Capsule::table('wDomain_handle')->insert([
'domain_id' => $domainId,
'handle_id' => $handleDbId,
'type' => $type,
]);
Comment thread
avishka-ra marked this conversation as resolved.
Outdated
} elseif ((int) $existingLink->handle_id !== $handleDbId) {
Capsule::table('wDomain_handle')
->where('domain_id', $domainId)
->where('type', $type)
->update(['handle_id' => $handleDbId]);
Comment thread
avishka-ra marked this conversation as resolved.
Outdated
}
}
} catch (\Exception $e) {
logModuleCall('openprovider', 'syncHandlesWithWhmcs', $params, $e->getMessage());
}
}
}
11 changes: 11 additions & 0 deletions modules/registrars/openprovider/src/Handle.php
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,24 @@ public function updateOrCreate($params, $type = 'registrant')
$this->model = $domain->handles()->wherePivot('type', $type)->firstOrFail();
$currentHandleType = $this->model->type;

// Serialize the currently stored Customer before prepareHandle replaces it.
$storedData = serialize($this->model->data);
Comment thread
avishka-ra marked this conversation as resolved.
Outdated

// No domain found with this handle, let's continue
$this->prepareHandle($params, $type);

$action = $this->findChanges($params);

if($action == false)
{
// OP data matches the form, but wHandles.data may still be stale (e.g. written
// by syncHandlesWithWhmcs or an older flow). Update it so findExisting stays accurate.
$newData = serialize($this->customer);
if ($newData !== $storedData) {
Capsule::table('wHandles')
->where('id', $this->model->id)
->update(['data' => $newData]);
Comment thread
avishka-ra marked this conversation as resolved.
Outdated
}
return $this->model->handle;
}

Expand Down