You are here

function login_security_update_8001 in Login Security 8

Same name and namespace in other branches
  1. 2.x login_security.install \login_security_update_8001()

Convert e-mail settings to use e-mail addresses instead of user names.

File

./login_security.install, line 55
Login Security installation routines.

Code

function login_security_update_8001() {
  $config = \Drupal::service('config.factory')
    ->getEditable('login_security.settings');

  // Get user email for user block notification.
  $user_blocked_admin_user = user_load_by_name($config
    ->get('user_blocked_email_user'));
  $user_blocked_admin_email = $user_blocked_admin_user ? $user_blocked_admin_user
    ->getEmail() : '';

  // Get user email for login activity notification.
  $login_activity_admin_user = user_load_by_name($config
    ->get('login_activity_email_user'));
  $login_activity_admin_email = $login_activity_admin_user ? $login_activity_admin_user
    ->getEmail() : '';

  // Save new config.
  $config
    ->set('user_blocked_notification_emails', $user_blocked_admin_email)
    ->set('login_activity_notification_emails', $login_activity_admin_email)
    ->clear('user_blocked_email_user')
    ->clear('login_activity_email_user')
    ->save(TRUE);
}