Skip to content
Extraits de code Groupes Projets
Valider e43871cf rédigé par diosmosis's avatar diosmosis
Parcourir les fichiers

Correct floating point comparison for latitude/longitude in VisitorGeolocator...

Correct floating point comparison for latitude/longitude in VisitorGeolocator when determining visit fields to update.
parent 85077a6e
Aucune branche associée trouvée
Aucune étiquette associée trouvée
Aucune requête de fusion associée trouvée
......@@ -36,6 +36,8 @@ require_once PIWIK_INCLUDE_PATH . "/plugins/UserCountry/LocationProvider.php";
*/
class VisitorGeolocator
{
const LAT_LONG_COMPARE_EPSILON = 0.0001;
/**
* @var string[]
*/
......@@ -190,7 +192,7 @@ class VisitorGeolocator
$locationPropertyValue = $location[$locationKey];
$existingPropertyValue = $row[$column];
if ($locationPropertyValue != $existingPropertyValue) {
if (!$this->areLocationPropertiesEqual($locationKey, $locationPropertyValue, $existingPropertyValue)) {
$valuesToUpdate[$column] = $locationPropertyValue;
}
}
......@@ -213,6 +215,19 @@ class VisitorGeolocator
return $this->backupProvider;
}
private function areLocationPropertiesEqual($locationKey, $locationPropertyValue, $existingPropertyValue)
{
if (($locationKey == LocationProvider::LATITUDE_KEY
|| $locationKey == LocationProvider::LONGITUDE_KEY)
&& $existingPropertyValue != 0
) {
// floating point comparison
return abs(($locationPropertyValue - $existingPropertyValue) / $existingPropertyValue) < self::LAT_LONG_COMPARE_EPSILON;
} else {
return $locationPropertyValue == $existingPropertyValue;
}
}
private function getDefaultProvider()
{
return LocationProvider::getProviderById(DefaultProvider::ID);
......
0% Chargement en cours ou .
You are about to add 0 people to the discussion. Proceed with caution.
Terminez d'abord l'édition de ce message.
Veuillez vous inscrire ou vous pour commenter