Skip to content

Commit db00ac1

Browse files
committed
Admin: Fix "off by one" issue with user/course export optimization - refs BT#20899
1 parent 396a1e6 commit db00ac1

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

main/admin/course_export.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,9 @@
113113
$default = $extraField->getDefaultValueByFieldId($extra['id']);
114114
$fieldValues = $extraField->getAllValuesByFieldId($extra['id']);
115115
foreach ($listToExport as $courseId => &$values) {
116+
if ($courseId === 0) {
117+
continue;
118+
}
116119
if (isset($fieldValues[$courseId])) {
117120
if (is_array($fieldValues[$courseId])) {
118121
$values['extra_'.$extra['variable']] = $fieldValues[$courseId];

main/admin/user_export.php

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,8 +132,10 @@
132132
$data = [];
133133
$extra_fields = UserManager::get_extra_fields(0, 0, 5, 'ASC', false);
134134

135+
$headers = false;
135136
if (!empty($export['addcsvheader'])) {
136137
if ($export['addcsvheader'] == '1' && ($export['file_type'] == 'csv' || $export['file_type'] == 'xls')) {
138+
$headers = true;
137139
if ($_configuration['password_encryption'] != 'none') {
138140
$data[] = [
139141
'UserId',
@@ -146,7 +148,7 @@
146148
'OfficialCode',
147149
'PhoneNumber',
148150
'RegistrationDate',
149-
'Active',
151+
'Active',
150152
'ExpirationDate',
151153
];
152154
} else {
@@ -191,6 +193,11 @@
191193
$default = $extraField->getDefaultValueByFieldId($fieldInfo[0]);
192194
$fieldValues = $extraField->getAllValuesByFieldId($fieldInfo[0]);
193195
foreach ($data as $userId => &$values) {
196+
if ($headers === true && $userId === 0) {
197+
// Avoid the header line, if any
198+
continue;
199+
}
200+
194201
if (isset($fieldValues[$userId])) {
195202
if (is_array($fieldValues[$userId])) {
196203
$values['extra_'.$fieldInfo[1]] = $fieldValues[$userId];

0 commit comments

Comments
 (0)