@@ -27,6 +27,11 @@ class Validate extends ImportResultController implements HttpPostActionInterface
2727 */
2828 private $ import ;
2929
30+ /**
31+ * @var Import
32+ */
33+ private $ _validateRowError = false ;
34+
3035 /**
3136 * Validate uploaded files action
3237 *
@@ -80,11 +85,11 @@ private function processValidationResult($validationResult, $resultBlock)
8085 {
8186 $ import = $ this ->getImport ();
8287 $ errorAggregator = $ import ->getErrorAggregator ();
83-
8488 if ($ import ->getProcessedRowsCount ()) {
8589 if ($ validationResult ) {
8690 $ totalError = $ errorAggregator ->getErrorsCount ();
87- $ totalRows = $ import ->getProcessedRowsCount () + $ errorAggregator ->getInvalidRowsCount ();
91+ $ totalRows = $ import ->getProcessedRowsCount ();
92+ $ this ->validateRowError ($ errorAggregator , $ totalRows );
8893 $ this ->addMessageForValidResult ($ resultBlock , $ totalError , $ totalRows );
8994 } else {
9095 $ resultBlock ->addError (
@@ -115,6 +120,24 @@ private function processValidationResult($validationResult, $resultBlock)
115120 }
116121 }
117122
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+
118141 /**
119142 * Provides import model.
120143 *
@@ -163,7 +186,7 @@ private function addMessageToSkipErrors(Result $resultBlock)
163186 */
164187 private function addMessageForValidResult (Result $ resultBlock , $ totalError , $ totalRows )
165188 {
166- if ($ this ->getImport ()->isImportAllowed () && $ totalRows >= $ totalError ) {
189+ if ($ this ->getImport ()->isImportAllowed () && ( $ totalRows > $ totalError || $ this -> _validateRowError ) ) {
167190 $ resultBlock ->addSuccess (__ ('File is valid! To start import process press "Import" button ' ), true );
168191 } else {
169192 $ resultBlock ->addError (__ ('The file is valid, but we can \'t import it for some reason. ' ));
0 commit comments