Multi-tenant scoping via CorePHP tenant package. workspace_id column added to all three tables. Existing records backfilled to workspace 1 (Lethean CIC). workspaceContextRequired=false allows public API calls without workspace context. Commit #100. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
80 lines
1.8 KiB
PHP
80 lines
1.8 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace Mod\Names\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
/**
|
|
* DNS change ticket — tracks alias update transactions.
|
|
*
|
|
* $ticket = DnsTicket::open('mybrand', $records, $txId);
|
|
* $ticket->confirm();
|
|
* $pending = DnsTicket::pending()->get();
|
|
*/
|
|
class DnsTicket extends Model
|
|
{
|
|
use \Core\Tenant\Concerns\BelongsToWorkspace;
|
|
|
|
protected bool $workspaceContextRequired = false;
|
|
|
|
protected $fillable = [
|
|
'ticket_id',
|
|
'name',
|
|
'status',
|
|
'tx_id',
|
|
'records',
|
|
'address',
|
|
'workspace_id',
|
|
'comment',
|
|
];
|
|
|
|
protected $casts = [
|
|
'records' => 'array',
|
|
];
|
|
|
|
protected static function booted(): void
|
|
{
|
|
static::creating(function (self $ticket) {
|
|
if (empty($ticket->ticket_id)) {
|
|
$ticket->ticket_id = bin2hex(random_bytes(6));
|
|
}
|
|
});
|
|
}
|
|
|
|
public function scopePending($query)
|
|
{
|
|
return $query->where('status', 'pending');
|
|
}
|
|
|
|
public function scopeQueued($query)
|
|
{
|
|
return $query->where('status', 'queued');
|
|
}
|
|
|
|
public function confirm(): void
|
|
{
|
|
$this->update(['status' => 'confirmed']);
|
|
}
|
|
|
|
public function fail(): void
|
|
{
|
|
$this->update(['status' => 'failed']);
|
|
}
|
|
|
|
/**
|
|
* Open a new DNS change ticket.
|
|
*/
|
|
public static function open(string $name, array $records, ?string $txId = null, ?string $address = null, ?string $comment = null): self
|
|
{
|
|
return static::create([
|
|
'name' => $name,
|
|
'status' => $txId ? 'pending' : 'queued',
|
|
'tx_id' => $txId,
|
|
'records' => $records,
|
|
'address' => $address,
|
|
'comment' => $comment,
|
|
]);
|
|
}
|
|
}
|