X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;ds=sidebyside;f=app%2FConsole%2FCommands%2FSyncSpeedGaming.php;h=656a079cf87ad2c843b9131c0c6a42bc6e104776;hb=11e76fc2410dc26cd9c19cac4117d36ce3212523;hp=177ee1947675b67485ffa8ca1148439a94572ce0;hpb=1a20c129923b63977d52a9fa80b7f85c9af8aaa9;p=alttp.git diff --git a/app/Console/Commands/SyncSpeedGaming.php b/app/Console/Commands/SyncSpeedGaming.php index 177ee19..656a079 100644 --- a/app/Console/Commands/SyncSpeedGaming.php +++ b/app/Console/Commands/SyncSpeedGaming.php @@ -59,7 +59,7 @@ class SyncSpeedGaming extends Command { 'from' => $from->toIso8601String(), 'to' => $to->toIso8601String(), ])->json(); - $this->purgeSchedule($event, $sgSchedule); + $this->purgeSchedule($event, $from, $to, $sgSchedule); foreach ($sgSchedule as $sgEntry) { try { $this->syncSchedule($event, $sgEntry); @@ -69,12 +69,19 @@ class SyncSpeedGaming extends Command { } } - private function purgeSchedule(Event $event, $sgSchedule) { + private function purgeSchedule(Event $event, $from, $to, $sgSchedule) { $ext_ids = []; foreach ($sgSchedule as $sgEntry) { $ext_ids[] = 'sg:'.$sgEntry['id']; } - $event->episodes()->whereNotIn('ext_id', $ext_ids)->delete(); + $to_purge = $event->episodes() + ->where('start', '>=', $from) + ->where('start', '<=', $to) + ->whereNotIn('ext_id', $ext_ids); + foreach ($to_purge->get() as $episode) { + $episode->players()->delete(); + } + $to_purge->delete(); } private function syncSchedule(Event $event, $sgEntry) {