You are here

public static function DatabaseFileUtilityBase::needsUpdate in Smart IP 8.2

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

Checks if Smart IP's data source module's database file needs update.

Parameters

bool $autoUpdate:

int $frequency:

Return value

bool

Overrides DatabaseFileUtilityInterface::needsUpdate

File

src/DatabaseFileUtilityBase.php, line 76
Contains \Drupal\smart_ip\DatabaseFileUtilityBase.

Class

DatabaseFileUtilityBase
Database file utility methods class wrapper.

Namespace

Drupal\smart_ip

Code

public static function needsUpdate($autoUpdate = TRUE, $frequency = self::DOWNLOAD_MONTHLY) {
  if ($autoUpdate) {
    $timeNow = strtotime('midnight', REQUEST_TIME);
    $lastUpdateTime = \Drupal::state()
      ->get('smart_ip_maxmind_geoip2_bin_db.last_update_time') ?: 0;
    $lastUpdateTime = strtotime('midnight', $lastUpdateTime);
    if ($frequency == self::DOWNLOAD_WEEKLY) {
      $wednesday = strtotime('first Wednesday', $timeNow);
      if ($wednesday <= $timeNow && $wednesday > $lastUpdateTime) {
        return TRUE;
      }
    }
    elseif ($frequency == self::DOWNLOAD_MONTHLY) {
      $firstWed = strtotime('first Wednesday of this month', $timeNow);
      if ($firstWed <= $timeNow && $firstWed > $lastUpdateTime) {
        return TRUE;
      }
    }
  }
  return FALSE;
}