From c8fe1f94624f89cfcbaba82e89e12a569a7d826c Mon Sep 17 00:00:00 2001 From: Nathan Curtis Date: Thu, 12 Dec 2024 16:40:33 -0800 Subject: [PATCH] [TM-1402] Trim the headers on tree species assocations. --- app/Console/Commands/ImportTreeSpeciesAssociations.php | 3 ++- app/Console/Commands/OneOff/PopulateTreeSpeciesResearch.php | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/app/Console/Commands/ImportTreeSpeciesAssociations.php b/app/Console/Commands/ImportTreeSpeciesAssociations.php index 6371025e..d6e3aa18 100644 --- a/app/Console/Commands/ImportTreeSpeciesAssociations.php +++ b/app/Console/Commands/ImportTreeSpeciesAssociations.php @@ -87,6 +87,7 @@ public function handle() protected function parseHeaders(array $headerRow): void { foreach ($headerRow as $index => $header) { + $header = trim($header, "\xEF\xBB\xBF\""); if ($header == 'tree_species_uuid') { $this->treeSpeciesUuidColumn = $index; } elseif ($header == 'taxon_id') { @@ -95,7 +96,7 @@ protected function parseHeaders(array $headerRow): void } $this->assert( - $this->treeSpeciesUuidColumn != null && $this->taxonIdColumn != null, + is_numeric($this->treeSpeciesUuidColumn) && is_numeric($this->taxonIdColumn), 'Not all required columns were found' ); } diff --git a/app/Console/Commands/OneOff/PopulateTreeSpeciesResearch.php b/app/Console/Commands/OneOff/PopulateTreeSpeciesResearch.php index e16bdc1a..ef2b4250 100644 --- a/app/Console/Commands/OneOff/PopulateTreeSpeciesResearch.php +++ b/app/Console/Commands/OneOff/PopulateTreeSpeciesResearch.php @@ -69,7 +69,7 @@ public function handle() $existing = TreeSpeciesResearch::where('scientific_name', $data['scientific_name'])->first(); $this->assert( $existing == null, - "Scientific name already exists, skipping: " . json_encode([ + 'Scientific name already exists, skipping: ' . json_encode([ 'existing_id' => $existing?->taxon_id, 'new_id' => $data['taxon_id'], 'scientific_name' => $data['scientific_name'], @@ -85,7 +85,7 @@ public function handle() $progressBar->finish(); - if (!empty($abortExceptions)) { + if (! empty($abortExceptions)) { $this->warn("Errors and warnings encountered during parsing CSV Rows:\n"); foreach ($abortExceptions as $error) { $this->logException($error);