From 125e2c25c69743e28a57f21682231f6e85507c46 Mon Sep 17 00:00:00 2001 From: Tim Weisenberger Date: Wed, 23 Oct 2024 15:55:27 +0200 Subject: [PATCH] fix: Ensure geocoding address and the need for geocoding is correctly determined --- Classes/Service/GeoCoder.php | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/Classes/Service/GeoCoder.php b/Classes/Service/GeoCoder.php index 550bb57..68bfcbc 100644 --- a/Classes/Service/GeoCoder.php +++ b/Classes/Service/GeoCoder.php @@ -34,13 +34,36 @@ public function __construct( public function getGeoCodingAddress(array $tcaRecord): string { - return $tcaRecord[$this->fieldMap->addressToGeocode] ?? $tcaRecord[$this->fieldMap->addressToDisplay] ?? ''; + if ( + array_key_exists($this->fieldMap->addressToGeocode, $tcaRecord) && + $tcaRecord[$this->fieldMap->addressToGeocode] !== '' + ) { + return $tcaRecord[$this->fieldMap->addressToGeocode]; + } + + if ( + array_key_exists($this->fieldMap->addressToDisplay, $tcaRecord) && + $tcaRecord[$this->fieldMap->addressToDisplay] !== '' + ) { + return $tcaRecord[$this->fieldMap->addressToDisplay]; + } + + return ''; } public function needsToBeGeoCoded(array $tcaRecord): bool { - return (!($tcaRecord[$this->fieldMap->latitude] ?? false) && !($tcaRecord[$this->fieldMap->longitude] ?? false)) - || (($tcaRecord[$this->fieldMap->probability] ?? PHP_INT_MAX) > $this->probabilityThreshold); + $hasLatitude = array_key_exists($this->fieldMap->latitude, $tcaRecord) + && $tcaRecord[$this->fieldMap->latitude] !== ''; + + $hasLongitude = array_key_exists($this->fieldMap->longitude, $tcaRecord) + && $tcaRecord[$this->fieldMap->longitude] !== ''; + + $probability = array_key_exists($this->fieldMap->probability, $tcaRecord) + ? ($tcaRecord[$this->fieldMap->probability] ?: 0) + : 0; + + return (!$hasLatitude && !$hasLongitude) || ($probability > $this->probabilityThreshold); } public function setProbabilityToManually(array $tcaRecord): array