up
This commit is contained in:
+10
-1
@@ -4,10 +4,17 @@ require_once __DIR__ . '/../config/config.php';
|
|||||||
|
|
||||||
header('Content-Type: application/json; charset=utf-8');
|
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;
|
$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
|
// Allow single id or array of ids
|
||||||
$ids = [];
|
$ids = [];
|
||||||
if (isset($input['id'])) {
|
if (isset($input['id'])) {
|
||||||
@@ -24,6 +31,8 @@ if (empty($ids) || array_filter($ids) === []) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (function_exists('writeLog')) writeLog('INFO', 'delete_template.php parsed ids', ['ids' => $ids]);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$db = Database::getInstance();
|
$db = Database::getInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../config/config.php';
|
||||||
|
try {
|
||||||
|
$db = Database::getInstance();
|
||||||
|
$ids = [3];
|
||||||
|
$placeholders = implode(',', array_fill(0,count($ids),'?'));
|
||||||
|
$existing = $db->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();
|
||||||
|
}
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?php
|
||||||
|
require_once __DIR__ . '/../config/config.php';
|
||||||
|
try {
|
||||||
|
$db = Database::getInstance();
|
||||||
|
$ids = [3];
|
||||||
|
$placeholders = implode(',', array_fill(0, count($ids), '?'));
|
||||||
|
$existing = $db->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;
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user