Skip to content

Commit a18e5b7

Browse files
committed
fix: Series missing name
1 parent 6f87e5c commit a18e5b7

File tree

1 file changed

+25
-3
lines changed

1 file changed

+25
-3
lines changed

app/Jobs/ProcessM3uImportSeriesChunk.php

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
use Illuminate\Contracts\Queue\ShouldQueue;
1212
use Illuminate\Foundation\Queue\Queueable;
1313
use Illuminate\Support\Facades\Http;
14+
use Illuminate\Support\Facades\Log;
1415
use JsonMachine\Items;
1516

1617
class ProcessM3uImportSeriesChunk implements ShouldQueue
@@ -134,6 +135,15 @@ public function handle(): void
134135

135136
// Create the streams
136137
foreach ($seriesStreams as $item) {
138+
// Normalize and validate the name — some providers omit it which violates the DB NOT NULL constraint
139+
$itemName = $item->name ?? $item->title ?? null;
140+
$itemName = $itemName !== null ? trim((string) $itemName) : null;
141+
142+
// We need a name to proceed, if still not set, skip this item
143+
if (empty($itemName)) {
144+
continue;
145+
}
146+
137147
// Check if we already have this series in the playlist
138148
$existingSeries = $playlist->series()
139149
->where('source_series_id', $item->series_id)
@@ -148,7 +158,7 @@ public function handle(): void
148158
// If we reach here, it means we need to create a new series
149159
$bulk[] = [
150160
'enabled' => $this->autoEnable, // Disable the series by default
151-
'name' => $item->name,
161+
'name' => $itemName,
152162
'source_series_id' => $item->series_id,
153163
'source_category_id' => $sourceCategoryId,
154164
'import_batch_no' => $this->batchNo,
@@ -174,7 +184,19 @@ public function handle(): void
174184
'series_progress' => min(99, $playlist->series_progress + ($this->batchCount / 100) * 5),
175185
]);
176186

177-
// Bulk insert the series in chunks
178-
collect($bulk)->chunk(100)->each(fn ($chunk) => Series::insert($chunk->toArray()));
187+
// Bulk insert the series in chunks with logging on failure
188+
collect($bulk)->chunk(100)->each(function ($chunk) {
189+
try {
190+
Series::insert($chunk->toArray());
191+
} catch (\Throwable $e) {
192+
Log::error('Series bulk insert failed', [
193+
'exception' => $e->getMessage(),
194+
'chunk' => $chunk->toArray(),
195+
]);
196+
197+
// Re-throw so the job fails loudly if needed
198+
throw $e;
199+
}
200+
});
179201
}
180202
}

0 commit comments

Comments
 (0)