From cc4966845cc67a8bf5dea604b8f9083d67a94648 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Thu, 10 Feb 2022 13:55:44 +1100 Subject: [PATCH] Fixes for imports --- app/Import/Providers/BaseImport.php | 20 +++++--------------- tests/Feature/Import/CSV/CsvImportTest.php | 3 ++- tests/Feature/Import/Wave/WaveTest.php | 2 +- 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/app/Import/Providers/BaseImport.php b/app/Import/Providers/BaseImport.php index 6a0e99c294..3e89bac081 100644 --- a/app/Import/Providers/BaseImport.php +++ b/app/Import/Providers/BaseImport.php @@ -148,16 +148,12 @@ class BaseImport public function ingest($data, $entity_type) { $count = 0; -nlog("record count = ".count($data)); -nlog($data); foreach ($data as $key => $record) { try { -nlog($key); -nlog($record); + $entity = $this->transformer->transform($record); -nlog($entity); /** @var \App\Http\Requests\Request $request */ $request = new $this->request_name(); @@ -178,20 +174,15 @@ nlog($entity); $this->getUserIDForRecord($entity) ) ); -nlog("saving {$entity->name}"); $entity->saveQuietly(); $count++; - nlog("entity number"); - nlog($entity->id); -nlog("after save"); - } + } catch (\Exception $ex) { -nlog("exception"); -nlog($ex->getMessage()); + if ($ex instanceof ImportException) { $message = $ex->getMessage(); @@ -200,16 +191,15 @@ nlog($ex->getMessage()); $message = 'Unknown error'; } -nlog($message); - $this->error_array[$entity_type][] = [ $entity_type => $record, 'error' => $message, ]; } - return $count; } + + return $count; } public function ingestInvoices($invoices, $invoice_number_key) diff --git a/tests/Feature/Import/CSV/CsvImportTest.php b/tests/Feature/Import/CSV/CsvImportTest.php index d295ae5b29..7b5ec9ade2 100644 --- a/tests/Feature/Import/CSV/CsvImportTest.php +++ b/tests/Feature/Import/CSV/CsvImportTest.php @@ -188,7 +188,8 @@ class CsvImportTest extends TestCase $base_transformer = new BaseTransformer($this->company); $this->assertTrue($base_transformer->hasClient('Ludwig Krajcik DVM')); - + $this->assertTrue($base_transformer->hasClient('Bradly Jaskolski Sr.')); + $client_id = $base_transformer->getClient('Ludwig Krajcik DVM', null); $c = Client::find($client_id); diff --git a/tests/Feature/Import/Wave/WaveTest.php b/tests/Feature/Import/Wave/WaveTest.php index 4cefccb5b9..bfb52f546b 100644 --- a/tests/Feature/Import/Wave/WaveTest.php +++ b/tests/Feature/Import/Wave/WaveTest.php @@ -58,7 +58,7 @@ class WaveTest extends TestCase 2 => 'contact_first_name', 3 => 'contact_last_name', 4 => 'customer_currency', - // 5 => 'account_number', + 5 => 'account_number', 6 => 'phone', 7 => 'fax', 8 => 'mobile',