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
This commit is contained in:
1sonhador committed 2025-10-28 15:52:09 +00:00
1 parent 0283e966a9
commit 381ac55f6c
4 files changed
+92

No files matched your search

@@ -34,6 +34,13 @@ class AddRawRequestToRedirectStats extends Migration
@@ -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
*/
@@ -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
*/
@@ -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)