From a8cd088df47aec2ef196c03a8bcae9f6bb5bf6b4 Mon Sep 17 00:00:00 2001 From: Jash Date: Tue, 17 Nov 2026 10:02:32 +0530 Subject: [PATCH] fix: frame TimeStampShort uses a MySQL format and the frame's own time refs #6563 --- tests/php/test_status_request.php | 16 ++++++++++++++-- web/ajax/status.php | 2 +- web/includes/config.php.in | 2 +- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/tests/php/test_status_request.php b/tests/php/test_status_request.php index 8e6087b891..1a71a1395e 100644 --- a/tests/php/test_status_request.php +++ b/tests/php/test_status_request.php @@ -18,7 +18,7 @@ namespace ZM { namespace { if (!isset($argv[1])) { $failures = 0; - foreach (array('system', 'sort_array') as $scenario) { + foreach (array('system', 'sort_array', 'frame_short') as $scenario) { passthru(escapeshellarg(PHP_BINARY).' '.escapeshellarg(__FILE__).' '.$scenario, $rc); if ($rc) $failures++; } @@ -36,7 +36,7 @@ namespace { function getDiskPercent() { return 0; } function translate($s) { return $s; } function validJsStr($v) { return (is_null($v) or is_array($v)) ? '' : strip_tags(addslashes($v)); } - function validInt($v) { return preg_replace('/[^\-\d]/', '', $v); } + function validInt($v) { return is_array($v) ? '' : preg_replace('/[^\-\d]/', '', $v); } $sqls = array(); function dbFetchOne($sql, $col = null, $params = array()) { $GLOBALS['sqls'][] = $sql; @@ -49,6 +49,9 @@ namespace { $scenario = $argv[1]; $_REQUEST = array('entity' => ($scenario == 'system') ? 'system' : 'frames'); if ($scenario == 'sort_array') $_REQUEST += array('id' => '7', 'sort' => array('FrameId')); + if ($scenario == 'frame_short') { + $_REQUEST = array('entity' => 'frame', 'id' => array('7', '3'), 'element' => array('TimeStampShort')); + } $thrown = ''; try { include __DIR__.'/../../web/ajax/status.php'; @@ -62,6 +65,15 @@ namespace { $ok = preg_match('/count\(if\(`?Deleted`? *= *(0|false),[^)]*\)\) as MonitorCount/i', $sql) && preg_match('/count\(if\(`?Deleted`? *= *(0|false) *and `Capturing` != \'None\',/i', $sql); echo ($ok ? 'ok' : 'FAIL').' - system counts leave out deleted monitors'.($ok ? '' : " ($sql)")."\n"; + } else if ($scenario == 'frame_short') { + // MySQL date_format() only expands %-specifiers, so the PHP style 'Y/m/d' the + // constant used to hold came back as that literal text, and the frame's own + // TimeStamp is what is shortened, not its event's start. + $sql = $sqls ? $sqls[0] : ''; + $fmt = file_get_contents(__DIR__.'/../../web/includes/config.php.in'); + $ok = preg_match("/define\('MYSQL_FMT_DATETIME_SHORT', '[^']*%y[^']*'\)/", $fmt) + && preg_match('/date_format\( Frames\.TimeStamp, /', $sql); + echo ($ok ? 'ok' : 'FAIL').' - TimeStampShort formats the frame TimeStamp with a MySQL format'.($ok ? '' : " ($sql; threw: $thrown)")."\n"; } else { $ok = ($thrown === ''); echo ($ok ? 'ok' : 'FAIL').' - array sort is ignored'.($ok ? '' : " (threw: $thrown)")."\n"; diff --git a/web/ajax/status.php b/web/ajax/status.php index e5e2a25b6d..3929b9dce7 100644 --- a/web/ajax/status.php +++ b/web/ajax/status.php @@ -223,7 +223,7 @@ $statusData = array( 'EventId' => true, 'Type' => true, 'TimeStamp' => true, - 'TimeStampShort' => array( 'sql' => 'date_format( StartDateTime, \''.MYSQL_FMT_DATETIME_SHORT.'\' )' ), + 'TimeStampShort' => array( 'sql' => 'date_format( Frames.TimeStamp, \''.MYSQL_FMT_DATETIME_SHORT.'\' )' ), 'Delta' => true, 'Score' => true, //'Image' => array( 'postFunc' => 'getFrameImage' ), diff --git a/web/includes/config.php.in b/web/includes/config.php.in index 1797408b18..882672fd89 100644 --- a/web/includes/config.php.in +++ b/web/includes/config.php.in @@ -109,7 +109,7 @@ define('SCALE_BASE', 100); // The additional scaling factor used to he // Date and time formats, not to be modified by language files // define('STRF_FMT_DATETIME_DB', 'Y-m-d H:i:s'); // Strftime format for database queries, don't change -define('MYSQL_FMT_DATETIME_SHORT', 'Y/m/d H:i:s'); // MySQL date_format shorter format for dates with time +define('MYSQL_FMT_DATETIME_SHORT', '%y/%m/%d %H:%i:%S'); // MySQL date_format shorter format for dates with time global $dateFormatter; global $dateTimeFormatter;