50 lines
1.6 KiB
PHP
Executable File
50 lines
1.6 KiB
PHP
Executable File
<?php
|
|
/**
|
|
* API - Reintentar Mensaje Discord
|
|
* Cambia el estado de un mensaje a 'pendiente'.
|
|
*/
|
|
header('Content-Type: application/json');
|
|
|
|
require_once __DIR__ . '/../../../shared/utils/helpers.php';
|
|
require_once __DIR__ . '/../../../shared/auth/jwt.php';
|
|
require_once __DIR__ . '/../../../shared/database/connection.php';
|
|
|
|
// Verificar autenticación
|
|
$userData = JWTAuth::authenticate();
|
|
if (!$userData) {
|
|
jsonResponse(['success' => false, 'error' => 'No autenticado'], 401);
|
|
}
|
|
|
|
// Verificar permiso (reutilizamos 'send_messages' ya que es una acción relacionada)
|
|
if (!hasPermission('send_messages', 'discord')) {
|
|
jsonResponse(['success' => false, 'error' => 'No tienes permiso para gestionar mensajes de Discord.'], 403);
|
|
}
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
|
|
jsonResponse(['success' => false, 'error' => 'Método no permitido'], 405);
|
|
}
|
|
|
|
$input = json_decode(file_get_contents('php://input'), true);
|
|
$messageId = $input['id'] ?? null;
|
|
|
|
if (empty($messageId)) {
|
|
jsonResponse(['success' => false, 'error' => 'Falta el ID del mensaje.'], 400);
|
|
}
|
|
|
|
try {
|
|
$db = getDB();
|
|
|
|
// Cambiar el estado del mensaje a 'pendiente'
|
|
$stmt = $db->prepare("UPDATE mensajes_discord SET estado = 'pendiente' WHERE id = ?");
|
|
$stmt->execute([$messageId]);
|
|
|
|
if ($stmt->rowCount() > 0) {
|
|
jsonResponse(['success' => true, 'message' => 'Mensaje marcado como pendiente.']);
|
|
} else {
|
|
jsonResponse(['success' => false, 'error' => 'No se encontró el mensaje o no se pudo actualizar.']);
|
|
}
|
|
|
|
} catch (Exception $e) {
|
|
jsonResponse(['success' => false, 'error' => 'Error en la base de datos: ' . $e->getMessage()], 500);
|
|
}
|