From 0acaa950f1dc417df7232ba3e64229e28a8ba91e Mon Sep 17 00:00:00 2001 From: Andre Lorbach Date: Mon, 8 Jun 2026 09:22:26 +0200 Subject: [PATCH] Cast event timestamps to int before date() for PHP 8.1+. Fixes disk chart/report consolidation (#132), grid date formatting, search filter SQL builders, and export filenames; correct wrong field variable in two disk consolidation helpers. closes https://github.com/rsyslog/loganalyzer/issues/132 --- ChangeLog | 1 + src/classes/logstreamclickhouse.class.php | 8 ++++---- src/classes/logstreamdb.class.php | 8 ++++---- src/classes/logstreamdisk.class.php | 6 +++--- src/classes/logstreampdo.class.php | 8 ++++---- src/export.php | 2 +- src/include/functions_frontendhelpers.php | 12 ++++++------ 7 files changed, 23 insertions(+), 22 deletions(-) diff --git a/ChangeLog b/ChangeLog index 200b09cb..9844b46c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -18,6 +18,7 @@ Version 5.0.2, 2026-05-05 - Robustness & i18n - **`DieWithErrorMsg` / `DieWithFriendlyErrorMsg`**: fix invalid extra `` in the auxiliary error table; normalise detail rows; correct friendly-error footer cell markup; trim redundant padding `
` in error cells ([`functions_common.php`](src/include/functions_common.php)). - Export placeholder copy: strip decorative **`>` / `<`** from **`LN_GEN_SELECTEXPORT`** in en/de/es/ja `main.php`. + - PHP 8.1+: cast event timestamps to **`int`** before **`date()`** in disk consolidation/chart helpers, grid date formatting, DB/PDO/ClickHouse date-range filters, and export filenames; fix wrong field variable in disk **`ConsolidateItemListByField`** / **`ConsolidateDataByField`** date grouping ([#132](https://github.com/rsyslog/loganalyzer/issues/132), thanks **@KDocProf**). - E2E / Playwright - **`Modern theme visual review`**: switch session style via `userchange.php`, assert theme stylesheets, capture **`modern-01`…`modern-05`** screenshots under `e2e/test-results/ci-visual/` (index grid, **details dialog**, admin index, advanced search, reports). diff --git a/src/classes/logstreamclickhouse.class.php b/src/classes/logstreamclickhouse.class.php index 79790b19..a6d7b513 100644 --- a/src/classes/logstreamclickhouse.class.php +++ b/src/classes/logstreamclickhouse.class.php @@ -1518,20 +1518,20 @@ private function CreateSQLWhereClause() { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP]) . "'"; } else if ( $myfilter[FILTER_DATEMODE] == DATEMODE_RANGE_TO ) { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP]) . "'"; } else if ( $myfilter[FILTER_DATEMODE] == DATEMODE_RANGE_DATE ) { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "' AND " . - $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", ($myeventtime[EVTIME_TIMESTAMP]+86400) ) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP]) . "' AND " . + $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP] + 86400 ) . "'"; } break; diff --git a/src/classes/logstreamdb.class.php b/src/classes/logstreamdb.class.php index 26709c65..ebe4ea34 100644 --- a/src/classes/logstreamdb.class.php +++ b/src/classes/logstreamdb.class.php @@ -1547,20 +1547,20 @@ private function CreateSQLWhereClause() { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP]) . "'"; } else if ( $myfilter[FILTER_DATEMODE] == DATEMODE_RANGE_TO ) { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP]) . "'"; } else if ( $myfilter[FILTER_DATEMODE] == DATEMODE_RANGE_DATE ) { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "' AND " . - $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", ($myeventtime[EVTIME_TIMESTAMP]+86400) ) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP]) . "' AND " . + $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP] + 86400 ) . "'"; } break; diff --git a/src/classes/logstreamdisk.class.php b/src/classes/logstreamdisk.class.php index c6b12b1e..c0c96288 100644 --- a/src/classes/logstreamdisk.class.php +++ b/src/classes/logstreamdisk.class.php @@ -821,7 +821,7 @@ public function ConsolidateItemListByField($szConsFieldId, $nRecordLimit, $szSor if ( $nConsFieldType == FILTER_TYPE_DATE ) { // Convert to FULL Day Date for now! - $myFieldData = date( "Y-m-d", $logArray[$szFieldId][EVTIME_TIMESTAMP] ); + $myFieldData = date( "Y-m-d", (int)$logArray[$szConsFieldId][EVTIME_TIMESTAMP] ); } else // Just copy the value! $myFieldData = $logArray[$szConsFieldId]; @@ -914,7 +914,7 @@ public function ConsolidateDataByField($szConsFieldId, $nRecordLimit, $szSortFie if ( $nConsFieldType == FILTER_TYPE_DATE ) { // Convert to FULL Day Date for now! - $myFieldData = date( "Y-m-d", $logArray[$szFieldId][EVTIME_TIMESTAMP] ); + $myFieldData = date( "Y-m-d", (int)$logArray[$szConsFieldId][EVTIME_TIMESTAMP] ); } else // Just copy the value! $myFieldData = $logArray[$szConsFieldId]; @@ -1017,7 +1017,7 @@ public function GetCountSortedByField($szFieldId, $nFieldType, $nRecordLimit) if ( $nFieldType == FILTER_TYPE_DATE ) { // Convert to FULL Day Date for now! - $myFieldData = date( "Y-m-d", $logArray[$szFieldId][EVTIME_TIMESTAMP] ); + $myFieldData = date( "Y-m-d", (int)$logArray[$szFieldId][EVTIME_TIMESTAMP] ); } else // Just copy the value! $myFieldData = $logArray[$szFieldId]; diff --git a/src/classes/logstreampdo.class.php b/src/classes/logstreampdo.class.php index bbacb436..02d7b356 100644 --- a/src/classes/logstreampdo.class.php +++ b/src/classes/logstreampdo.class.php @@ -1852,20 +1852,20 @@ private function CreateSQLWhereClause() { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP]) . "'"; } else if ( $myfilter[FILTER_DATEMODE] == DATEMODE_RANGE_TO ) { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP]) . "'"; } else if ( $myfilter[FILTER_DATEMODE] == DATEMODE_RANGE_DATE ) { // Obtain Event struct for the time! $myeventtime = GetEventTime($myfilter[FILTER_VALUE]); - $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", $myeventtime[EVTIME_TIMESTAMP]) . "' AND " . - $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", ($myeventtime[EVTIME_TIMESTAMP]+86400) ) . "'"; + $tmpfilters[$propertyname][FILTER_VALUE] .= $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " > '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP]) . "' AND " . + $dbmapping[$szTableType]['DBMAPPINGS'][$propertyname] . " < '" . date("Y-m-d H:i:s", (int)$myeventtime[EVTIME_TIMESTAMP] + 86400 ) . "'"; } break; diff --git a/src/export.php b/src/export.php index 25adb1c4..9b39e9b1 100644 --- a/src/export.php +++ b/src/export.php @@ -400,7 +400,7 @@ $szOutputCharset = ""; $szOutputFileName = isset($content['period_start_ts']) - ? "ExportMessages_" . date('Ymd\THis', $content['period_start_ts']) . "-" . date('Ymd\THis', $content['period_end_ts']) + ? "ExportMessages_" . date('Ymd\THis', (int)$content['period_start_ts']) . "-" . date('Ymd\THis', (int)$content['period_end_ts']) : "ExportMessages"; $szOutputFileExtension = ".txt"; $szOPFieldSeparator = " "; diff --git a/src/include/functions_frontendhelpers.php b/src/include/functions_frontendhelpers.php index 0626dc6a..368d6d85 100644 --- a/src/include/functions_frontendhelpers.php +++ b/src/include/functions_frontendhelpers.php @@ -230,14 +230,14 @@ function GetFormatedDate($evttimearray, $onExport = false) ($onExport == true && GetConfigSetting("ExportUseTodayYesterday", 0, CFGLEVEL_USER) == 1) || ( $onExport == false && GetConfigSetting("ViewUseTodayYesterday", 0, CFGLEVEL_USER) == 1 - && ( date('m', $evttimearray[EVTIME_TIMESTAMP]) == date('m') && date('Y', $evttimearray[EVTIME_TIMESTAMP]) == date('Y') ) + && ( date('m', (int)$evttimearray[EVTIME_TIMESTAMP]) == date('m') && date('Y', (int)$evttimearray[EVTIME_TIMESTAMP]) == date('Y') ) ) ) { - if ( date('d', $evttimearray[EVTIME_TIMESTAMP]) == date('d') ) - return "Today " . date("H:i:s", $evttimearray[EVTIME_TIMESTAMP] ); - else if ( date('d', $evttimearray[EVTIME_TIMESTAMP] + 86400) == date('d') ) - return "Yesterday " . date("H:i:s", $evttimearray[EVTIME_TIMESTAMP] ); + if ( date('d', (int)$evttimearray[EVTIME_TIMESTAMP]) == date('d') ) + return "Today " . date("H:i:s", (int)$evttimearray[EVTIME_TIMESTAMP] ); + else if ( date('d', (int)$evttimearray[EVTIME_TIMESTAMP] + 86400) == date('d') ) + return "Yesterday " . date("H:i:s", (int)$evttimearray[EVTIME_TIMESTAMP] ); } // Copy to local variable @@ -251,7 +251,7 @@ function GetFormatedDate($evttimearray, $onExport = false) } // Reach return normal format! - return $szDateFormatted = date("Y-m-d H:i:s", $nMyTimeStamp ); + return $szDateFormatted = date("Y-m-d H:i:s", (int)$nMyTimeStamp ); } function GetDebugBgColor( $szDebugMode )