]> git.localhorst.tv Git - alttp.git/commitdiff
don't overdetach episode channels
authorDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Feb 2023 14:16:03 +0000 (15:16 +0100)
committerDaniel Karbach <daniel.karbach@localhorst.tv>
Tue, 21 Feb 2023 14:16:03 +0000 (15:16 +0100)
app/Console/Commands/SyncSpeedGaming.php

index eaaa4fa48e7ccb5989d0c4ca29218ed3c80857c5..6d0fa1faa777801f213af2f38abfb8c62ec33047 100644 (file)
@@ -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) {