function smart_ip_cron in Smart IP 7
Same name and namespace in other branches
- 8.4 smart_ip.module \smart_ip_cron()
- 8.2 smart_ip.module \smart_ip_cron()
- 8.3 smart_ip.module \smart_ip_cron()
- 6.2 smart_ip.module \smart_ip_cron()
- 6 smart_ip.module \smart_ip_cron()
- 7.2 smart_ip.module \smart_ip_cron()
Implements hook_cron().
Updates the Smart IP database automatically on one month periodic basis.
File
- ./
smart_ip.module, line 113 - Determines country, geo location (longitude/latitude), region, city and postal code of the user, based on IP address
Code
function smart_ip_cron() {
$time = time();
if (variable_get('smart_ip_db_update_busy_timeout', 0) <= $time - 3600 && variable_get('smart_ip_db_update_busy', FALSE)) {
// Reset busy flag after 1 hour
variable_set('smart_ip_db_update_busy', FALSE);
}
if (variable_get('smart_ip_auto_update', TRUE) && !variable_get('smart_ip_db_update_busy', FALSE)) {
// One month and interval. Maxmind updates every first day of a month.
if (variable_get('smart_ip_last_update', 0) <= $time - 2678400) {
global $base_root;
if (!variable_get('smart_ip_extract_zip_done', FALSE) && !variable_get('smart_ip_get_zip_done', FALSE)) {
// Set an indicator that Smart IP database update has been started by cron
variable_set('smart_ip_db_update_busy', TRUE);
variable_set('smart_ip_db_update_busy_timeout', $time);
}
$options = array(
'headers' => array(
'Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8',
),
'method' => 'POST',
'data' => 'smart_ip_cron_key=' . rawurlencode(trim(variable_get('cron_key', 'drupal'))),
'timeout' => 30,
);
drupal_http_request($base_root . '/?q=smart_ip_batch', $options);
}
}
}