2026-06-20 07:23:16 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Events;
|
|
|
|
|
|
|
|
|
|
use App\Models\V5\Application as V5Application;
|
|
|
|
|
use App\Models\V5\Server as V5Server;
|
2026-07-06 15:40:37 +00:00
|
|
|
use App\Support\V5\CanvasResourceSerializer;
|
2026-06-20 07:23:16 +00:00
|
|
|
use Illuminate\Broadcasting\InteractsWithSockets;
|
|
|
|
|
use Illuminate\Broadcasting\PrivateChannel;
|
2026-07-06 15:40:37 +00:00
|
|
|
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;
|
2026-06-20 07:23:16 +00:00
|
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
2026-07-06 15:40:37 +00:00
|
|
|
class V5CanvasResourceUpdated implements ShouldBroadcast
|
2026-06-20 07:23:16 +00:00
|
|
|
{
|
|
|
|
|
use Dispatchable, InteractsWithSockets, SerializesModels;
|
|
|
|
|
|
2026-07-06 15:40:37 +00:00
|
|
|
/**
|
|
|
|
|
* Push the queued broadcast job only after the dispatching database
|
|
|
|
|
* transaction commits, so workers never serialize pre-commit state.
|
|
|
|
|
*/
|
|
|
|
|
public bool $afterCommit = true;
|
|
|
|
|
|
2026-06-20 07:23:16 +00:00
|
|
|
public function __construct(
|
|
|
|
|
public int $teamId,
|
|
|
|
|
public ?int $applicationId = null,
|
|
|
|
|
public ?int $caddyIngressServerId = null,
|
2026-06-22 09:56:26 +00:00
|
|
|
public ?int $serverId = null,
|
2026-06-20 07:23:16 +00:00
|
|
|
) {}
|
|
|
|
|
|
|
|
|
|
public function broadcastOn(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
new PrivateChannel("team.{$this->teamId}"),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function broadcastAs(): string
|
|
|
|
|
{
|
|
|
|
|
return 'v5.canvas.resource.updated';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-06-22 09:56:26 +00:00
|
|
|
* @return array{application: array<string, mixed>|null, applications: array<int, array<string, mixed>>, caddyIngress: array<string, mixed>|null}
|
2026-06-20 07:23:16 +00:00
|
|
|
*/
|
|
|
|
|
public function broadcastWith(): array
|
|
|
|
|
{
|
2026-07-06 15:40:37 +00:00
|
|
|
$serializer = app(CanvasResourceSerializer::class);
|
2026-06-20 07:23:16 +00:00
|
|
|
$application = $this->applicationId !== null
|
2026-06-22 09:56:26 +00:00
|
|
|
? V5Application::query()->with(['server', 'domains'])->find($this->applicationId)
|
2026-06-20 07:23:16 +00:00
|
|
|
: null;
|
2026-06-22 09:56:26 +00:00
|
|
|
$applications = $this->serverId !== null
|
|
|
|
|
? V5Application::query()
|
|
|
|
|
->where('server_id', $this->serverId)
|
|
|
|
|
->with(['server', 'domains'])
|
|
|
|
|
->get()
|
|
|
|
|
: collect();
|
2026-06-20 07:23:16 +00:00
|
|
|
$caddyIngress = $this->caddyIngressServerId !== null
|
|
|
|
|
? V5Server::query()->find($this->caddyIngressServerId)
|
|
|
|
|
: null;
|
|
|
|
|
|
|
|
|
|
return [
|
2026-07-06 15:40:37 +00:00
|
|
|
'application' => $application instanceof V5Application ? $serializer->serializeApplication($application) : null,
|
2026-06-22 09:56:26 +00:00
|
|
|
'applications' => $applications
|
2026-07-06 15:40:37 +00:00
|
|
|
->map(fn (V5Application $application) => $serializer->serializeApplication($application))
|
2026-06-22 09:56:26 +00:00
|
|
|
->values()
|
|
|
|
|
->all(),
|
2026-06-20 07:23:16 +00:00
|
|
|
'caddyIngress' => $caddyIngress instanceof V5Server && $caddyIngress->isIngress()
|
2026-07-06 15:40:37 +00:00
|
|
|
? $serializer->serializeCaddyIngress($caddyIngress)
|
2026-06-20 07:23:16 +00:00
|
|
|
: null,
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|