You are here

function ip_geoloc_diagnose in IP Geolocation Views & Maps 7

Report on the configuration status.

Reports in particular to the system access log, which is required for visitor views and maps.

Return value

int -1, if there's a problem, otherwise a count of IP addresses not stored

1 call to ip_geoloc_diagnose()
ip_geoloc_admin_configure in ./ip_geoloc.admin.inc
Menu callback for admin settings.

File

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

Code

function ip_geoloc_diagnose() {
  $geoloc_count = db_query('SELECT COUNT(DISTINCT ip_address) FROM {ip_geoloc}')
    ->fetchField();
  drupal_set_message(t("The IP geolocation database currently contains information for %geoloc_count visited IP addresses.", array(
    '%geoloc_count' => $geoloc_count,
  )), 'status', FALSE);
  if (!db_table_exists('accesslog')) {
    drupal_set_message(t("The <strong>accesslog</strong> database table does not exist, probably because core's <strong>Statistics</strong> module is not enabled. Views and maps of visitors will not be available until you enable the <strong>Statistics</strong> module and its <strong>access log</strong>. The visitor location map blocks are not affected and should still display."), 'warning');
  }
  elseif (!module_exists('statistics')) {
    drupal_set_message(t('The <strong>Statistics</strong> module is not enabled. Views and maps of visitors will not be available or display errors until you enable the <strong>Statistics</strong> module and its <strong>access log</strong>. The visitor location map blocks are not affected and should still display.'), 'warning');
  }
  else {
    $ip_address_count = db_query('SELECT COUNT(DISTINCT hostname) FROM {accesslog}')
      ->fetchField();
    drupal_set_message(t("The system access log currently contains entries from %ip_address_count IP addresses.", array(
      '%ip_address_count' => $ip_address_count,
    )), 'status', FALSE);
    if (!variable_get('statistics_enable_access_log', FALSE)) {
      drupal_set_message(t('The <strong>Statistics</strong> module is enabled, but its system <strong>access log</strong> is not. Therefore all visitor Views are frozen and will not grow. The visitor location map blocks are not affected and should still display. You can enable the <strong>access log</strong> at <a href="!url">Configuration >> Statistics</a>.', array(
        '!url' => url('admin/config/system/statistics'),
      )), 'warning');
    }
    else {
      $non_synched_ips = ip_geoloc_ips_to_be_synched();
      $count = count($non_synched_ips);
      if ($count > 0) {
        $t = t("%count IP addresses in the system access log currently have no associated lat/long or address information on the IP geolocation database. These are the most recent ones: %ips", array(
          '%count' => $count,
          '%ips' => implode(', ', array_slice($non_synched_ips, 0, 10, TRUE)),
        ));
        drupal_set_message($t, 'status', FALSE);
      }
      else {
        drupal_set_message(t("The IP geolocation database is up to date and in sync with the system access log."), 'status', FALSE);
      }
      return $count;
    }
  }
  return -1;
}