www/api/_ack_patch.php

15 lines
616 B
PHP
Raw Normal View History

2026-05-11 22:31:48 +00:00
<?php
// PATCH: handler robusto para /api/commands/ack
$j = json_decode(file_get_contents('php://input'), true) ?: [];
$id = isset($j['id']) ? (int)$j['id'] : 0;
$ok = isset($j['success']) ? (int)!!$j['success'] : (isset($j['ok']) ? (int)!!$j['ok'] : 1);
if ($id<=0) { http_response_code(400); echo json_encode(['error'=>'id required']); exit; }
$stmt = $pdo->prepare("UPDATE commands
SET status = CASE WHEN :ok=1 THEN 'done' ELSE 'failed' END
WHERE id=:id AND status!='done'");
$stmt->execute([':ok'=>$ok, ':id'=>$id]);
echo json_encode(['updated'=>$stmt->rowCount(), 'id'=>$id, 'success'=>(bool)$ok]);
exit;