@@ -62,18 +62,15 @@ public function handle(CSVImportReader $reader)
6262 &$ where_clauses
6363 ) {
6464
65- $ new_mismatch = Mismatch:: make ($ mismatchLine );
65+ $ new_mismatch = $ this -> createMismatch ($ mismatchLine );
6666 $ new_mismatches [] = $ new_mismatch ;
67- $ mismatch_attributes = collect ($ new_mismatch ->getAttributes ());
68- $ mismatch_attributes ->forget ('review_status ' );
6967 $ where_clause = [['review_status ' , '!= ' , 'pending ' ]];
70- $ mismatch_attributes ->map (function ($ attribute , $ key ) use (&$ where_clause ) {
71- // key can be empty in the file but in the db always has statement by default
72- if ($ key != 'type ' || $ attribute != null ) {
73- $ where_clause [] = [$ key , $ attribute ];
68+ foreach ($ new_mismatch ->getAttributes () as $ key => $ attribute ) {
69+ if ($ key == 'review_status ' ) {
70+ continue ;
7471 }
75- }) ;
76-
72+ $ where_clause [] = [ $ key , $ attribute ] ;
73+ }
7774 $ where_clauses [] = $ where_clause ;
7875 });
7976
@@ -88,17 +85,15 @@ public function handle(CSVImportReader $reader)
8885 $ existing_mismatches = $ mismatches_per_upload_user ->get ();
8986
9087 foreach ($ new_mismatches as $ new_mismatch ) {
91- $ isDuplicate = function ($ value ) use ($ new_mismatch ) {
88+ if ( $ existing_mismatches -> doesntContain ( function ($ value ) use ($ new_mismatch ) {
9289 $ metaAttrs = $ new_mismatch ->getAttributes ();
9390 foreach ($ metaAttrs as $ attrKey => $ attr ) {
9491 if ($ attrKey != 'review_status ' && $ value ->{$ attrKey } != $ attr ) {
9592 return false ;
9693 }
9794 }
9895 return true ;
99- };
100-
101- if (!$ existing_mismatches ->contains ($ isDuplicate )) {
96+ })) {
10297 $ this ->saveMismatch ($ new_mismatch );
10398 }
10499 }
@@ -126,6 +121,18 @@ public function failed(Throwable $exception)
126121 $ this ->meta ->save ();
127122 }
128123
124+
125+ private function createMismatch ($ mismatch_data )
126+ {
127+ $ new_mismatch = Mismatch::make ($ mismatch_data );
128+
129+ if ($ new_mismatch ->type == null ) {
130+ $ new_mismatch ->type = 'statement ' ;
131+ }
132+
133+ return $ new_mismatch ;
134+ }
135+
129136 /**
130137 * Save mismatch to database
131138 *
@@ -134,9 +141,6 @@ public function failed(Throwable $exception)
134141 */
135142 private function saveMismatch ($ new_mismatch )
136143 {
137- if ($ new_mismatch ->type == null ) {
138- $ new_mismatch ->type = 'statement ' ;
139- }
140144 // if review_status == pending -> save
141145 $ new_mismatch ->importMeta ()->associate ($ this ->meta );
142146 $ new_mismatch ->save ();
0 commit comments