Skip to content

Commit 0fbb1bf

Browse files
authored
Merge pull request #1862 from kainhofer/ContactImport
Improve/fix Contact import
2 parents e858d2f + 9d603da commit 0fbb1bf

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

languages/en.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,7 @@
344344
<string name="SYS_COLOR_SECONDARY">Secondary Color</string>
345345
<string name="SYS_COLOR_SECONDARY_DESC">The secondary color used for Admidio. The side bar will use this color, as well as the preferences sections.</string>
346346
<string name="SYS_COLUMN">Column</string>
347+
<string name="SYS_COLUMN_POS">Column #VAR1#</string>
347348
<string name="SYS_COLUMN_SELECTION">Column selection</string>
348349
<string name="SYS_COLUMN_SELECTION_DESC">Selects the columns to be displayed in the list.\n\n Inactive roles are marked with (*).</string>
349350
<string name="SYS_COMMA">Comma (,)</string>

modules/contacts/import_column_config.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,13 @@
7070
$categoryId = null;
7171
$arrayImportableFields = array();
7272

73+
// Cleanup CSV columns: If a column does not have a header (null value), use its position instead
74+
foreach ($arrayCsvColumns as $pos => $column) {
75+
if (empty($column)) {
76+
$arrayCsvColumns[$pos] = $gL10n->get('SYS_COLUMN_POS', array($pos));
77+
}
78+
}
79+
7380
$arrayImportableFields[] = array(
7481
'cat_name' => $gL10n->get('SYS_BASIC_DATA'),
7582
'cat_tooltip' => '',

modules/contacts/import_user.php

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,13 +93,9 @@
9393
);
9494
}
9595

96-
foreach ($line as $columnKey => $columnValue) {
97-
if (empty($columnValue)) {
98-
$columnValue = '';
99-
}
96+
foreach ($importProfileFields as $assignedFieldColumnId => $columnKey) {
97+
$columnValue = $line[$columnKey] ?? '';
10098

101-
// get usf id or database column name
102-
$assignedFieldColumnId = array_search($columnKey, $importProfileFields);
10399
// remove spaces and html tags
104100
$columnValue = trim(strip_tags($columnValue));
105101

@@ -122,11 +118,25 @@
122118
}
123119

124120
// add login data to the user
125-
if ($userLoginName !== '' && $userPassword !== '') {
126-
try {
127-
$userImport->setLoginData($userLoginName, $userPassword);
128-
} catch (Exception $e) {
129-
$importMessages[] = $e->getMessage();
121+
// Ideally, both username and password are set using the same import
122+
// Setting username without password is possible (user needs to reset password to be able to log in)
123+
// Setting the password only should only be possible if an existing user already has a username assigned
124+
if ($userPassword !== '') {
125+
if ($userLoginName == '') {
126+
$userLoginName = $userImport->getValue('usr_login_name');
127+
}
128+
if (!empty($userLoginName)) {
129+
try {
130+
$userImport->setLoginData($userLoginName, $userPassword);
131+
} catch (Exception $e) {
132+
$importMessages[] = $e->getMessage();
133+
}
134+
} else {
135+
$importMessages[] = $userImport->getValue('FIRST_NAME') . ' ' . $userImport->getValue('LAST_NAME') . ": password given for new user, but no username";
136+
}
137+
} else {
138+
if (!empty($userLoginName)) {
139+
$userImport->setValue('usr_login_name', $userLoginName);
130140
}
131141
}
132142

0 commit comments

Comments
 (0)