2026-06-19 09:44:42 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Events;
|
|
|
|
|
|
|
|
|
|
use App\Models\V5\Cluster as V5Cluster;
|
2026-07-06 15:40:37 +00:00
|
|
|
use App\Support\V5\ClusterSerializer;
|
2026-06-19 09:44:42 +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-19 09:44:42 +00:00
|
|
|
use Illuminate\Foundation\Events\Dispatchable;
|
|
|
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
|
|
2026-07-06 15:40:37 +00:00
|
|
|
class V5ClusterUpdated implements ShouldBroadcast
|
2026-06-19 09:44:42 +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-19 09:44:42 +00:00
|
|
|
public function __construct(public int $teamId, public int $clusterId) {}
|
|
|
|
|
|
|
|
|
|
public function broadcastOn(): array
|
|
|
|
|
{
|
|
|
|
|
return [
|
|
|
|
|
new PrivateChannel("team.{$this->teamId}"),
|
|
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function broadcastAs(): string
|
|
|
|
|
{
|
|
|
|
|
return 'v5.cluster.updated';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* @return array{cluster: array<string, mixed>|null}
|
|
|
|
|
*/
|
|
|
|
|
public function broadcastWith(): array
|
|
|
|
|
{
|
|
|
|
|
$cluster = V5Cluster::query()
|
|
|
|
|
->where('team_id', $this->teamId)
|
|
|
|
|
->with(['servers' => fn ($query) => $query
|
|
|
|
|
->with('privateKey')
|
|
|
|
|
->orderBy('name')])
|
|
|
|
|
->withCount('servers')
|
|
|
|
|
->find($this->clusterId);
|
|
|
|
|
|
|
|
|
|
return [
|
2026-07-06 15:40:37 +00:00
|
|
|
'cluster' => $cluster instanceof V5Cluster ? app(ClusterSerializer::class)->serialize($cluster) : null,
|
2026-06-19 09:44:42 +00:00
|
|
|
];
|
|
|
|
|
}
|
|
|
|
|
}
|