CIM37 - Performance update

This commit is contained in:
“VeLiTi”
2024-04-03 22:24:55 +02:00
parent 2cb07cfd47
commit e9d34d0017
2 changed files with 48 additions and 41 deletions

View File

@@ -141,8 +141,13 @@ switch ($action) {
break; break;
case 'geolocation': case 'geolocation':
$sql = 'SELECT e.* FROM equipment e '.$whereclause.''; if ($whereclause == ''){
$whereclause = 'WHERE geolocation is not null';
} else {
$whereclause .= ' AND geolocation is not null';
}
$sql = 'SELECT distinct(geolocation) FROM equipment e '.$whereclause.'';
break; break;

View File

@@ -1858,47 +1858,49 @@ function createPartner($user_salesid,$user_soldto,$p_name,$p_type, $token){
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++
// Update GEOlOCATION // Update GEOlOCATION
// +++++++++++++++++++++++++++++++++++++++++++++++++++++++ // +++++++++++++++++++++++++++++++++++++++++++++++++++++++
function geolocationUpdate($token){ function geolocationUpdate($token){
include dirname(__FILE__,2).'/settings/settings.php'; include dirname(__FILE__,2).'/settings/settings.php';
//GET ALL WARRANTY REGISTRATIONS WHERE NO GEOLOCATION SET
$sql = 'SELECT e.*, h.* FROM equipment e join history h on e.rowID = h.equipmentid where h.type = "Warranty" AND e.geolocation is Null';
$pdo = dbConnect($dbname);
$stmt = $pdo->prepare($sql);
$stmt->execute();
$messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
//FOR ALL RECORDS RETURN FIND GEOLOCATION AT OSM //GET ALL WARRANTY REGISTRATIONS WHERE NO GEOLOCATION SET
foreach ($messages as $message){ $sql = 'SELECT h.equipmentid, h.description FROM equipment e join history h on e.rowID = h.equipmentid where h.type = "Warranty" AND e.geolocation is Null';
$warranty = json_decode($message['description']); $pdo = dbConnect($dbname);
$stmt = $pdo->prepare($sql);
//API URL OSM $stmt->execute();
$api_url = 'https://nominatim.openstreetmap.org/search?format=json&city='.$warranty->city.'&country='.$warranty->country; $messages = $stmt->fetchAll(PDO::FETCH_ASSOC);
//BUILD UP FILESTREAM //FOR ALL RECORDS RETURN FIND GEOLOCATION AT OSM
$httpOptions = [ foreach ($messages as $message){
"http" => [ $warranty = json_decode($message['description']);
"method" => "GET",
"header" => "User-Agent: Nominatim-Test" //API URL OSM
] $api_url = 'https://nominatim.openstreetmap.org/search?format=json&city='.$warranty->city.'&country='.$warranty->country;
]; $api_url = str_replace(' ','%20',$api_url);
//BUILD UP FILESTREAM
$httpOptions = [
"http" => [
"method" => "GET",
"header" => "User-Agent: Nominatim-Test"
]
];
$streamContext = stream_context_create($httpOptions); $streamContext = stream_context_create($httpOptions);
$geo_feedback = file_get_contents($api_url, false, $streamContext); $geo_feedback = file_get_contents($api_url, false, $streamContext);
$geo_feedback = json_decode($geo_feedback, true) ?? ''; $geo_feedback = json_decode($geo_feedback, true);
$lat = (isset($geo_feedback[0]["lat"]) && ($geo_feedback[0]["lat"] !='' || $geo_feedback[0]["lat"] != null))?$geo_feedback[0]["lat"]:0;
$long = (isset($geo_feedback[0]["lon"]) && ($geo_feedback[0]["lon"] !='' || $geo_feedback[0]["lon"] != null))?$geo_feedback[0]["lon"]:0;
//CHECK IF RESULTS ARE FOUND if ($lat !=0){
if (!empty($geo_feedback) || $geo_feedback !=''){ $geo_feedback = array($lat,$long);
$lat = $geo_feedback[0]["lat"] ?? ''; //JSON ENCODE GEOLOCATION RECEIVED AND SENT TO EQUIPMENT API
$long = $geo_feedback[0]["lon"] ?? ''; $geo_feedback = json_encode($geo_feedback);
$geo_feedback = array($lat,$long); //BUILD POST DATA
//JSON ENCODE GEOLOCATION RECEIVED AND SENT TO EQUIPMENT API $data = json_encode(array("rowID" => $message['equipmentid'] , "geolocation" => $geo_feedback), JSON_UNESCAPED_UNICODE);
$geo_feedback = json_encode($geo_feedback); //Secure data
//BUILD POST DATA $payload = generate_payload($data);
$data = json_encode(array("rowID" => $message['equipmentid'] , "geolocation" => $geo_feedback), JSON_UNESCAPED_UNICODE); //API call
//Secure data $responses = ioAPI('/v1/equipments', $payload, $token);
$payload = generate_payload($data);
//API call
ioAPI('/v1/equipments', $payload, $token);
}
} }
} }
}