You are here

public function SmartIpEventSubscriber::cronRun in Smart IP 8.3

Same name in this branch
  1. 8.3 modules/device_geolocation/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\device_geolocation\EventSubscriber\SmartIpEventSubscriber::cronRun()
  2. 8.3 modules/smart_ip_maxmind_geoip2_bin_db/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_maxmind_geoip2_bin_db\EventSubscriber\SmartIpEventSubscriber::cronRun()
  3. 8.3 modules/smart_ip_ipinfodb_web_service/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_ipinfodb_web_service\EventSubscriber\SmartIpEventSubscriber::cronRun()
  4. 8.3 modules/smart_ip_ip2location_bin_db/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_ip2location_bin_db\EventSubscriber\SmartIpEventSubscriber::cronRun()
  5. 8.3 modules/smart_ip_abstract_web_service/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_abstract_web_service\EventSubscriber\SmartIpEventSubscriber::cronRun()
  6. 8.3 modules/smart_ip_maxmind_geoip2_web_service/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_maxmind_geoip2_web_service\EventSubscriber\SmartIpEventSubscriber::cronRun()
Same name and namespace in other branches
  1. 8.4 modules/smart_ip_ip2location_bin_db/src/EventSubscriber/SmartIpEventSubscriber.php \Drupal\smart_ip_ip2location_bin_db\EventSubscriber\SmartIpEventSubscriber::cronRun()

Act on Drupal cron run.

Parameters

\Drupal\smart_ip\DatabaseFileEvent $event: Smart IP database file related events for event listeners.

Overrides SmartIpDataSourceInterface::cronRun

File

modules/smart_ip_ip2location_bin_db/src/EventSubscriber/SmartIpEventSubscriber.php, line 508
Contains \Drupal\smart_ip_ip2location_bin_db\EventSubscriber\SmartIpEventSubscriber.

Class

SmartIpEventSubscriber
Core functionality of this Smart IP data source module. Listens to Smart IP override events.

Namespace

Drupal\smart_ip_ip2location_bin_db\EventSubscriber

Code

public function cronRun(DatabaseFileEvent $event) {
  $dataSource = \Drupal::config('smart_ip.settings')
    ->get('data_source');
  if ($dataSource == self::sourceId()) {
    $config = \Drupal::config(SmartIpEventSubscriber::configName());
    $autoUpdate = $config
      ->get('db_auto_update');
    $ipVersion = \Drupal::state()
      ->get('smart_ip_ip2location_bin_db.current_ip_version_queue');
    $lastUpdateTime = \Drupal::state()
      ->get('smart_ip_ip2location_bin_db.last_update_time') ?: 0;
    if ($ipVersion || DatabaseFileUtility::needsUpdate($lastUpdateTime, $autoUpdate, DatabaseFileUtility::DOWNLOAD_MONTHLY)) {
      if (empty($ipVersion)) {

        // Update IPv4 IP2Location binary database first
        $ipVersion = Ip2locationBinDb::IPV4_VERSION;
        \Drupal::state()
          ->set('smart_ip_ip2location_bin_db.current_ip_version_queue', $ipVersion);
      }
      DatabaseFileUtility::downloadDatabaseFile($ipVersion);
    }
  }
}