From: Daniel Karbach Date: Sun, 19 Feb 2023 17:11:26 +0000 (+0100) Subject: properly purge episodes X-Git-Url: https://git.localhorst.tv/?a=commitdiff_plain;h=11e76fc2410dc26cd9c19cac4117d36ce3212523;p=alttp.git properly purge episodes --- 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) {