Skip to content
This repository was archived by the owner on Apr 29, 2019. It is now read-only.

Commit e131ff7

Browse files
authored
ENGCOM-3278: #75: fix stoping on errors #130
2 parents 9fbc4da + 34a2d24 commit e131ff7

File tree

6 files changed

+57
-15
lines changed

6 files changed

+57
-15
lines changed

app/code/Magento/ImportExport/Controller/Adminhtml/Import/Validate.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ private function processValidationResult($validationResult, $resultBlock)
8686
$resultBlock->addError(
8787
__('Data validation failed. Please fix the following errors and upload the file again.')
8888
);
89-
$this->addErrorMessages($resultBlock, $errorAggregator);
89+
9090
if ($errorAggregator->getErrorsCount()) {
9191
$this->addMessageToSkipErrors($resultBlock);
9292
}
@@ -100,6 +100,8 @@ private function processValidationResult($validationResult, $resultBlock)
100100
$errorAggregator->getErrorsCount()
101101
)
102102
);
103+
104+
$this->addErrorMessages($resultBlock, $errorAggregator);
103105
} else {
104106
if ($errorAggregator->getErrorsCount()) {
105107
$this->collectErrors($resultBlock);

app/code/Magento/ImportExport/Model/Import.php

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ public function getOperationResultMessages(ProcessingErrorAggregatorInterface $v
312312
{
313313
$messages = [];
314314
if ($this->getProcessedRowsCount()) {
315-
if ($validationResult->getErrorsCount()) {
315+
if ($validationResult->isErrorLimitExceeded()) {
316316
$messages[] = __('Data validation failed. Please fix the following errors and upload the file again.');
317317

318318
// errors info
@@ -630,16 +630,7 @@ public function validateSource(\Magento\ImportExport\Model\Import\AbstractSource
630630
$messages = $this->getOperationResultMessages($errorAggregator);
631631
$this->addLogComment($messages);
632632

633-
$errorsCount = $errorAggregator->getErrorsCount();
634-
$result = !$errorsCount;
635-
$validationStrategy = $this->getData(self::FIELD_NAME_VALIDATION_STRATEGY);
636-
if ($errorsCount
637-
&& $validationStrategy === ProcessingErrorAggregatorInterface::VALIDATION_STRATEGY_SKIP_ERRORS
638-
) {
639-
$this->messageManager->addWarningMessage(__('Skipped errors: %1', $errorsCount));
640-
$result = true;
641-
}
642-
633+
$result = !$errorAggregator->isErrorLimitExceeded();
643634
if ($result) {
644635
$this->addLogComment(__('Import data validation is complete.'));
645636
}

app/code/Magento/ImportExport/Model/Import/ErrorProcessing/ProcessingErrorAggregator.php

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ public function __construct(
6161
}
6262

6363
/**
64+
* Add error via code and level
65+
*
6466
* @param string $errorCode
6567
* @param string $errorLevel
6668
* @param int|null $rowNumber
@@ -96,6 +98,8 @@ public function addError(
9698
}
9799

98100
/**
101+
* Add row to be skipped during import
102+
*
99103
* @param int $rowNumber
100104
* @return $this
101105
*/
@@ -110,6 +114,8 @@ public function addRowToSkip($rowNumber)
110114
}
111115

112116
/**
117+
* Add specific row to invalid list via row number
118+
*
113119
* @param int $rowNumber
114120
* @return $this
115121
*/
@@ -126,6 +132,8 @@ protected function processInvalidRow($rowNumber)
126132
}
127133

128134
/**
135+
* Add error message template
136+
*
129137
* @param string $code
130138
* @param string $template
131139
* @return $this
@@ -138,6 +146,8 @@ public function addErrorMessageTemplate($code, $template)
138146
}
139147

140148
/**
149+
* Check if row is invalid by row number
150+
*
141151
* @param int $rowNumber
142152
* @return bool
143153
*/
@@ -147,6 +157,8 @@ public function isRowInvalid($rowNumber)
147157
}
148158

149159
/**
160+
* Get number of invalid rows
161+
*
150162
* @return int
151163
*/
152164
public function getInvalidRowsCount()
@@ -155,6 +167,8 @@ public function getInvalidRowsCount()
155167
}
156168

157169
/**
170+
* Initialize validation strategy
171+
*
158172
* @param string $validationStrategy
159173
* @param int $allowedErrorCount
160174
* @return $this
@@ -178,6 +192,8 @@ public function initValidationStrategy($validationStrategy, $allowedErrorCount =
178192
}
179193

180194
/**
195+
* Check if import has to be terminated
196+
*
181197
* @return bool
182198
*/
183199
public function hasToBeTerminated()
@@ -186,15 +202,17 @@ public function hasToBeTerminated()
186202
}
187203

188204
/**
205+
* Check if error limit has been exceeded
206+
*
189207
* @return bool
190208
*/
191209
public function isErrorLimitExceeded()
192210
{
193211
$isExceeded = false;
194-
$errorsCount = $this->getErrorsCount([ProcessingError::ERROR_LEVEL_NOT_CRITICAL]);
212+
$errorsCount = $this->getErrorsCount();
195213
if ($errorsCount > 0
196214
&& $this->validationStrategy == self::VALIDATION_STRATEGY_STOP_ON_ERROR
197-
&& $errorsCount >= $this->allowedErrorsCount
215+
&& $errorsCount > $this->allowedErrorsCount
198216
) {
199217
$isExceeded = true;
200218
}
@@ -203,6 +221,8 @@ public function isErrorLimitExceeded()
203221
}
204222

205223
/**
224+
* Check if import has a fatal error
225+
*
206226
* @return bool
207227
*/
208228
public function hasFatalExceptions()
@@ -211,6 +231,8 @@ public function hasFatalExceptions()
211231
}
212232

213233
/**
234+
* Get all errors from an import process
235+
*
214236
* @return ProcessingError[]
215237
*/
216238
public function getAllErrors()
@@ -228,6 +250,8 @@ public function getAllErrors()
228250
}
229251

230252
/**
253+
* Get a specific set of errors via codes
254+
*
231255
* @param string[] $codes
232256
* @return ProcessingError[]
233257
*/
@@ -244,6 +268,8 @@ public function getErrorsByCode(array $codes)
244268
}
245269

