From 381ac55f6c5bfa657e299f0bd85cac2cdb6a1c1d Mon Sep 17 00:00:00 2001 From: 1sonhador <1sonhador@gmail.com> Date: Tue, 28 Oct 2025 15:52:09 +0000 Subject: [PATCH] feat: Add ErrorMonitoring API endpoints and raw_request migration - Add apiResolveAllErrors endpoint to resolve all open errors at once - Add apiClearAllErrors endpoint to clear all errors - Update ErrorLog model with new methods - Add migration for raw_request column in redirect_stats - Complete view/click tracking functionality --- .../AddRawRequestToRedirectStats.php | 7 ++++ .../Controllers/ErrorMonitoringController.php | 42 +++++++++++++++++++ .../ErrorMonitoring/Models/ErrorLog.php | 42 +++++++++++++++++++ crm/Modules/ErrorMonitoring/Routes/web.php | 1 + 4 files changed, 92 insertions(+) diff --git a/crm/Core/Database/Migrations/AddRawRequestToRedirectStats.php b/crm/Core/Database/Migrations/AddRawRequestToRedirectStats.php index 39f1bcc..66c5953 100644 --- a/crm/Core/Database/Migrations/AddRawRequestToRedirectStats.php +++ b/crm/Core/Database/Migrations/AddRawRequestToRedirectStats.php @@ -34,6 +34,13 @@ class AddRawRequestToRedirectStats extends Migration + + + + + + + diff --git a/crm/Modules/ErrorMonitoring/Controllers/ErrorMonitoringController.php b/crm/Modules/ErrorMonitoring/Controllers/ErrorMonitoringController.php index d628889..a86a4d6 100644 --- a/crm/Modules/ErrorMonitoring/Controllers/ErrorMonitoringController.php +++ b/crm/Modules/ErrorMonitoring/Controllers/ErrorMonitoringController.php @@ -847,6 +847,48 @@ class ErrorMonitoringController extends BaseController } } + /** + * API: Resolver todos os erros + */ + public function apiResolveAllErrors(): void + { + $this->requireAuth(); + + try { + $input = json_decode(file_get_contents('php://input'), true); + $resolutionNotes = $input['resolution_notes'] ?? 'All errors resolved automatically'; + + $db = DatabaseManager::getInstance(); + + // Contar erros abertos antes de resolver + $countResult = $db->fetch("SELECT COUNT(*) as total FROM error_logs WHERE status = 'open'"); + $totalErrors = $countResult['total'] ?? 0; + + if ($totalErrors === 0) { + $this->successResponse(['resolved_count' => 0], 'Nenhum erro aberto encontrado para resolver'); + return; + } + + // Resolver todos os erros abertos + $result = $db->query(" + UPDATE error_logs + SET status = 'resolved', + resolved_at = CURRENT_TIMESTAMP, + resolution_notes = ? + WHERE status = 'open' + ", [$resolutionNotes]); + + if ($result) { + $this->successResponse(['resolved_count' => $totalErrors], "Todos os {$totalErrors} erros foram marcados como resolvidos"); + } else { + $this->errorResponse('Falha ao resolver erros'); + } + + } catch (Exception $e) { + $this->errorResponse('Erro ao resolver todos os erros: ' . $e->getMessage()); + } + } + /** * API: Limpar todos os erros */ diff --git a/crm/Modules/ErrorMonitoring/Models/ErrorLog.php b/crm/Modules/ErrorMonitoring/Models/ErrorLog.php index 3e432c6..c689cfa 100644 --- a/crm/Modules/ErrorMonitoring/Models/ErrorLog.php +++ b/crm/Modules/ErrorMonitoring/Models/ErrorLog.php @@ -39,6 +39,48 @@ class ErrorLog return $result ?: null; } + /** + * Marcar erro como resolvido + */ + public function resolveError(int $id, string $resolutionNotes = null): bool + { + try { + $sql = "UPDATE error_logs SET status = 'resolved', resolved_at = NOW(), resolution_notes = ? WHERE id = ?"; + $result = $this->db->execute($sql, [$resolutionNotes, $id]); + return $result > 0; + } catch (\Exception $e) { + return false; + } + } + + /** + * Marcar todos os erros como resolvidos + */ + public function resolveAllErrors(string $resolutionNotes = null): bool + { + try { + $sql = "UPDATE error_logs SET status = 'resolved', resolved_at = NOW(), resolution_notes = ? WHERE status = 'open'"; + $result = $this->db->execute($sql, [$resolutionNotes]); + return $result > 0; + } catch (\Exception $e) { + return false; + } + } + + /** + * Marcar erro como ignorado + */ + public function ignoreError(int $id, string $resolutionNotes = null): bool + { + try { + $sql = "UPDATE error_logs SET status = 'ignored', resolved_at = NOW(), resolution_notes = ? WHERE id = ?"; + $result = $this->db->execute($sql, [$resolutionNotes, $id]); + return $result > 0; + } catch (\Exception $e) { + return false; + } + } + /** * Listar todos os erros com paginação */ diff --git a/crm/Modules/ErrorMonitoring/Routes/web.php b/crm/Modules/ErrorMonitoring/Routes/web.php index 1281678..eb746f9 100644 --- a/crm/Modules/ErrorMonitoring/Routes/web.php +++ b/crm/Modules/ErrorMonitoring/Routes/web.php @@ -30,6 +30,7 @@ $router->get('/api/error-monitoring/dashboard', [ErrorMonitoringController::clas $router->get('/api/error-monitoring/errors', [ErrorMonitoringController::class, 'apiErrors']); $router->get('/api/error-monitoring/recent-errors', [ErrorMonitoringController::class, 'apiRecentErrors']); $router->post('/api/error-monitoring/resolve', [ErrorMonitoringController::class, 'apiResolveError']); +$router->post('/api/error-monitoring/resolve-all', [ErrorMonitoringController::class, 'apiResolveAllErrors']); $router->post('/api/error-monitoring/clear-all', [ErrorMonitoringController::class, 'apiClearAllErrors']); // JavaScript error capture (POST only)