Initial Ladill Hosting app with Gitea deploy pipeline.
Deploy Ladill Hosting / deploy (push) Failing after 17s
Deploy Ladill Hosting / deploy (push) Failing after 17s
Shared web hosting extracted from the platform monolith, with CI deploy to /var/www/ladill-hosting matching Bird/Domains/Email. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -0,0 +1,137 @@
|
||||
<?php
|
||||
|
||||
namespace App\Services\Domain;
|
||||
|
||||
use App\Models\Domain;
|
||||
use App\Models\DomainOrder;
|
||||
use App\Models\RcServiceOrder;
|
||||
|
||||
class DomainRegistryService
|
||||
{
|
||||
/**
|
||||
* Create or update the unified domain registry entry for a registrar purchase.
|
||||
*/
|
||||
public function recordPurchasedDomain(
|
||||
int $userId,
|
||||
string $host,
|
||||
string $registrar,
|
||||
?string $registrarOrderId = null,
|
||||
bool $verified = true,
|
||||
array $meta = [],
|
||||
): Domain {
|
||||
$host = strtolower(trim($host));
|
||||
|
||||
$existing = Domain::query()->where('host', $host)->first();
|
||||
|
||||
$verificationMeta = array_merge(
|
||||
(array) ($existing?->verification_meta ?? []),
|
||||
$meta,
|
||||
array_filter([
|
||||
'registrar' => $registrar,
|
||||
'registrar_order_id' => $registrarOrderId,
|
||||
'registered_at' => $verified ? now()->toIso8601String() : null,
|
||||
]),
|
||||
);
|
||||
|
||||
$attributes = [
|
||||
'user_id' => $existing?->user_id ?: $userId,
|
||||
'host' => $host,
|
||||
'type' => $existing?->type ?: 'custom',
|
||||
'source' => $this->resolveSource($existing),
|
||||
'onboarding_mode' => $existing?->onboarding_mode ?: Domain::MODE_RESELLER_AUTO,
|
||||
'status' => $verified ? 'verified' : ($existing?->status ?: 'pending'),
|
||||
'onboarding_state' => $verified
|
||||
? Domain::STATE_ACTIVE
|
||||
: ($existing?->onboarding_state ?: Domain::STATE_PENDING_NS),
|
||||
'registrar' => $registrar ?: $existing?->registrar,
|
||||
'registrar_order_id' => $registrarOrderId ?: $existing?->registrar_order_id,
|
||||
'verified_at' => $verified ? ($existing?->verified_at ?: now()) : $existing?->verified_at,
|
||||
'verification_meta' => $verificationMeta,
|
||||
];
|
||||
|
||||
if ($existing) {
|
||||
$existing->update($attributes);
|
||||
|
||||
return $existing->fresh();
|
||||
}
|
||||
|
||||
return Domain::create($attributes);
|
||||
}
|
||||
|
||||
public function recordFromDomainOrder(DomainOrder $order, bool $verified = true): Domain
|
||||
{
|
||||
if (! $order->user_id) {
|
||||
throw new \InvalidArgumentException('Domain order is missing user_id.');
|
||||
}
|
||||
|
||||
return $this->recordPurchasedDomain(
|
||||
$order->user_id,
|
||||
$order->domain_name,
|
||||
(string) ($order->registrar ?: DomainOrder::REGISTRAR_DYNADOT),
|
||||
$order->registrar_order_id ? (string) $order->registrar_order_id : null,
|
||||
$verified,
|
||||
[
|
||||
'domain_order_id' => $order->id,
|
||||
'order_type' => $order->order_type,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function recordFromRcServiceOrder(RcServiceOrder $order, bool $verified = false): ?Domain
|
||||
{
|
||||
if (! $order->user_id || ! filled($order->domain_name)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
if (! in_array($order->order_type, [
|
||||
RcServiceOrder::TYPE_DOMAIN_REGISTRATION,
|
||||
RcServiceOrder::TYPE_DOMAIN_TRANSFER,
|
||||
], true)) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return $this->recordPurchasedDomain(
|
||||
$order->user_id,
|
||||
$order->domain_name,
|
||||
DomainOrder::REGISTRAR_RESELLERCLUB,
|
||||
$order->rc_order_id ? (string) $order->rc_order_id : null,
|
||||
$verified,
|
||||
[
|
||||
'rc_service_order_id' => $order->id,
|
||||
'order_type' => $order->order_type,
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
public function markVerified(string $host): ?Domain
|
||||
{
|
||||
$domain = Domain::query()->where('host', strtolower(trim($host)))->first();
|
||||
|
||||
if (! $domain) {
|
||||
return null;
|
||||
}
|
||||
|
||||
$domain->update([
|
||||
'status' => 'verified',
|
||||
'onboarding_state' => Domain::STATE_ACTIVE,
|
||||
'verified_at' => $domain->verified_at ?: now(),
|
||||
]);
|
||||
|
||||
return $domain->fresh();
|
||||
}
|
||||
|
||||
private function resolveSource(?Domain $existing): string
|
||||
{
|
||||
if (! $existing) {
|
||||
return 'purchased';
|
||||
}
|
||||
|
||||
$source = (string) ($existing->source ?: '');
|
||||
|
||||
if (in_array($source, ['website', 'hosting', 'email', 'hosting_email', 'website_email'], true)) {
|
||||
return $source;
|
||||
}
|
||||
|
||||
return 'purchased';
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user