You are here

public static function SmartIp::updateUserLocation in Smart IP 8.2

Same name and namespace in other branches
  1. 8.4 src/SmartIp.php \Drupal\smart_ip\SmartIp::updateUserLocation()
  2. 8.3 src/SmartIp.php \Drupal\smart_ip\SmartIp::updateUserLocation()

Update user's location only if the IP address stored in session is not the same as the IP address detected by the server.

2 calls to SmartIp::updateUserLocation()
GeolocateUserSubscriber::GeolocateUser in src/EventSubscriber/GeolocateUserSubscriber.php
Initiate user geolocation.
SmartIpLocation::getData in src/SmartIpLocation.php
Gets all the Smart IP location data.

File

src/SmartIp.php, line 109
Contains \Drupal\smart_ip\SmartIp.

Class

SmartIp
Smart IP static basic methods wrapper.

Namespace

Drupal\smart_ip

Code

public static function updateUserLocation() {
  $debug = \Drupal::config('smart_ip.settings')
    ->get('debug_mode');
  if (!$debug) {
    $ip = \Drupal::request()
      ->getClientIp();
    $smartIpSession = self::getSession('smart_ip');
    if (!isset($smartIpSession['location']['ipAddress']) || $smartIpSession['location']['ipAddress'] != $ip) {
      $result = self::query();
      self::userLocationFallback($result);

      /** @var \Drupal\smart_ip\SmartIpLocation $location */
      $location = \Drupal::service('smart_ip.smart_ip_location');
      $location
        ->setData($result);
      $location
        ->save();
    }
  }
}