@@ -62,18 +62,15 @@ public function handle(CSVImportReader $reader)
62
62
&$ where_clauses
63
63
) {
64
64
65
- $ new_mismatch = Mismatch:: make ($ mismatchLine );
65
+ $ new_mismatch = $ this -> createMismatch ($ mismatchLine );
66
66
$ new_mismatches [] = $ new_mismatch ;
67
- $ mismatch_attributes = collect ($ new_mismatch ->getAttributes ());
68
- $ mismatch_attributes ->forget ('review_status ' );
69
67
$ 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 ;
74
71
}
75
- }) ;
76
-
72
+ $ where_clause [] = [ $ key , $ attribute ] ;
73
+ }
77
74
$ where_clauses [] = $ where_clause ;
78
75
});
79
76
@@ -88,17 +85,15 @@ public function handle(CSVImportReader $reader)
88
85
$ existing_mismatches = $ mismatches_per_upload_user ->get ();
89
86
90
87
foreach ($ new_mismatches as $ new_mismatch ) {
91
- $ isDuplicate = function ($ value ) use ($ new_mismatch ) {
88
+ if ( $ existing_mismatches -> doesntContain ( function ($ value ) use ($ new_mismatch ) {
92
89
$ metaAttrs = $ new_mismatch ->getAttributes ();
93
90
foreach ($ metaAttrs as $ attrKey => $ attr ) {
94
91
if ($ attrKey != 'review_status ' && $ value ->{$ attrKey } != $ attr ) {
95
92
return false ;
96
93
}
97
94
}
98
95
return true ;
99
- };
100
-
101
- if (!$ existing_mismatches ->contains ($ isDuplicate )) {
96
+ })) {
102
97
$ this ->saveMismatch ($ new_mismatch );
103
98
}
104
99
}
@@ -126,6 +121,18 @@ public function failed(Throwable $exception)
126
121
$ this ->meta ->save ();
127
122
}
128
123
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
+
129
136
/**
130
137
* Save mismatch to database
131
138
*
@@ -134,9 +141,6 @@ public function failed(Throwable $exception)
134
141
*/
135
142
private function saveMismatch ($ new_mismatch )
136
143
{
137
- if ($ new_mismatch ->type == null ) {
138
- $ new_mismatch ->type = 'statement ' ;
139
- }
140
144
// if review_status == pending -> save
141
145
$ new_mismatch ->importMeta ()->associate ($ this ->meta );
142
146
$ new_mismatch ->save ();
0 commit comments