1111use Illuminate \Contracts \Queue \ShouldQueue ;
1212use Illuminate \Foundation \Queue \Queueable ;
1313use Illuminate \Support \Facades \Http ;
14+ use Illuminate \Support \Facades \Log ;
1415use JsonMachine \Items ;
1516
1617class 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