You are here

public static function DatabaseFileUtilityBase::needsUpdate in Smart IP 8.3

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

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

Parameters

int $lastUpdateTime: Smart IP's data source module's database file last update time.

bool $autoUpdate: Auto update flag.

int $frequency: Auto update frequency: weekly or monthly.

Return value

bool TRUE if Smart IP's data source module's database file needs update and FALSE if not.

Overrides DatabaseFileUtilityInterface::needsUpdate

File

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

Class

DatabaseFileUtilityBase
Database file utility methods class wrapper.

Namespace

Drupal\smart_ip

Code

public static function needsUpdate($lastUpdateTime, $autoUpdate = TRUE, $frequency = self::DOWNLOAD_MONTHLY) {
  if ($autoUpdate) {
    $timeNow = strtotime('midnight', \Drupal::time()
      ->getRequestTime());
    $lastUpdateTime = strtotime('midnight', $lastUpdateTime);
    if ($frequency == self::DOWNLOAD_WEEKLY) {
      $wednesday = strtotime('Wednesday this week', $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;
}