From 2fdb5d00b09cd330c4f4621103eaa28bf501089a Mon Sep 17 00:00:00 2001 From: Frank Schubert Date: Thu, 23 Jan 2025 15:04:52 +0100 Subject: [PATCH] Now trimming decimal gps values to not be truncated in database --- application/ADBWohneinheit/ADBWohneinheit.php | 6 +++ ...0123134356_adb_increase_gps_float_size.php | 39 +++++++++++++++++++ .../ADBAddressHelper/address_helper.php | 24 ++++++++++-- 3 files changed, 66 insertions(+), 3 deletions(-) create mode 100644 db/migrations/20250123134356_adb_increase_gps_float_size.php diff --git a/application/ADBWohneinheit/ADBWohneinheit.php b/application/ADBWohneinheit/ADBWohneinheit.php index 2a74d2cf5..ff8b12731 100644 --- a/application/ADBWohneinheit/ADBWohneinheit.php +++ b/application/ADBWohneinheit/ADBWohneinheit.php @@ -107,6 +107,12 @@ class ADBWohneinheit extends mfBaseModel { $old_status = new ADBStatus($this->_old_data->status_id); $new_status = new ADBStatus($this->data->status_id); $logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."' [".$old_status->code." => ".$new_status->code."]"; + } elseif($key = "external_data" && $this->_old_data->external_data && $this->external_data) { + $old_data = json_decode($this->_old_data->external_data); + $new_data = json_decode($this->external_data); + if(json_encode($old_data) !== json_encode($new_data)) { + $logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."'"; + } } else { $logstr .= "| '$key' => FROM '".$this->_old_data->$key."' TO '".$this->data->$key."'"; } diff --git a/db/migrations/20250123134356_adb_increase_gps_float_size.php b/db/migrations/20250123134356_adb_increase_gps_float_size.php new file mode 100644 index 000000000..8bfbce32c --- /dev/null +++ b/db/migrations/20250123134356_adb_increase_gps_float_size.php @@ -0,0 +1,39 @@ +getEnvironment() == "thetool") { + + } + + if($this->getEnvironment() == "addressdb") { + $hn = $this->table("Hausnummer"); + $hn->changeColumn("gps_lat", "decimal", ["null" => true, "default" => null, "precision" => 17, "scale" => 14]); + $hn->changeColumn("gps_long", "decimal", ["null" => true, "default" => null, "precision" => 17, "scale" => 14]); + $hn->changeColumn("borderpoint_lat", "decimal", ["null" => true, "default" => null, "precision" => 17, "scale" => 14]); + $hn->changeColumn("borderpoint_long", "decimal", ["null" => true, "default" => null, "precision" => 17, "scale" => 14]); + $hn->update(); + + $fcp = $this->table("RimoFcp"); + $fcp->changeColumn("gps_lat", "decimal", ["null" => true, "default" => null, "precision" => 17, "scale" => 14]); + $fcp->changeColumn("gps_long", "decimal", ["null" => true, "default" => null, "precision" => 17, "scale" => 14]); + $fcp->update(); + } + } + + public function down(): void + { + if($this->getEnvironment() == "thetool") { + + } + + if($this->getEnvironment() == "addressdb") { + + } + } +} diff --git a/scripts/adb-rimo-import/ADBAddressHelper/address_helper.php b/scripts/adb-rimo-import/ADBAddressHelper/address_helper.php index d2e4e972e..f08c8d242 100644 --- a/scripts/adb-rimo-import/ADBAddressHelper/address_helper.php +++ b/scripts/adb-rimo-import/ADBAddressHelper/address_helper.php @@ -154,8 +154,10 @@ class AddressHelper $ort_name = $this->db->escape(trim($building->address->city)); $plz_name = $this->db->escape(trim($building->address->zipCode)); - $lat = $building->address->latitude; - $long = $building->address->longitude; + $lat = ($building->address->latitude) ? $this->truncateFloat($building->address->latitude, 14) : null; + $long = ($building->address->longitude) ? $this->truncateFloat($building->address->longitude, 14) : null; + //$lat = $building->address->latitude; + //$long = $building->address->longitude; $unit_count = $building->homesCount; $lot_num = $building->address->lotNumber; $fcp_name = false; @@ -324,7 +326,7 @@ class AddressHelper "hausnummer" => $hausnummer_name, "zusatz" => ($addresszusatz) ? $addresszusatz : null, "grund_nr" => ($lot_num) ? $lot_num : null, - "gps_lat" => $lat, + "gps_lat" => (float)$lat, "gps_long" => $long, "unit_count" => ($unit_count) ? $unit_count : 1, "freigabe" => $this->netzgebiet->freigabe, @@ -527,10 +529,26 @@ class AddressHelper return true; } + public function truncateFloat($number, $digits = 10) { + if(!$number) return null; + if(!is_numeric($number)) return null; + if(strpos($number, ".") === false) return $number; + + list ($num_part, $dec_part) = explode(".", $number); + if(strlen($dec_part) > $digits) { + $dec_part = substr($dec_part, 0, $digits); + } + + $new_number_str = (string)$num_part . "." . (string)$dec_part; + return (float)$new_number_str; + + } + private function logFindAddressError($text) { $logtext = trim($text); $this->find_address_error = $logtext; echo $logtext . "\n"; } + } \ No newline at end of file