From dfe85296a846134908465be6aa16835d459680b1 Mon Sep 17 00:00:00 2001 From: stephan Date: Fri, 21 Aug 2026 14:33:28 -0400 Subject: [PATCH] Refactor RadarSyncService and RadarModel: improve AI analysis handling by checking for analysis columns before executing AI logic, and update comments for clarity. Adjust view logic to ensure count display is only updated when the element exists. --- v4_ci4/app/Libraries/Radar/RadarSyncService.php | 16 ++++++++++------ v4_ci4/app/Models/RadarModel.php | 3 ++- v4_ci4/app/Views/radar/index.php | 2 +- 3 files changed, 13 insertions(+), 8 deletions(-) diff --git a/v4_ci4/app/Libraries/Radar/RadarSyncService.php b/v4_ci4/app/Libraries/Radar/RadarSyncService.php index aa3c7c04..3e206f9c 100644 --- a/v4_ci4/app/Libraries/Radar/RadarSyncService.php +++ b/v4_ci4/app/Libraries/Radar/RadarSyncService.php @@ -46,13 +46,17 @@ class RadarSyncService $analyzer = null; $aiStats = ['enabled' => false, 'ran' => 0, 'skipped' => 0, 'errors' => 0, 'note' => '', 'model' => '']; try { - $ai = AiFactory::client(); - if ($ai->isConfigured()) { - $analyzer = new RadarAnalyzeService($ai); - $aiStats['enabled'] = true; - $aiStats['model'] = $ai->model(); + if (! $this->model->hasAnalysisColumns()) { + $aiStats['note'] = 'Colonnes analysis absentes — exécuter sql/MSOP-3-radar-analysis.sql'; } else { - $aiStats['note'] = 'IA non configurée (clé absente)'; + $ai = AiFactory::client(); + if ($ai->isConfigured()) { + $analyzer = new RadarAnalyzeService($ai); + $aiStats['enabled'] = true; + $aiStats['model'] = $ai->model(); + } else { + $aiStats['note'] = 'IA non configurée (clé absente)'; + } } } catch (\Throwable $e) { $aiStats['note'] = $e->getMessage(); diff --git a/v4_ci4/app/Models/RadarModel.php b/v4_ci4/app/Models/RadarModel.php index 5dc56bb8..77c24c2f 100644 --- a/v4_ci4/app/Models/RadarModel.php +++ b/v4_ci4/app/Models/RadarModel.php @@ -201,7 +201,8 @@ class RadarModel public function needsAnalysis(int $threadId): bool { if (! $this->hasAnalysisColumns()) { - return true; + // Sans sql/MSOP-3-radar-analysis.sql on ne lance pas l’IA en boucle. + return false; } $row = $this->db()->table('radar_threads')->select('analysis')->where('id', $threadId)->get()->getRowArray(); diff --git a/v4_ci4/app/Views/radar/index.php b/v4_ci4/app/Views/radar/index.php index 3e0c8915..93985f88 100644 --- a/v4_ci4/app/Views/radar/index.php +++ b/v4_ci4/app/Views/radar/index.php @@ -224,7 +224,7 @@ $statusClass = static function (string $status): string { } function render(threads) { - countEl.textContent = (threads.length || 0) + ' fil(s)'; + if (countEl) countEl.textContent = (threads.length || 0) + ' fil(s)'; if (!threads.length) { root.innerHTML = '

Aucun signal pour l’instant.

'; return;