From 9cd0234665ea66dff172d94b9c1b4cb61b1d25b1 Mon Sep 17 00:00:00 2001 From: Fbenas Date: Sun, 21 Jun 2020 17:58:23 +0100 Subject: Improve robustness of all scripts and add more to sync command --- app/Rugby/Factory/DataAdapter.php | 1 - app/Rugby/Factory/Service.php | 21 +++++++++++++++++++++ app/Rugby/Factory/SixnationsrugbyAdapter.php | 1 - 3 files changed, 21 insertions(+), 2 deletions(-) (limited to 'app/Rugby/Factory') diff --git a/app/Rugby/Factory/DataAdapter.php b/app/Rugby/Factory/DataAdapter.php index b4971ce..d0434c9 100644 --- a/app/Rugby/Factory/DataAdapter.php +++ b/app/Rugby/Factory/DataAdapter.php @@ -4,5 +4,4 @@ namespace App\Rugby\Factory; interface DataAdapter { - } diff --git a/app/Rugby/Factory/Service.php b/app/Rugby/Factory/Service.php index fa8028f..e966ce6 100644 --- a/app/Rugby/Factory/Service.php +++ b/app/Rugby/Factory/Service.php @@ -52,6 +52,27 @@ class Service $away_team = Model\Team::Create(['name' => $data['team_away']]); } + $existing_match = Model\Match::whereHas( + 'teams', + function ($query) use ($home_team) { + $query->where('name', '=', $home_team->name); + } + )->whereHas( + 'teams', + function ($query) use ($away_team) { + $query->where('name', '=', $away_team->name); + } + )->whereHas( + 'tournaments', + function ($query) use ($tournament) { + $query->where('name', '=', $tournament->name); + } + )->get(); + + if ($existing_match->first()) { + return; + } + $match = Model\Match::create( [ 'date' => (new \Carbon\Carbon($data['match_date']))->format('Y-m-d H:i:s'), diff --git a/app/Rugby/Factory/SixnationsrugbyAdapter.php b/app/Rugby/Factory/SixnationsrugbyAdapter.php index 6b6edd7..4a36602 100644 --- a/app/Rugby/Factory/SixnationsrugbyAdapter.php +++ b/app/Rugby/Factory/SixnationsrugbyAdapter.php @@ -28,7 +28,6 @@ class SixnationsrugbyAdapter implements DataAdapter return $this->tournament_name; } - protected function cleanData($data) { // string -- cgit v1.2.3