From 510071550a0f1b564d16b28922e9ef5f8c10d4a9 Mon Sep 17 00:00:00 2001 From: Luke Towers Date: Fri, 15 Sep 2017 17:05:46 -0600 Subject: [PATCH] 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). --- modules/backend/models/ImportModel.php | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/modules/backend/models/ImportModel.php b/modules/backend/models/ImportModel.php index 55f6512ad..334734d2f 100644 --- a/modules/backend/models/ImportModel.php +++ b/modules/backend/models/ImportModel.php @@ -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; }