From: Daniel Karbach Date: Tue, 21 Feb 2023 14:16:03 +0000 (+0100) Subject: don't overdetach episode channels X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=e7eb3495728ca9c2883d7cf07b363b48a95231fe;p=alttp.git don't overdetach episode channels --- 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) {