From f355a6e9e12e28978dcfa3bf406015c5854a2100 Mon Sep 17 00:00:00 2001 From: snipe Date: Tue, 23 May 2023 19:21:31 -0700 Subject: [PATCH] Added first name and last name Signed-off-by: snipe --- app/Importer/Importer.php | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/app/Importer/Importer.php b/app/Importer/Importer.php index fa2cd08d8f..59d583df97 100644 --- a/app/Importer/Importer.php +++ b/app/Importer/Importer.php @@ -242,6 +242,8 @@ abstract class Importer $user_array = [ 'full_name' => $this->findCsvMatch($row, 'full_name'), + 'first_name' => $this->findCsvMatch($row, 'first_name'), + 'last_name' => $this->findCsvMatch($row, 'last_name'), 'email' => $this->findCsvMatch($row, 'email'), 'manager_id'=> '', 'department_id' => '', @@ -249,8 +251,7 @@ abstract class Importer 'activated' => $this->fetchHumanBoolean($this->findCsvMatch($row, 'activated')), 'remote' => $this->fetchHumanBoolean(($this->findCsvMatch($row, 'remote'))), ]; - - + if ($type == 'manager') { $user_array['full_name'] = $this->findCsvMatch($row, 'manager'); $user_array['username'] = $this->findCsvMatch($row, 'manager_username'); @@ -266,8 +267,9 @@ abstract class Importer // If the full name and username is empty, bail out--we need this to extract first name (at the very least) - if ((empty($user_array['username'])) && (empty($user_array['full_name']))) { - $this->log('Insufficient user data provided (Full name or username is required) - skipping user creation.'); + if ((empty($user_array['username'])) && (empty($user_array['full_name'])) && (empty($user_array['first_name']))) { + $this->log('Insufficient user data provided (Full name, first name or username is required) - skipping user creation.'); + \Log::debug('User array: '); \Log::debug(print_r($user_array, true)); \Log::debug(print_r($row, true)); return false; @@ -279,10 +281,12 @@ abstract class Importer $user_array['email'] = User::generateEmailFromFullName($user_array['full_name']); } - // Get some fields for first name and last name based off of full name - $user_formatted_array = User::generateFormattedNameFromFullName($user_array['full_name'], Setting::getSettings()->username_format); - $user_array['first_name'] = $user_formatted_array['first_name']; - $user_array['last_name'] = $user_formatted_array['last_name']; + if (empty($user_array['first_name'])) { + // Get some fields for first name and last name based off of full name + $user_formatted_array = User::generateFormattedNameFromFullName($user_array['full_name'], Setting::getSettings()->username_format); + $user_array['first_name'] = $user_formatted_array['first_name']; + $user_array['last_name'] = $user_formatted_array['last_name']; + } if (empty($user_array['username'])) { $user_array['username'] = $user_formatted_array['username'];