diff options
author | benakamoorthi <benaka.moorthi@gmail.com> | 2012-10-13 20:39:10 +0400 |
---|---|---|
committer | benakamoorthi <benaka.moorthi@gmail.com> | 2012-10-13 20:39:10 +0400 |
commit | e216cc7eedecb208624a9d10811a2865d1de076f (patch) | |
tree | cc0d21ceeb5b35c2dd827cd90e9cf633d8a02db4 /plugins/UserCountry | |
parent | 1001bc057e487871e5a066b72768296cb89468df (diff) |
Refs #1823, test GeoIP w/ normal tracking, bulk tracking & log importing. Test if Apache module is working using GEOIP_ADDR server variable instead of GEOIP_COUNTRY_CODE since the latter may not always be set.
git-svn-id: http://dev.piwik.org/svn/trunk@7180 59fd770c-687e-43c8-a1e3-f5a4ff64c105
Diffstat (limited to 'plugins/UserCountry')
-rwxr-xr-x | plugins/UserCountry/LocationProvider.php | 3 | ||||
-rwxr-xr-x | plugins/UserCountry/LocationProvider/GeoIp.php | 5 | ||||
-rwxr-xr-x | plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php | 38 |
3 files changed, 17 insertions, 29 deletions
diff --git a/plugins/UserCountry/LocationProvider.php b/plugins/UserCountry/LocationProvider.php index 8ead0e9f5c..34124f0d23 100755 --- a/plugins/UserCountry/LocationProvider.php +++ b/plugins/UserCountry/LocationProvider.php @@ -290,7 +290,8 @@ abstract class Piwik_UserCountry_LocationProvider $provider = self::getProviderById($providerId); if ($provider === false) { - throw new Exception("Invalid provider ID '$providerId'."); + throw new Exception( + "Invalid provider ID '$providerId'. The provider either does not exist or is not available"); } Piwik_SetOption(self::CURRENT_PROVIDER_OPTION_NAME, $providerId); return $provider; diff --git a/plugins/UserCountry/LocationProvider/GeoIp.php b/plugins/UserCountry/LocationProvider/GeoIp.php index c08e463510..9c2d49a476 100755 --- a/plugins/UserCountry/LocationProvider/GeoIp.php +++ b/plugins/UserCountry/LocationProvider/GeoIp.php @@ -17,7 +17,7 @@ */ abstract class Piwik_UserCountry_LocationProvider_GeoIp extends Piwik_UserCountry_LocationProvider { - const GEOIP_DATABASE_DIR = 'misc'; + public static $geoIPDatabaseDir = 'misc'; /** * Stores possible database file names categorized by the type of information @@ -176,9 +176,10 @@ abstract class Piwik_UserCountry_LocationProvider_GeoIp extends Piwik_UserCountr */ public static function getPathToGeoIpDatabase( $possibleFileNames ) { + $dir = PIWIK_INCLUDE_PATH.'/'.self::$geoIPDatabaseDir; foreach ($possibleFileNames as $filename) { - $path = PIWIK_INCLUDE_PATH.'/'.self::GEOIP_DATABASE_DIR.'/'.$filename; + $path = $dir.'/'.$filename; if (file_exists($path)) { return $path; diff --git a/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php b/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php index 116e12e942..d39aba6756 100755 --- a/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php +++ b/plugins/UserCountry/LocationProvider/GeoIp/ServerBased.php @@ -13,7 +13,7 @@ /** * A LocationProvider that uses an GeoIP module installed in an HTTP Server. * - * To make this provider available, make sure the GEOIP_COUNTRY_CODE server + * To make this provider available, make sure the GEOIP_ADDR server * variable is set. * * @package Piwik_UserCountry @@ -22,6 +22,7 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou { const ID = 'geoip_serverbased'; const TITLE = 'GeoIP (%s)'; + const TEST_SERVER_VAR = 'GEOIP_ADDR'; private static $geoIpServerVars = array( parent::COUNTRY_CODE_KEY => 'GEOIP_COUNTRY_CODE', @@ -98,15 +99,9 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou * Returns an array describing the types of location information this provider will * return. * - * What this provider supports is dependent on how it is configured. We can't tell - * what databases a server module has access to, so we rely on which $_SERVER - * variables are available. If GEOIP_ISP is available, then we assume we can return - * this information. - * - * Since it's an error if GEOIP_COUNTRY_CODE is not available, we assume country - * info is always supported. - * - * Getting continent info is not dependent on GeoIP, so it is always supported. + * There's no way to tell exactly what database the HTTP server is using, so we just + * assume country and continent information is available. This can make diagnostics + * a bit more difficult, unfortunately. * * @return array */ @@ -114,15 +109,6 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou { $result = array(); - // set supported info based on what $_SERVER variables are available - foreach (self::$geoIpServerVars as $locKey => $serverVarName) - { - if (isset($_SERVER[$serverVarName])) - { - $result[$locKey] = true; - } - } - // assume country info is always available. it's an error if it's not. $result[self::COUNTRY_CODE_KEY] = true; $result[self::COUNTRY_NAME_KEY] = true; @@ -134,7 +120,7 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou /** * Checks if an HTTP server module has been installed. It checks by looking for - * the GEOIP_COUNTRY_CODE server variable. + * the GEOIP_ADDR server variable. * * There's a special check for the Apache module, but we can't check specifically * for anything else. @@ -155,22 +141,22 @@ class Piwik_UserCountry_LocationProvider_GeoIp_ServerBased extends Piwik_UserCou } } - return !empty($_SERVER['GEOIP_COUNTRY_CODE']); + return !empty($_SERVER[self::TEST_SERVER_VAR]); } /** - * Returns true if the GEOIP_COUNTRY_CODE server variable is defined. + * Returns true if the GEOIP_ADDR server variable is defined. * - * @return true + * @return bool */ public function isWorking() { - if (empty($_SERVER['GEOIP_COUNTRY_CODE'])) + if (empty($_SERVER[self::TEST_SERVER_VAR])) { - return Piwik_Translate("UserCountry_CannotFindGeoIPServerVar", '$_SERVER GEOIP_COUNTRY_CODE'); + return Piwik_Translate("UserCountry_CannotFindGeoIPServerVar", self::TEST_SERVER_VAR.' $_SERVER'); } - return parent::isWorking(); + return true; // can't check for another IP } /** |