@@ -27,6 +27,11 @@ class Validate extends ImportResultController implements HttpPostActionInterface
27
27
*/
28
28
private $ import ;
29
29
30
+ /**
31
+ * @var Import
32
+ */
33
+ private $ _validateRowError = false ;
34
+
30
35
/**
31
36
* Validate uploaded files action
32
37
*
@@ -80,11 +85,11 @@ private function processValidationResult($validationResult, $resultBlock)
80
85
{
81
86
$ import = $ this ->getImport ();
82
87
$ errorAggregator = $ import ->getErrorAggregator ();
83
-
84
88
if ($ import ->getProcessedRowsCount ()) {
85
89
if ($ validationResult ) {
86
90
$ totalError = $ errorAggregator ->getErrorsCount ();
87
- $ totalRows = $ import ->getProcessedRowsCount () + $ errorAggregator ->getInvalidRowsCount ();
91
+ $ totalRows = $ import ->getProcessedRowsCount ();
92
+ $ this ->validateRowError ($ errorAggregator , $ totalRows );
88
93
$ this ->addMessageForValidResult ($ resultBlock , $ totalError , $ totalRows );
89
94
} else {
90
95
$ resultBlock ->addError (
@@ -115,6 +120,24 @@ private function processValidationResult($validationResult, $resultBlock)
115
120
}
116
121
}
117
122
123
+ /**
124
+ * Validate row error.
125
+ *
126
+ * @param $errorAggregator
127
+ * @param $totalRows
128
+ * @return bool
129
+ */
130
+ private function validateRowError ($ errorAggregator , $ totalRows ): bool
131
+ {
132
+ $ errors = $ errorAggregator ->getAllErrors ();
133
+ $ rowNumber = [];
134
+ foreach ($ errors as $ error ) {
135
+ $ rowNumber = array_unique ([...$ rowNumber , ...[$ error ->getRowNumber ()]]);
136
+ }
137
+ (count ($ rowNumber ) < $ totalRows )? $ this ->_validateRowError = true : $ this ->_validateRowError = false ;
138
+ return $ this ->_validateRowError ;
139
+ }
140
+
118
141
/**
119
142
* Provides import model.
120
143
*
@@ -163,7 +186,7 @@ private function addMessageToSkipErrors(Result $resultBlock)
163
186
*/
164
187
private function addMessageForValidResult (Result $ resultBlock , $ totalError , $ totalRows )
165
188
{
166
- if ($ this ->getImport ()->isImportAllowed () && $ totalRows >= $ totalError ) {
189
+ if ($ this ->getImport ()->isImportAllowed () && ( $ totalRows > $ totalError || $ this -> _validateRowError ) ) {
167
190
$ resultBlock ->addSuccess (__ ('File is valid! To start import process press "Import" button ' ), true );
168
191
} else {
169
192
$ resultBlock ->addError (__ ('The file is valid, but we can \'t import it for some reason. ' ));
0 commit comments