From 4686ed32d87f385f73d52794f1805f4d23c7c9bc Mon Sep 17 00:00:00 2001 From: Aleksandra Kozubal <104600942+AleksandraKozubal@users.noreply.github.com> Date: Mon, 21 Aug 2023 07:34:11 +0200 Subject: [PATCH] #120 - fix load() in DataImporter.php (#121) --- app/Importers/DataImporter.php | 27 +++++++++++------- .../2023_06_06_114212_create_cities_table.php | 2 +- public/providers/binbin.png | Bin 0 -> 1696 bytes 3 files changed, 18 insertions(+), 11 deletions(-) create mode 100644 public/providers/binbin.png diff --git a/app/Importers/DataImporter.php b/app/Importers/DataImporter.php index e705ea3a..e3f286ae 100644 --- a/app/Importers/DataImporter.php +++ b/app/Importers/DataImporter.php @@ -99,19 +99,26 @@ protected function createImportInfoDetails(string $code, string $providerName): protected function load(string $cityName, string $countryName, string $lat = "", string $long = ""): string { - $city = City::query()->where("name", $cityName)->first(); - $alternativeCityName = CityAlternativeName::query()->where("name", $cityName)->first(); + $country = Country::query()->where("name", $countryName)->orWhere("alternative_name", $countryName)->first(); - if ($city || $alternativeCityName) { - $cityId = $city ? $city->id : $alternativeCityName->city_id; + if ($country) { + $city = City::query()->where("name", $cityName)->where("country_id", $country->id)->first(); + $alternativeCityName = CityAlternativeName::query()->where("name", $cityName)->first(); - $this->createProvider($cityId, self::getProviderName()); + if ($city) { + $cityId = $city->id; + $this->createProvider($cityId, self::getProviderName()); - return strval($cityId); - } - $country = Country::query()->where("name", $countryName)->orWhere("alternative_name", $countryName)->first(); + return strval($cityId); + } elseif ($alternativeCityName) { + $cityId = $alternativeCityName->city_id; + $city = City::query()->where("id", $cityId)->first(); + + if ($city->country_id === $country->id){ + $this->createProvider($cityId, self::getProviderName()); + } + } - if ($country) { $coordinates = $this->mapboxService->getCoordinatesFromApi($cityName, $countryName); $countCoordinates = count($coordinates); @@ -128,7 +135,7 @@ protected function load(string $cityName, string $countryName, string $lat = "", $this->createProvider($city->id, self::getProviderName()); return strval($city->id); - } + } $this->countryNotFound($cityName, $countryName); $this->createImportInfoDetails("420", self::getProviderName()); diff --git a/database/migrations/2023_06_06_114212_create_cities_table.php b/database/migrations/2023_06_06_114212_create_cities_table.php index 52ffe8a9..ac05805c 100644 --- a/database/migrations/2023_06_06_114212_create_cities_table.php +++ b/database/migrations/2023_06_06_114212_create_cities_table.php @@ -17,7 +17,7 @@ public function up(): void ->on("countries") ->onDelete("cascade"); - $table->string("name")->unique(); + $table->string("name"); $table->string("latitude")->nullable(); $table->string("longitude")->nullable(); $table->timestamps(); diff --git a/public/providers/binbin.png b/public/providers/binbin.png new file mode 100644 index 0000000000000000000000000000000000000000..55756c4ce8d045dabd946753ef5ff6592e5b6dd5 GIT binary patch literal 1696 zcmV;R24DG!P)8QOsbjgVyH|gFzBlfk zd!Fz2bML<2d*>VOAD`zr&w1YGbH1N*&U2oNx-I$pD1Cr>rurlGS#^hcn>w!_x+lTq z+lifP`=ooOx-(Vh)#?+8?oH~fesG^4pS1~>2m7RZO``jd zx~L!eYnU-W-Jb%^O~w}iR}XOCDTR7Aa6>XR3;6mV_a3D4-a5&-R~i-qQJH(ietA2( z%nc84->Js-E^`C5bCAxv6ZlUuz8AQCfcs80wg4L|bKe-`#shO+L~I4F0CtZVehOF? z5zh{4->F7K908UCe;6}-2v{8vcMNjx69%a~BJNSo1>Ol91|E)xgM-|2IuH>%)WtNp z{0v}oMC=;$zCE3%&H&~Eha+NlFZmJ?aRB(;B)F9vhG+_dT@f*IEc&|a^IG5(V0T0u zn#kIS5O}l?9OeP@Xza|=&i_#ho9C!sR38Ig2A&3XsRz~Hs@JI}wIp*+=Ky=7dd38d zn5*8TK136ShJj~*L+Zoo=hWA<)mOpE>Q(A}>Px^LnnLSf=fHhyCvvpmJ6rv@x>~)Y zEde#urRrVki@-kMU%&x%yZRk9ug)un^fq`({ZJ2L7pgCeS+i4peG7xGR-bFZVUPOB zmM%nJ0;2$ z$H3uB19qM^DPvrnV3S5N%&c%JBho~$S$!4s@2IdweRDFNg_^Xlsa_0x`4~8?Qr~q9 z>)YTmU}Z913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