public function Ip2CountryController::updateDatabaseAction in IP-based Determination of a Visitor's Country 8
AJAX callback to update the IP to Country database.
Parameters
string $rir: String with name of IP registry. One of 'afrinic', 'arin', 'lacnic', 'ripe'. Not case sensitive.
Return value
string JSON object for display by jQuery script.
1 string reference to 'Ip2CountryController::updateDatabaseAction'
File
- src/
Controller/ Ip2CountryController.php, line 87
Class
- Ip2CountryController
- Controller routines for user routes.
Namespace
Drupal\ip2country\ControllerCode
public function updateDatabaseAction($rir) {
$ip2country_config = $this
->config('ip2country.settings');
$watchdog = $ip2country_config
->get('watchdog');
$md5_checksum = $ip2country_config
->get('md5_checksum');
$batch_size = $ip2country_config
->get('batch_size');
// Update DB from RIR.
$status = $this->ip2countryManager
->updateDatabase($rir, $md5_checksum, $batch_size);
if ($status != FALSE) {
if ($watchdog) {
$this->logger
->get('ip2country')
->notice('Manual database update from @registry server.', [
'@registry' => mb_strtoupper($rir),
]);
}
print Json::encode([
'count' => $this
->t('@rows rows affected.', [
'@rows' => $this->ip2countryManager
->getRowCount(),
]),
'server' => $rir,
'message' => $this
->t('The IP to Country database has been updated from @server.', [
'@server' => mb_strtoupper($rir),
]),
]);
}
else {
if ($watchdog) {
$this->logger
->get('ip2country')
->notice('Manual database update from @registry server FAILED.', [
'@registry' => mb_strtoupper($rir),
]);
}
print Json::encode([
'count' => $this
->t('@rows rows affected.', [
'@rows' => 0,
]),
'server' => $rir,
'message' => $this
->t('The IP to Country database update failed.'),
]);
}
exit;
}