From 5b9d2d2224d4e9ba8d003808b4d432cf8495b954 Mon Sep 17 00:00:00 2001 From: asdfghjkl Date: Sat, 27 Jul 2019 14:23:37 +0300 Subject: [PATCH 1/4] Fix undefined variable --- app/Helpers/PrecinctImporter.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/app/Helpers/PrecinctImporter.php b/app/Helpers/PrecinctImporter.php index ee402c7..7421111 100644 --- a/app/Helpers/PrecinctImporter.php +++ b/app/Helpers/PrecinctImporter.php @@ -130,7 +130,9 @@ private function importPrecinctsFromArray(array $data) $precinct->save(); } } catch (QueryException $ex){ - Log::warning("Could not persist precinct \n $precinct"); + $precinctNo = isset($rawPrecinctData['precinct_no']) ? $rawPrecinctData['precinct_no'] : "missing"; + $cityId = isset($rawPrecinctData['city_id']) ? $rawPrecinctData['city_id'] : "missing"; + Log::warning("Could not persist precinct with precinct_no={$precinctNo} and city_id={$cityId}"); } } From cdf885b02faaa6304281979b4b552afab3b88af5 Mon Sep 17 00:00:00 2001 From: asdfghjkl Date: Mon, 23 Sep 2019 19:55:39 +0300 Subject: [PATCH 2/4] Skip importing precinct if it has any error --- app/Helpers/PrecinctImporter.php | 18 ++++++++++++------ database/seeds/DatabaseSeeder.php | 1 - 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/Helpers/PrecinctImporter.php b/app/Helpers/PrecinctImporter.php index 7421111..1e38622 100644 --- a/app/Helpers/PrecinctImporter.php +++ b/app/Helpers/PrecinctImporter.php @@ -117,7 +117,7 @@ private function readFromJson(SplFileObject $file) { private function importPrecinctsFromArray(array $data) { foreach ($data as $rawPrecinctData) { - try{ + try { $existingPrecinct = Precinct::where([ 'precinct_no' => $rawPrecinctData['precinct_no'], 'city_id' => $rawPrecinctData['city_id'] @@ -129,12 +129,9 @@ private function importPrecinctsFromArray(array $data) $precinct = new Precinct($rawPrecinctData); $precinct->save(); } - } catch (QueryException $ex){ - $precinctNo = isset($rawPrecinctData['precinct_no']) ? $rawPrecinctData['precinct_no'] : "missing"; - $cityId = isset($rawPrecinctData['city_id']) ? $rawPrecinctData['city_id'] : "missing"; - Log::warning("Could not persist precinct with precinct_no={$precinctNo} and city_id={$cityId}"); + } catch (\Exception $ex) { + Log::error("Could not persist precinct {$this->getArrayAsString($rawPrecinctData)}: $ex"); } - } } @@ -153,4 +150,13 @@ private function getCityId(string $cityName, string $countyCode) Log::warning("Could not find city with name $cityName and county with code $countyCode"); return 0; } + + private function getArrayAsString($array) + { + try { + return json_encode($array); + } catch (\Exception $ex) { + return 'Array with error'; + } + } } diff --git a/database/seeds/DatabaseSeeder.php b/database/seeds/DatabaseSeeder.php index 869bf88..42189fa 100644 --- a/database/seeds/DatabaseSeeder.php +++ b/database/seeds/DatabaseSeeder.php @@ -18,7 +18,6 @@ class DatabaseSeeder extends Seeder */ public function run() { - IncidentType::truncate(); Incident::truncate(); City::truncate(); From cdd962797a1742bc7fd82b8357b9b9b93cff26b3 Mon Sep 17 00:00:00 2001 From: asdfghjkl Date: Wed, 25 Sep 2019 18:58:14 +0300 Subject: [PATCH 3/4] Revert API_PREFIX value --- config/api.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/config/api.php b/config/api.php index 7151338..de3f195 100644 --- a/config/api.php +++ b/config/api.php @@ -57,7 +57,7 @@ | */ - 'prefix' => env('API_PREFIX', 'api'), + 'prefix' => env('API_PREFIX', null), /* |-------------------------------------------------------------------------- From 02ea55a6f97a22e3caa24c3c2a89d3b4a15f93d0 Mon Sep 17 00:00:00 2001 From: asdfghjkl Date: Sat, 19 Oct 2019 18:31:53 +0300 Subject: [PATCH 4/4] Remove unnecessary try-catch --- app/Helpers/PrecinctImporter.php | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/app/Helpers/PrecinctImporter.php b/app/Helpers/PrecinctImporter.php index 1e38622..8a2bbb5 100644 --- a/app/Helpers/PrecinctImporter.php +++ b/app/Helpers/PrecinctImporter.php @@ -130,7 +130,8 @@ private function importPrecinctsFromArray(array $data) $precinct->save(); } } catch (\Exception $ex) { - Log::error("Could not persist precinct {$this->getArrayAsString($rawPrecinctData)}: $ex"); + $jsonRawPrecinctData = json_encode($rawPrecinctData); + Log::error("Could not persist precinct {$jsonRawPrecinctData}: $ex"); } } } @@ -150,13 +151,4 @@ private function getCityId(string $cityName, string $countyCode) Log::warning("Could not find city with name $cityName and county with code $countyCode"); return 0; } - - private function getArrayAsString($array) - { - try { - return json_encode($array); - } catch (\Exception $ex) { - return 'Array with error'; - } - } }