Skip to content

Commit 78b361d

Browse files
committed
Add bulk action for assigning failover channels
1 parent cf15b9e commit 78b361d

File tree

2 files changed

+75
-2
lines changed

2 files changed

+75
-2
lines changed

app/Console/Commands/PruneStaleHlsProcesses.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public function handle()
4444
if ($lastSeen->addSeconds($threshold)->isPast()) {
4545
$wasRunning = $this->hlsService->stopStream(type: 'channel', id: $channelId);
4646
if (!$wasRunning) {
47-
$this->info("❌ Channel {$channelId} was not running, skipping");
47+
$this->info("❌ Channel {$channelId} was not running");
4848
continue;
4949
} else {
5050
$this->info("❌ Channel {$channelId} was running and has been stopped");
@@ -66,7 +66,7 @@ public function handle()
6666
if ($lastSeen->addSeconds($threshold)->isPast()) {
6767
$wasRunning = $this->hlsService->stopStream(type: 'episode', id: $episodeId);
6868
if (!$wasRunning) {
69-
$this->info("❌ Episode {$episodeId} was not running, skipping");
69+
$this->info("❌ Episode {$episodeId} was not running");
7070
continue;
7171
} else {
7272
$this->info("❌ Episode {$episodeId} was running and has been stopped");

app/Filament/Resources/ChannelResource.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,79 @@ public static function setupTable(Table $table, $relationId = null): Table
398398
->modalIcon('heroicon-o-photo')
399399
->modalDescription('Update the preferred icon for the selected channel(s).')
400400
->modalSubmitActionLabel('Update now'),
401+
402+
Tables\Actions\BulkAction::make('failover')
403+
->label('Add as failover')
404+
->form([
405+
Forms\Components\Select::make('master_channel_id')
406+
->label('Master Channel')
407+
->options(function ($state) {
408+
// Get the current channel ID to exclude it from options
409+
$channels = \App\Models\Channel::query()
410+
->withoutEagerLoads()
411+
->with('playlist')
412+
->when($state, function ($query) use ($state) {
413+
return $query->where('id', '=', $state);
414+
})->limit(100)->get();
415+
416+
// Create options array
417+
$options = [];
418+
foreach ($channels as $channel) {
419+
$displayTitle = $channel->title_custom ?: $channel->title;
420+
$playlistName = $channel->playlist->name ?? 'Unknown';
421+
$options[$channel->id] = "{$displayTitle} [{$playlistName}]";
422+
}
423+
424+
return $options;
425+
})
426+
->searchable()
427+
->getSearchResultsUsing(function (string $search) {
428+
// Always include the selected value if it exists
429+
$channels = \App\Models\Channel::query()
430+
->withoutEagerLoads()
431+
->with('playlist')
432+
->where(function ($query) use ($search) {
433+
$query->where('title', 'like', "%{$search}%")
434+
->orWhere('title_custom', 'like', "%{$search}%")
435+
->orWhere('name', 'like', "%{$search}%")
436+
->orWhere('name_custom', 'like', "%{$search}%");
437+
})
438+
->limit(50) // Reasonable limit for search results
439+
->get();
440+
441+
// Create options array
442+
$options = [];
443+
foreach ($channels as $channel) {
444+
$displayTitle = $channel->title_custom ?: $channel->title;
445+
$playlistName = $channel->playlist->name ?? 'Unknown';
446+
$options[$channel->id] = "{$displayTitle} [{$playlistName}]";
447+
}
448+
449+
return $options;
450+
})
451+
->required(),
452+
])
453+
->action(function (Collection $records, array $data): void {
454+
foreach ($records as $record) {
455+
ChannelFailover::updateOrCreate([
456+
'channel_id' => $data['master_channel_id'],
457+
'channel_failover_id' => $record->id,
458+
]);
459+
}
460+
})->after(function () {
461+
Notification::make()
462+
->success()
463+
->title('Channels as failover')
464+
->body('The selected channels have been added as failovers.')
465+
->send();
466+
})
467+
->deselectRecordsAfterCompletion()
468+
->requiresConfirmation()
469+
->icon('heroicon-o-arrow-path-rounded-square')
470+
->modalIcon('heroicon-o-arrow-path-rounded-square')
471+
->modalDescription('Add the selected channel(s) to the chosen channel as failover sources.')
472+
->modalSubmitActionLabel('Add failovers now'),
473+
401474
Tables\Actions\BulkAction::make('find-replace')
402475
->label('Find & Replace')
403476
->form([

0 commit comments

Comments
 (0)