function ip2country_cron in IP-based Determination of a Visitor's Country 6
Same name and namespace in other branches
- 8 ip2country.module \ip2country_cron()
- 7 ip2country.module \ip2country_cron()
Implements hook_cron().
Updates the IP to Country database automatically on a periodic basis. Default period is 1 week.
File
- ./
ip2country.module, line 66 - Determination of user's Country based on IP.
Code
function ip2country_cron() {
// Utility functions for fetching and loading IP/Country DB from RIR.
module_load_include('inc', 'ip2country');
// Automatic database updates are disabled when $update_interval == 0.
$update_interval = variable_get('ip2country_update_interval', 604800);
if ($update_interval && variable_get('ip2country_last_update', 0) <= time() - $update_interval) {
$status = ip2country_update_database(variable_get('ip2country_rir', 'arin'));
// Log to watchdog if requested.
if (variable_get('ip2country_watchdog', TRUE)) {
if ($status != FALSE) {
// Success.
watchdog('ip2country', 'Database updated from @registry server. Table contains @rows rows.', array(
'@registry' => drupal_strtoupper(variable_get('ip2country_rir', 'arin')),
'@rows' => $status,
), WATCHDOG_NOTICE);
}
else {
// Failure.
watchdog('ip2country', 'Database update from @registry server FAILED.', array(
'@registry' => drupal_strtoupper(variable_get('ip2country_rir', 'arin')),
), WATCHDOG_WARNING);
}
}
}
}