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:
@ -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();
|
||||
|
||||
@ -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();
|
||||
|
||||
|
||||
@ -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 l’instant.</p>';
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user