You are here

function ip_geoloc_sync_with_accesslog in IP Geolocation Views & Maps 7

Bring the visitor location database up to date with the system accesslog.

Go through all the IP addresses in the {accesslog} table (Statistics module). For each IP address not yet recorded in the {ip_geoloc} table, retrieve its geolocation data and store in {ip_geoloc}. This is a one-off process. Once synchronised the {ip_geoloc} table will lock step with the {accesslog} table. Returns the number of {accesslog} records processed or FALSE if no IP geolocation retrieval function was found.

Note: modules supported for the backfill currently are: Smart IP module GeoIP API module custom modules that implement hook_get_ip_geolocation_alter().

1 string reference to 'ip_geoloc_sync_with_accesslog'
ip_geoloc_admin_configure in ./ip_geoloc.admin.inc
Menu callback for admin settings.

File

./ip_geoloc.admin.inc, line 366
Admin configuration settings for IPGV&M.

Code

function ip_geoloc_sync_with_accesslog() {

  // Wipe previous message to avoid confusion.
  drupal_get_messages();
  $use_smart_ip = variable_get('ip_geoloc_smart_ip_as_backup', FALSE) && module_exists('smart_ip');
  $use_google_to_reverse_geocode = variable_get('ip_geoloc_google_to_reverse_geocode', FALSE);

  // From Configuration >> IP Geolocation form.
  $batch_size = check_plain($_POST['ip_geoloc_sync_batch_size']);
  if (empty($batch_size)) {
    $batch_size = variable_get('ip_geoloc_sync_batch_size', 500);
  }
  $ips_to_be_processed = ip_geoloc_ips_to_be_synched();
  if (count($ips_to_be_processed) > $batch_size) {
    $ips_to_be_processed = array_slice($ips_to_be_processed, 0, $batch_size, TRUE);
  }
  $count = count($ips_to_be_processed);
  $batch = array(
    'file' => drupal_get_path('module', 'ip_geoloc') . '/ip_geoloc.admin.inc',
    'operations' => array(
      array(
        '_ip_geoloc_process_access_log',
        array(
          $ips_to_be_processed,
          $use_smart_ip,
          $use_google_to_reverse_geocode,
        ),
      ),
    ),
    'title' => t('Processing next %count IP addresses from access log', array(
      '%count' => $count,
    )),
    'progress_message' => t('Time elapsed: @elapsed. Time remaining: @estimate.'),
    'error_message' => t('An error occurred while processing the access log.'),
    'finished' => '_ip_geoloc_process_access_log_finished',
  );
  batch_set($batch);
  return $count;
}