From 4aae7c0b1a06e78f6f232284a87609836bf6f1e0 Mon Sep 17 00:00:00 2001 From: Joshua Dwire Date: Fri, 19 Feb 2021 19:50:17 -0500 Subject: [PATCH] Update import process to handle new data format --- app/Jobs/Import/CSVImport.php | 4 +++- tests/Feature/Import/ImportCsvTest.php | 12 ++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/app/Jobs/Import/CSVImport.php b/app/Jobs/Import/CSVImport.php index e0fc289ad8d6..392272327ee8 100644 --- a/app/Jobs/Import/CSVImport.php +++ b/app/Jobs/Import/CSVImport.php @@ -78,7 +78,9 @@ class CSVImport implements ShouldQueue { $this->hash = $request['hash']; $this->import_type = $request['import_type']; $this->skip_header = $request['skip_header'] ?? null; - $this->column_map = $request['column_map'] ?? null; + $this->column_map = + ! empty( $request['column_map'] ) ? + array_combine( array_keys( $request['column_map'] ), array_column( $request['column_map'], 'mapping' ) ) : null; } /** diff --git a/tests/Feature/Import/ImportCsvTest.php b/tests/Feature/Import/ImportCsvTest.php index ecc977940921..6f2989d6b450 100644 --- a/tests/Feature/Import/ImportCsvTest.php +++ b/tests/Feature/Import/ImportCsvTest.php @@ -74,7 +74,7 @@ class ImportCsvTest extends TestCase $data = [ 'hash' => $hash, - 'column_map' => [ 'client' => $column_map ], + 'column_map' => [ 'client' => [ 'mapping' => $column_map ] ], 'skip_header' => true, 'import_type' => 'csv', ]; @@ -113,7 +113,7 @@ class ImportCsvTest extends TestCase $data = [ 'hash' => $hash, - 'column_map' => [ 'invoice' => $column_map ], + 'column_map' => [ 'invoice' => [ 'mapping' => $column_map ] ], 'skip_header' => true, 'import_type' => 'csv', ]; @@ -141,7 +141,7 @@ class ImportCsvTest extends TestCase $data = [ 'hash' => $hash, - 'column_map' => [ 'vendor' => $column_map ], + 'column_map' => [ 'vendor' => [ 'mapping' => $column_map ] ], 'skip_header' => true, 'import_type' => 'csv', ]; @@ -166,7 +166,7 @@ class ImportCsvTest extends TestCase $data = [ 'hash' => $hash, - 'column_map' => [ 'product' => $column_map ], + 'column_map' => [ 'product' => [ 'mapping' => $column_map ] ], 'skip_header' => true, 'import_type' => 'csv', ]; @@ -191,7 +191,7 @@ class ImportCsvTest extends TestCase $data = [ 'hash' => $hash, - 'column_map' => [ 'expense' => $column_map ], + 'column_map' => [ 'expense' => [ 'mapping' => $column_map ] ], 'skip_header' => true, 'import_type' => 'csv', ]; @@ -218,7 +218,7 @@ class ImportCsvTest extends TestCase $data = [ 'hash' => $hash, - 'column_map' => [ 'payment' => $column_map ], + 'column_map' => [ 'payment' => [ 'mapping' => $column_map ] ], 'skip_header' => true, 'import_type' => 'csv', ];