From e7eb3495728ca9c2883d7cf07b363b48a95231fe Mon Sep 17 00:00:00 2001 From: Daniel Karbach Date: Tue, 21 Feb 2023 15:16:03 +0100 Subject: [PATCH] don't overdetach episode channels --- app/Console/Commands/SyncSpeedGaming.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/app/Console/Commands/SyncSpeedGaming.php b/app/Console/Commands/SyncSpeedGaming.php index eaaa4fa..6d0fa1f 100644 --- a/app/Console/Commands/SyncSpeedGaming.php +++ b/app/Console/Commands/SyncSpeedGaming.php @@ -176,10 +176,13 @@ class SyncSpeedGaming extends Command { foreach ($sgEntry['channels'] as $sgChannel) { $ext_ids[] = 'sg:'.$sgChannel['id']; } - $episode->channels() - ->where('ext_id', 'LIKE', 'sg:%') - ->whereNotIn('ext_id', $ext_ids) - ->detach(); + $channels = $episode->channels() + ->where('ext_id', 'LIKE', 'sg:%') + ->whereNotIn('ext_id', $ext_ids) + ->get(); + if (!$channels->isEmpty()) { + $episode->channels()->detach($channels->pluck('id')); + } } private function syncChannel(Episode $episode, $sgChannel) { -- 2.39.2