|
93 | 93 | ); |
94 | 94 | } |
95 | 95 |
|
96 | | - foreach ($line as $columnKey => $columnValue) { |
97 | | - if (empty($columnValue)) { |
98 | | - $columnValue = ''; |
99 | | - } |
| 96 | + foreach ($importProfileFields as $assignedFieldColumnId => $columnKey) { |
| 97 | + $columnValue = $line[$columnKey] ?? ''; |
100 | 98 |
|
101 | | - // get usf id or database column name |
102 | | - $assignedFieldColumnId = array_search($columnKey, $importProfileFields); |
103 | 99 | // remove spaces and html tags |
104 | 100 | $columnValue = trim(strip_tags($columnValue)); |
105 | 101 |
|
|
122 | 118 | } |
123 | 119 |
|
124 | 120 | // 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); |
130 | 140 | } |
131 | 141 | } |
132 | 142 |
|
|
0 commit comments