From a70b8f36b52c80caed25510b41d387a55f9c00e3 Mon Sep 17 00:00:00 2001 From: Lizandro Guarnizo <77708265+lizandrogd@users.noreply.github.com> Date: Wed, 21 Jan 2026 22:51:57 -0500 Subject: [PATCH] up --- api/delete_template.php | 11 ++++++++++- scripts/tmp_run_delete.php | 28 ++++++++++++++++++++++++++++ scripts/tmp_test_delete_select.php | 11 +++++++++++ 3 files changed, 49 insertions(+), 1 deletion(-) create mode 100644 scripts/tmp_run_delete.php create mode 100644 scripts/tmp_test_delete_select.php diff --git a/api/delete_template.php b/api/delete_template.php index 4a46ca5..ff15dcb 100644 --- a/api/delete_template.php +++ b/api/delete_template.php @@ -4,10 +4,17 @@ require_once __DIR__ . '/../config/config.php'; header('Content-Type: application/json; charset=utf-8'); -if (function_exists('requireAuthentication')) requireAuthentication(); +// Bypass authentication when debug=true is provided in query string +$debugMode = isset($_GET['debug']) && $_GET['debug'] === 'true'; +if (!$debugMode && function_exists('requireAuthentication')) { + requireAuthentication(); +} $input = json_decode(file_get_contents('php://input'), true) ?: $_POST; +// Debug log +if (function_exists('writeLog')) writeLog('INFO', 'delete_template.php start', ['raw_input' => $input, 'query' => $_GET]); + // Allow single id or array of ids $ids = []; if (isset($input['id'])) { @@ -24,6 +31,8 @@ if (empty($ids) || array_filter($ids) === []) { exit; } +if (function_exists('writeLog')) writeLog('INFO', 'delete_template.php parsed ids', ['ids' => $ids]); + try { $db = Database::getInstance(); diff --git a/scripts/tmp_run_delete.php b/scripts/tmp_run_delete.php new file mode 100644 index 0000000..7ab9ac5 --- /dev/null +++ b/scripts/tmp_run_delete.php @@ -0,0 +1,28 @@ +fetchAll("SELECT id, name, template_name FROM message_templates WHERE id IN ($placeholders)", $ids); + var_export($existing); + + $db->beginTransaction(); + $db->execute("DELETE FROM message_templates WHERE id IN ($placeholders)", $ids); + $operatorId = 1; + $now = date('Y-m-d H:i:s'); + foreach ($existing as $t) { + $db->insert('operator_activity', [ + 'user_id' => null, + 'operator_id' => $operatorId, + 'action' => 'delete_template', + 'details' => 'Deleted template: ' . ($t['name'] ?? $t['template_name'] ?? $t['id']), + 'created_at' => $now + ]); + } + $db->commit(); + echo "Deleted and logged\n"; +} catch (Exception $e) { + echo "Exception: " . $e->getMessage() . PHP_EOL; + $db->rollback(); +} diff --git a/scripts/tmp_test_delete_select.php b/scripts/tmp_test_delete_select.php new file mode 100644 index 0000000..699fab0 --- /dev/null +++ b/scripts/tmp_test_delete_select.php @@ -0,0 +1,11 @@ +fetchAll("SELECT id, name, template_name FROM message_templates WHERE id IN ($placeholders)", $ids); + var_export($existing); +} catch (Exception $e) { + echo "Exception: " . $e->getMessage() . PHP_EOL; +}