246270
/**
271+
* Get an error via row number
272+
*
247273
* @param int $rowNumber
248274
* @return ProcessingError[]
249275
*/
@@ -258,6 +284,8 @@ public function getErrorByRowNumber($rowNumber)
258284
}
259285

260286
/**
287+
* Get a set rows via a set of error codes
288+
*
261289
* @param array $errorCode
262290
* @param array $excludedCodes
263291
* @param bool $replaceCodeWithMessage
@@ -292,6 +320,8 @@ public function getRowsGroupedByErrorCode(
292320
}
293321

294322
/**
323+
* Get the max allowed error count
324+
*
295325
* @return int
296326
*/
297327
public function getAllowedErrorsCount()
@@ -300,6 +330,8 @@ public function getAllowedErrorsCount()
300330
}
301331

302332
/**
333+
* Get current error count
334+
*
303335
* @param string[] $errorLevels
304336
* @return int
305337
*/
@@ -318,6 +350,8 @@ public function getErrorsCount(
318350
}
319351

320352
/**
353+
* Clear the error aggregator
354+
*
321355
* @return $this
322356
*/
323357
public function clear()
@@ -331,6 +365,8 @@ public function clear()
331365
}
332366

333367
/**
368+
* Check if an error has already been added to the aggregator
369+
*
334370
* @param int $rowNum
335371
* @param string $errorCode
336372
* @param string $columnName
@@ -348,6 +384,8 @@ protected function isErrorAlreadyAdded($rowNum, $errorCode, $columnName = null)
348384
}
349385

350386
/**
387+
* Build an error message via code, message and column name
388+
*
351389
* @param string $errorCode
352390
* @param string $errorMessage
353391
* @param string $columnName
@@ -369,6 +407,8 @@ protected function getErrorMessage($errorCode, $errorMessage, $columnName)
369407
}
370408

371409
/**
410+
* Process the error statistics for a given error level
411+
*
372412
* @param string $errorLevel
373413
* @return $this
374414
*/

app/code/Magento/ImportExport/Test/Unit/Model/Import/ErrorProcessing/ProcessingErrorAggregatorTest.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,7 @@ public function testIsErrorLimitExceededTrue()
216216
*/
217217
public function testIsErrorLimitExceededFalse()
218218
{
219+
$this->model->initValidationStrategy('validation-stop-on-errors', 5);
219220
$this->model->addError('systemException');
220221
$this->model->addError('systemException', 'critical', 7, 'Some column name', 'Message', 'Description');
221222
$this->model->addError('systemException', 'critical', 4, 'Some column name', 'Message', 'Description');

dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/TestCase/ImportDataNegativeTest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<item name="entity" xsi:type="string">Advanced Pricing</item>
2020
<item name="behavior" xsi:type="string">Add/Update</item>
2121
<item name="validation_strategy" xsi:type="string">Stop on Error</item>
22-
<item name="allowed_error_count" xsi:type="string">10</item>
22+
<item name="allowed_error_count" xsi:type="string">1</item>
2323
<item name="import_field_separator" xsi:type="string">,</item>
2424
<item name="import_multiple_value_separator" xsi:type="string">,</item>
2525
<item name="import_file" xsi:type="array">

dev/tests/functional/tests/app/Magento/AdvancedPricingImportExport/Test/_files/template/pricing/advanced_incorrect.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,13 @@
1414
'tier_price' => 'text',
1515
'tier_price_value_type' => 'Fixed',
1616
],
17+
'data_1' => [
18+
'sku' => '%sku%',
19+
'tier_price_website' => "All Websites [USD]",
20+
'tier_price_customer_group' => 'ALL GROUPS',
21+
'tier_price_qty' => '3',
22+
'tier_price' => 'text',
23+
'tier_price_value_type' => 'Fixed',
24+
],
1725
],
1826
];

0 commit comments

Comments
 (0)