Another importer fix. (#5383)

* Fix condition where matching user fails when providing a username but no full name.  Also shortcircuit username matching if a user exists.

* Simplify Logic

If the user provided is numeric, but doesn't exist in the database, assume that the user's name is a number and go through all relevant generation.  of email/first+last names.  Alternatively we may want to abort or remove the is_numeric bits.. it seems a little counterintuitive
This commit is contained in:
Daniel Meltzer 2018-04-18 10:58:26 -04:00 committed by snipe
parent 5948a0b235
commit 7b72dde222

View file

@ -247,6 +247,18 @@ abstract class Importer
$user_username = $this->findCsvMatch($row, "username"); $user_username = $this->findCsvMatch($row, "username");
$first_name = ''; $first_name = '';
$last_name = ''; $last_name = '';
if(empty($user_name) && empty($user_email) && empty($user_username)) {
$this->log('No user data provided - skipping user creation, just adding asset');
//$user_username = '';
return false;
}
// A username was given.
if( !empty($user_username)) {
$user = User::where('username', $user_username)->first();
if($user) {
return $user;
}
}
// A number was given instead of a name // A number was given instead of a name
if (is_numeric($user_name)) { if (is_numeric($user_name)) {
$this->log('User '.$user_name.' is not a name - assume this user already exists'); $this->log('User '.$user_name.' is not a name - assume this user already exists');
@ -255,28 +267,24 @@ abstract class Importer
return $user; return $user;
} }
$this->log('User with id'.$user_name.' does not exist. Continuing through our processes'); $this->log('User with id'.$user_name.' does not exist. Continuing through our processes');
} elseif (empty($user_name)) { }
$this->log('No user data provided - skipping user creation, just adding asset'); // Generate data based on user name.
//$user_username = ''; $user_email_array = User::generateFormattedNameFromFullName(Setting::getSettings()->email_format, $user_name);
return false; $first_name = $user_email_array['first_name'];
} else { $last_name = $user_email_array['last_name'];
$user_email_array = User::generateFormattedNameFromFullName(Setting::getSettings()->email_format, $user_name);
$first_name = $user_email_array['first_name'];
$last_name = $user_email_array['last_name'];
if ($user_email=='') { if (empty($user_email)) {
if (Setting::getSettings()->email_domain) { if (Setting::getSettings()->email_domain) {
$user_email = str_slug($user_email_array['username']).'@'.Setting::getSettings()->email_domain; $user_email = str_slug($user_email_array['username']).'@'.Setting::getSettings()->email_domain;
}
} }
}
if ($user_username=='') { if (empty($user_username)) {
if ($this->usernameFormat =='email') { if ($this->usernameFormat =='email') {
$user_username = $user_email; $user_username = $user_email;
} else { } else {
$user_name_array = User::generateFormattedNameFromFullName(Setting::getSettings()->username_format, $user_name); $user_name_array = User::generateFormattedNameFromFullName(Setting::getSettings()->username_format, $user_name);
$user_username = $user_name_array['username']; $user_username = $user_name_array['username'];
}
} }
} }
$user = new User; $user = new User;