X-Git-Url: https://git.localhorst.tv/?a=blobdiff_plain;f=app%2FConsole%2FCommands%2FSyncSpeedGaming.php;h=8c74c68124428eb190237dae117f957680ceb0fe;hb=dec43db11e9433f5bfcfaa091518082559cb3169;hp=177ee1947675b67485ffa8ca1148439a94572ce0;hpb=071885a30f24b980699b337d9cdb65952f8c6c42;p=alttp.git diff --git a/app/Console/Commands/SyncSpeedGaming.php b/app/Console/Commands/SyncSpeedGaming.php index 177ee19..8c74c68 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) { @@ -86,7 +93,7 @@ class SyncSpeedGaming extends Command { } $episode->event()->associate($event); $episode->title = $sgEntry['match1']['title']; - $start = Carbon::parse($sgEntry['when']); + $start = Carbon::createFromFormat('Y-m-d\TH:i:sP', $sgEntry['when']); if ($start->ne($episode->start)) { $episode->start = $start; }