fix: log delete by selected ids reports a failed DELETE instead of answering success refs #7347

This commit is contained in:
Jash committed 2026-11-22 06:44:23 +05:30
1 parent 136a02b925
commit d02b0c99bb
2 files changed
+25 -1

No files matched your search

+22
View File
@@ -0,0 +1,22 @@
<?php
// Deleting selected log rows by id must report a failed DELETE to the browser
// instead of answering success. Usage: php test_log_delete_ids_failure.php [root]
$root = $argv[1] ?? __DIR__.'/../..';
$GLOBALS['err'] = null;
$GLOBALS['ok'] = false;
function dbQuery($sql, $params = null) { return null; } // simulated failure
function canEdit($a) { return true; }
function validHtmlStr($s) { return htmlspecialchars($s, ENT_QUOTES); }
function ajaxError($m) { $GLOBALS['err'] = $m; }
function ajaxResponse($d = array()) { $GLOBALS['ok'] = true; }
$user = null;
eval('namespace ZM; class Logger { public static $codes = array(-1=>"ERR", 0=>"INF", 1=>"DBG"); }
function Error($m) {} function Warning($m) {} function Debug($m) {}');
$_REQUEST = array('task' => 'delete', 'ids' => array('1', '2'));
require($root.'/web/ajax/log.php');
if ($GLOBALS['err'] !== null && !$GLOBALS['ok']) {
echo "[PASS] failed delete by ids is reported: {$GLOBALS['err']}\n";
exit(0);
}
echo "[FAIL] failed delete by ids was answered as success\n";
exit(1);
+3 -1
View File
@@ -30,7 +30,9 @@ if (!isset($_REQUEST['task'])) {
if (!empty($_REQUEST['ids'])) {
$ids = array_map('intval', (array)$_REQUEST['ids']);
$placeholders = implode(',', array_fill(0, count($ids), '?'));
dbQuery('DELETE FROM Logs WHERE Id IN (' . $placeholders . ')', $ids);
if (dbQuery('DELETE FROM Logs WHERE Id IN (' . $placeholders . ')', $ids) === null) {
$message = 'Failed to delete the selected log entries';
}
} else if (!empty($_REQUEST['all'])) {
// Deleting by id needs one request per 100 rows, which is unusable at the
// hundreds of thousands of rows people accumulate, and the table's