fix: persist custom date filter across syslog page navigation#251
fix: persist custom date filter across syslog page navigation#251somethingwithproof wants to merge 4 commits intoCacti:developfrom
Conversation
There was a problem hiding this comment.
Pull request overview
Fixes syslog viewer pagination resetting a custom date range by updating request/session handling in set_shift_span() so custom date1/date2 values can be restored when page navigation requests only include page=N.
Changes:
- Adjusts
set_shift_span()span logic to avoid recalculating dates on pagination when a custom range exists in session. - Restores
date1/date2from session and forcescustom=truewhen navigating pages without explicit date parameters. - Persists custom
date1/date2into session when the user selects a custom range.
syslog.php
Outdated
| global $graph_timeshifts; | ||
|
|
||
| if ($shift_span == 'span' || $shift_span === false) { | ||
| if ($shift_span == 'span' || ($shift_span === false && !isset($_SESSION[$session_prefix . '_date1']))) { |
There was a problem hiding this comment.
The span-vs-pagination branching only checks for the presence of the session "_date1" key. If "_date1" exists but "_date2" does not (e.g., older session state, partial cleanup, manual session edits), the code will fall into the pagination restore path and later read an undefined "_date2" index. Consider checking that both session date keys exist here (or treating a missing one as "no custom dates" and recalculating from the predefined timespan).
| if ($shift_span == 'span' || ($shift_span === false && !isset($_SESSION[$session_prefix . '_date1']))) { | |
| if ($shift_span == 'span' || ($shift_span === false && (!isset($_SESSION[$session_prefix . '_date1']) || !isset($_SESSION[$session_prefix . '_date2'])))) { |
syslog.php
Outdated
| // Page navigation: custom dates were set earlier; restore from session. | ||
| set_request_var('date1', $_SESSION[$session_prefix . '_date1']); | ||
| set_request_var('date2', $_SESSION[$session_prefix . '_date2']); | ||
| set_request_var('custom', true); |
There was a problem hiding this comment.
In the pagination restore branch, the code reads $_SESSION[$session_prefix . '_date1'] and '_date2' unconditionally. If either key is missing, PHP will raise an undefined index notice and date filtering may break. Add an isset() (or equivalent) guard for both keys and fall back to the span calculation / defaults when they are not present.
|
Fixed in fc27fb2 -- outer guard now checks for both |
When a user sets a custom date range and then navigates to the next page, the shift_span detection runs before validate_store_request_vars restores session values. shift_span was false (no date params in the page link), causing set_shift_span() to fall into the 'span' branch, which recalculated dates from predefined_timespan and killed the session date vars -- wiping the custom filter. Two-part fix: - In the 'custom' case, save date1/date2 to session (same pattern the existing 'shift' case already uses) so page navigation can find them. - Distinguish page navigation with saved custom dates (shift_span false + session dates present) from an explicit predefined-timespan selection. Only recalculate from predefined_timespan when no custom dates are in session. Fixes Cacti#250 Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
If _date1 exists but _date2 is absent (partial session state), the old check passed the guard and entered the pagination-restore path. The inner isset() at line 800 already fell back safely, but the outer guard now explicitly requires both keys to avoid confusing partial-session scenarios. Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
fc27fb2 to
f59b1ef
Compare
Signed-off-by: Thomas Vincent <thomasvincent@gmail.com>
Fixes #250.
Root cause
set_shift_span()detectedshift_spanbeforevalidate_store_request_vars()restored session values. Page navigation passes onlypage=N— nodate1/date2in the request — soshift_spanwasfalse. That fell into thespanbranch, which recalculated dates frompredefined_timespanand killed the session date vars, wiping the custom filter on every page turn.Fix
Two changes to
set_shift_span():customcase: savedate1/date2to session (same pattern the existingshiftcase already uses) so subsequent page navigation can find them.falsecase (page navigation): check whether custom dates exist in session. If yes, restore them and setcustom = trueinstead of recalculating frompredefined_timespan.The
spancase (explicit predefined-timespan selection) is unchanged: it still recalculates and kills the session dates as before.Verification