fix: traiter le premier lot de tickets

Refs #4 #5 #6 #9 #12 #16 #18 #20
This commit is contained in:
Alexandre NOEL 2026-09-07 23:31:29 +02:00
commit 04cbe54dd1
14 changed files with 87 additions and 12 deletions

View file

@ -9,7 +9,12 @@ final class GeoService
return null;
}
// Cache DB
// Garde-fou pour les bases anciennes dans lesquelles la table de cache
// n'avait jamais été créée par une migration dédiée.
$db->exec(
"CREATE TABLE IF NOT EXISTS geocode_cache (q TEXT PRIMARY KEY, lat REAL, lng REAL, raw_json TEXT, fetched_at TEXT NOT NULL DEFAULT (datetime('now')))",
);
$st = $db->prepare('SELECT lat,lng FROM geocode_cache WHERE q=:q LIMIT 1');
$st->execute([':q' => $q]);
$row = $st->fetch(PDO::FETCH_ASSOC);
@ -17,7 +22,6 @@ final class GeoService
return ['lat' => (float) $row['lat'], 'lng' => (float) $row['lng']];
}
// Nominatim (OpenStreetMap) — respecter l'usage: User-Agent + requêtes raisonnables
$url = 'https://nominatim.openstreetmap.org/search?format=jsonv2&limit=1&q=' . rawurlencode($q);
$ch = curl_init($url);
@ -43,7 +47,6 @@ final class GeoService
$json = json_decode($body, true);
if (!is_array($json) || empty($json[0]['lat']) || empty($json[0]['lon'])) {
// Stocker "vide" en cache évite de spammer
$db->prepare(
"INSERT OR REPLACE INTO geocode_cache(q,lat,lng,raw_json,fetched_at) VALUES(:q,NULL,NULL,:raw,datetime('now'))",
)->execute([':q' => $q, ':raw' => $body]);