Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion app/Jobs/MergeChannels.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,12 @@ public function __construct(public Collection $channels, $user, $playlistId = nu
public function handle(): void
{
$processed = 0;
$groupedChannels = $this->channels->groupBy(function ($channel) {
// Filter out channels where the stream ID is empty
$filteredChannels = $this->channels->filter(function ($channel) {
return !empty($channel->stream_id_custom) || !empty($channel->stream_id);
});

$groupedChannels = $filteredChannels->groupBy(function ($channel) {
$streamId = $channel->stream_id_custom ?: $channel->stream_id;
return strtolower($streamId);
});
Expand Down
23 changes: 23 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,29 @@
use App\Http\Controllers\XtreamApiController;
use Illuminate\Support\Facades\Route;

use App\Jobs\MergeChannels;
use App\Models\Channel;
use App\Models\User;
use Illuminate\Support\Collection;

Route::get('/test-merge', function () {
// Create a user
$user = User::factory()->create();

// Create channels
$channel1 = Channel::factory()->create(['stream_id' => 'stream1', 'user_id' => $user->id]);
$channel2 = Channel::factory()->create(['stream_id' => 'stream1', 'user_id' => $user->id]);
$channel3 = Channel::factory()->create(['stream_id' => '', 'user_id' => $user->id]);
$channel4 = Channel::factory()->create(['stream_id' => null, 'user_id' => $user->id]);

$channels = new Collection([$channel1, $channel2, $channel3, $channel4]);

// Dispatch the job
MergeChannels::dispatch($channels, $user);

return 'Merge job dispatched';
});

/*
* Playlist/EPG output routes
*/
Expand Down
4 changes: 3 additions & 1 deletion start-container
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env bash

set -x

# Get/set runtime environment variables
export PUID="${PUID:-1000}" # NOT CURRENTLY USED...
export PGID="${PGID:-1000}" # NOT CURRENTLY USED...
Expand Down Expand Up @@ -46,7 +48,7 @@ export QUEUE_PHP_COMMAND="/usr/bin/php /var/www/html/artisan horizon"
export WEBSOCKET_PHP_COMMAND="/usr/bin/php /var/www/html/artisan reverb:start --host=0.0.0.0 --port=$REVERB_PORT --no-interaction --no-ansi"

# Make sure the laravel project is installed
if [ ! -f "/var/www/html/artisan" ]; then
if [ ! -f "artisan" ]; then
echo "Laravel artisan not found! Make sure project is installed."
exit 1
fi
Expand Down
36 changes: 36 additions & 0 deletions tests/Unit/MergeChannelsTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace Tests\Unit;

use App\Jobs\MergeChannels;
use App\Models\Channel;
use App\Models\User;
use Illuminate\Foundation\Testing\RefreshDatabase;
use Illuminate\Support\Collection;
use Tests\TestCase;

class MergeChannelsTest extends TestCase
{
use RefreshDatabase;

/** @test */
public function it_does_not_merge_channels_with_empty_stream_ids()
{
// Create a user
$user = User::factory()->create();

// Create channels
$channel1 = Channel::factory()->create(['stream_id' => 'stream1', 'user_id' => $user->id]);
$channel2 = Channel::factory()->create(['stream_id' => 'stream1', 'user_id' => $user->id]);
$channel3 = Channel::factory()->create(['stream_id' => '', 'user_id' => $user->id]);
$channel4 = Channel::factory()->create(['stream_id' => null, 'user_id' => $user->id]);

$channels = new Collection([$channel1, $channel2, $channel3, $channel4]);

// Dispatch the job
MergeChannels::dispatch($channels, $user);

// Assert that only the channels with the same stream_id were merged
$this->assertDatabaseCount('channel_failovers', 1);
}
}