DatabaseFileUtility.php in Smart IP 8.3
File
modules/smart_ip_maxmind_geoip2_bin_db/src/DatabaseFileUtility.php
View source
<?php
namespace Drupal\smart_ip_maxmind_geoip2_bin_db;
use Drupal\smart_ip_maxmind_geoip2_bin_db\EventSubscriber\SmartIpEventSubscriber;
use Drupal\smart_ip_maxmind_geoip2_bin_db\MaxmindGeoip2BinDb;
use Drupal\smart_ip\DatabaseFileUtilityBase;
use Drupal\Component\Utility\UrlHelper;
class DatabaseFileUtility extends DatabaseFileUtilityBase {
public static function getFilename($version = MaxmindGeoip2BinDb::LITE_VERSION, $edition = MaxmindGeoip2BinDb::CITY_EDITION, $withExt = TRUE) {
if ($version == MaxmindGeoip2BinDb::LINCENSED_VERSION && $edition == MaxmindGeoip2BinDb::COUNTRY_EDITION) {
$file = MaxmindGeoip2BinDb::FILENAME_LINCENSED_COUNTRY;
}
elseif ($version == MaxmindGeoip2BinDb::LINCENSED_VERSION && $edition == MaxmindGeoip2BinDb::CITY_EDITION) {
$file = MaxmindGeoip2BinDb::FILENAME_LINCENSED_CITY;
}
elseif ($version == MaxmindGeoip2BinDb::LITE_VERSION && $edition == MaxmindGeoip2BinDb::COUNTRY_EDITION) {
$file = MaxmindGeoip2BinDb::FILENAME_LITE_COUNTRY;
}
else {
$file = MaxmindGeoip2BinDb::FILENAME_LITE_CITY;
}
if ($withExt) {
return $file . MaxmindGeoip2BinDb::FILE_EXTENSION;
}
return $file;
}
public static function downloadDatabaseFile() {
$config = \Drupal::config(SmartIpEventSubscriber::configName());
$version = $config
->get('version');
$edition = $config
->get('edition');
$sourceId = SmartIpEventSubscriber::sourceId();
$file = self::getFilename($version, $edition);
$url = '';
if ($version == MaxmindGeoip2BinDb::LINCENSED_VERSION) {
$url = MaxmindGeoip2BinDb::LINCENSED_DL_URL;
$url .= '?' . UrlHelper::buildQuery([
'license_key' => $config
->get('license_key'),
'edition_id' => self::getFilename($version, $edition, FALSE),
'suffix' => 'tar.gz',
]);
}
elseif ($version == MaxmindGeoip2BinDb::LITE_VERSION) {
$url = MaxmindGeoip2BinDb::LITE_DL_URL;
$url .= '?' . UrlHelper::buildQuery([
'account_id' => $config
->get('user_account'),
'license_key' => $config
->get('license_key'),
'edition_id' => self::getFilename($version, $edition, FALSE),
'suffix' => 'tar.gz',
]);
}
if (parent::requestDatabaseFile($url, $file, $sourceId)) {
\Drupal::state()
->set('smart_ip_maxmind_geoip2_bin_db.last_update_time', \Drupal::time()
->getRequestTime());
}
}
}