Call User::generateFormattedNameFromFullName() in the UserImporter

This commit is contained in:
Ivan Nieto Vivanco 2022-05-18 13:02:44 -05:00
parent b7b21689f2
commit 32111a863b

View file

@ -3,6 +3,7 @@
namespace App\Importer;
use App\Models\Department;
use App\Models\Setting;
use App\Models\User;
use App\Notifications\WelcomeNotification;
@ -60,6 +61,13 @@ class UserImporter extends ItemImporter
if ($this->shouldUpdateField($user_department)) {
$this->item['department_id'] = $this->createOrFetchDepartment($user_department);
}
if (is_null($this->item['username']) || $this->item['username'] == "") {
$user_full_name = $this->item['first_name'] . ' ' . $this->item['last_name'];
$user_formatted_array = User::generateFormattedNameFromFullName($user_full_name, Setting::getSettings()->username_format);
$this->item['username'] = $user_formatted_array['username'];
}
$user = User::where('username', $this->item['username'])->first();
if ($user) {
if (! $this->updating) {