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.

This commit is contained in:
2026-08-21 14:33:28 -04:00
parent b6e8961bf8
commit dfe85296a8
3 changed files with 13 additions and 8 deletions

View File

@ -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();

View File

@ -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 lIA en boucle.
return false;
}
$row = $this->db()->table('radar_threads')->select('analysis')->where('id', $threadId)->get()->getRowArray();

View File

@ -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 = '<p class="text-sm text-zinc-400">Aucun signal pour linstant.</p>';
return;