Report correct row number in import error logs

This fixes an issue where the row number reported by import error logs would be off by 1 or 2 depending on whether the first row was labelled as titles or not.

As arrays start at 0 in PHP, `$firstRowTitles = false` would result in reported row numbers being off by one less than their actual number. If `$firstRowTitles = true`, the reported row number would be off by two less than their actual number (one for the zero index, one for the first row not existing in the `$results` set).
This commit is contained in:
Luke Towers 2017-09-15 17:05:46 -06:00 committed by GitHub
parent fa2c536a53
commit 510071550a
1 changed files with 10 additions and 0 deletions

View File

@ -146,6 +146,16 @@ abstract class ImportModel extends Model
foreach ($contents as $row) {
$result[] = $this->processImportRow($row, $matches);
}
// Offset the array index in order to have the correct row index in error logs
if ($options['firstRowTitles']) {
array_unshift($result, [], []);
unset($result[0]);
unset($result[1]);
} else {
array_unshift($result, []);
unset($result[0]);
}
return $result;
}