Files
ladill-servers/app/Models/ContaboInfrastructureProvision.php
isaaccladandCursor b6c8ac343f Extract Ladill Servers as standalone app at servers.ladill.com.
VPS and dedicated server ordering, managed panels, SSO, billing, and launcher integration — forked from hosting infrastructure with server-focused routes and dashboard.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-06 19:18:30 +00:00

114 lines
2.8 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ContaboInfrastructureProvision extends Model
{
public const PURPOSE_HOSTING_NODE = 'hosting_node';
public const PURPOSE_EMAIL_PRIMARY = 'email_primary';
public const PURPOSE_EMAIL_EXTENSION = 'email_extension';
public const STATUS_PENDING = 'pending';
public const STATUS_CREATING = 'creating';
public const STATUS_WAITING_IP = 'waiting_ip';
public const STATUS_BOOTSTRAPPING = 'bootstrapping';
public const STATUS_COMPLETED = 'completed';
public const STATUS_FAILED = 'failed';
protected $fillable = [
'purpose',
'status',
'name',
'contabo_product_id',
'region',
'image_id',
'contabo_instance_id',
'completion_token',
'payload',
'log',
'ssh_public_key',
'ssh_private_key',
'generated_mail_db_password',
'hosting_node_id',
'email_server_id',
'created_by',
'error_message',
'instance_created_at',
'ip_assigned_at',
'completed_at',
'failed_at',
];
protected $casts = [
'payload' => 'array',
'log' => 'array',
'instance_created_at' => 'datetime',
'ip_assigned_at' => 'datetime',
'completed_at' => 'datetime',
'failed_at' => 'datetime',
];
protected $hidden = [
'ssh_private_key',
'generated_mail_db_password',
'completion_token',
];
public function hostingNode(): BelongsTo
{
return $this->belongsTo(HostingNode::class);
}
public function emailServer(): BelongsTo
{
return $this->belongsTo(EmailServer::class);
}
public function creator(): BelongsTo
{
return $this->belongsTo(User::class, 'created_by');
}
public function completionUrl(): string
{
return url('/api/infrastructure/contabo/callback/'.$this->id.'?token='.$this->completion_token);
}
public function purposeLabel(): string
{
return match ($this->purpose) {
self::PURPOSE_HOSTING_NODE => 'Hosting node',
self::PURPOSE_EMAIL_PRIMARY => 'Mail server (primary)',
self::PURPOSE_EMAIL_EXTENSION => 'Mail server (extension)',
default => $this->purpose,
};
}
public function addLog(string $message): void
{
$log = $this->log ?? [];
$log[] = ['at' => now()->toIso8601String(), 'message' => $message];
$this->update(['log' => $log]);
}
public function markFailed(string $message): void
{
$this->update([
'status' => self::STATUS_FAILED,
'error_message' => $message,
'failed_at' => now(),
]);
$this->addLog('Failed: '.$message);
}
}