Commit 8243cd86 authored by James Scott's avatar James Scott Committed by James Scott
Browse files

Issue #3308514 by jlscott: Remove duplicate code

parent 65d2d0cc
Loading
Loading
Loading
Loading
+2 −13
Original line number Diff line number Diff line
@@ -72,19 +72,8 @@ function auto_username_user_insert($account) {
 */
function auto_username_user_update($account) {
  if (\Drupal::config('auto_username.settings')->get('aun_update_on_edit')) {
    $new_name = \Drupal::service('auto_username.utilities')->autoUsernameGenerateUsername($account);
    // No point updating anything if the generated name was just the same.
    if ($account->name == $new_name) {
      return;
    }

    // Replace with generated username.
    Database::getConnection()
      ->update('users_field_data')
      ->fields(array('name' => $new_name))
      ->condition('uid', $account->id())
      ->execute();
    $account->name = $new_name;
    // Same processing as for user insert.
    auto_username_user_insert($account);
  }
}