Repository navigation
fix(schedules): carry Cacti core scheduler fixes into FlowView schedules - #348
TheWitness wants to merge 2 commits into
Conversation
Brings the FlowView schedule logic in line with the fixes made to Cacti core's lib/api_scheduler.php (Cacti/cacti#7568, #9063, #9153, #7995): - Refuse a send interval that is not in the list and a Scheduled Base Time that cannot be parsed, and do not store the row when validation fails. A zero interval used to spin save_schedules() forever and, once stored, queued the report on every poller cycle. - Compute the initial lastsent anchor arithmetically instead of stepping a while loop, and never from the 1970 epoch. - Advance lastsent after a run to the latest slot at or before the run time, so sends stay on the base time instead of drifting with poller lag, and a manual Send Now no longer moves the schedule. - Correct Every Week, Every 2 Weeks and Every Month from 5, 10 and 20 days to 7, 14 and 30 days, migrating existing rows on upgrade. - Pass the server offset to the schedule datetimepicker. Fixes #347 Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
🟡 Changes recommended
Manual sends can overwrite valid future schedule anchors, while the interval migration can delay existing schedules’ first sends by several days.
2 open issues
What changed in this PR
Aligns FlowView’s report scheduler with Cacti core fixes for validation, timing, and recurrence intervals.
Changes:
- Rejects invalid intervals, base times, and missing recipients before saving.
- Adds arithmetic schedule anchoring and whole-interval advancement.
- Corrects recurring intervals, migrates existing values, and sets the picker’s server timezone.
| File | Description |
|---|---|
| tests/Unit/ScheduleRunnerTest.php | Adds six schedule-anchor and validation tests. |
| run_schedule.php | Uses whole-interval advancement when recording runs. |
| locales/po/cacti.pot | Adds scheduler validation messages. |
| includes/functions.php | Adds initial-anchor and advancement helpers. |
| flowview_upgrade.php | Migrates legacy recurrence intervals. |
| flowview_schedules.php | Updates validation, interval choices, display fallback, and picker timezone. |
Review effort: Balanced
…future anchors Address review: the interval migration rebases lastsent so each schedule's next send is unchanged, and a manual send before the first scheduled slot keeps the future anchor instead of resetting it to the run minute. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
|
somethingwithproof
left a comment
There was a problem hiding this comment.
Reviewed against core develop's lib/api_scheduler.php (#9063, #7568/#9241, #9153/#7995) on PHP 8.2–8.6. The anchor maths matches the old loop, never fires twice (a 5-minute poller simulated over 3 days across the DST change sent exactly 3 times), refuses zero intervals and unreadable base times, and the migration is idempotent. Input handling is sound: sendinterval is filtered and allow-listed, the new SQL is prepared, and the redirect id is integer-filtered. Approve with nits; two behaviour points:
- Send Now still moves the base time after an edit.
run_schedule.php:179-182overwritesstarton every run, including a manual send, andstartis both "Scheduled Base Time" and "Last Sent".save_schedules()(flowview_schedules.php:468) re-anchors fromstartwhen the interval or start changes, so a daily 08:00 schedule sent manually at 13:22:41 stays at 08:00 until the interval is edited, then becomes 13:22:41. A separate last-run column, or re-anchoring fromlastsent + sendintervalwhen only the interval changes, would keep the base time fixed. - A failed validation on a new schedule loses the form.
flowview_schedules.php:458-461redirects before saving toaction=edit&id=, and nothing restores the fields. Keeping the posted values in the session for the reload would preserve them.
Nits:
- The
timezone:option atflowview_schedules.php:829has little effect whileshowButtonPanelis false (the add-on uses it mainly for the Now button). - The base time accepts relative text (
now,tomorrow,+1 week), and0000-00-00 00:00:00anchors at an odd seconds offset; storingdate('Y-m-d H:i:s', $base)instead of the raw text would normalise both. - Fixed-second intervals shift the wall-clock send by an hour across DST, as core's do, and "Every Month" is 30 days rather than a calendar month; worth a line in the help text.
flowview_upgrade.php:388reuses$oldas the loop variable, shadowing the version parameter.
somethingwithproof
left a comment
There was a problem hiding this comment.
Approving. The two behaviour points in my earlier review (Send Now moving the base time after an interval edit, and a failed validation losing a new schedule's form) can follow in a later change.




Summary
Fixes #347. This brings FlowView's interval scheduler (
flowview_schedules.php→flowview_process.php→run_schedule.php) in line with the fixes made to Cacti core'slib/api_scheduler.phpondevelop(Cacti/cacti#7568, #9063, #9153, #7995; see also Cacti/cacti#9241).max(1, recur_every)guard (#9063)save_schedules()refuses a send interval that is not in the list. A zero interval used to loop forever in the request, and once stored it queued the report on every poller cycle.=== falseguards, no 1970 next start (#7568, #9241)flowview_schedule_initial_lastsent()computes the anchor arithmetically. Newflowview_schedule_advance_lastsent()moveslastsentto the latest slot at or before the run, so sends stay on the base time instead of drifting with poller lag.$week = $day * 7flowview_upgrade.phpmigrates existing rows, and the list page falls back to "N Seconds" for any interval not in the list.timezoneserver offset (#9153, #7995)#startdatetimepicker.json_encode(__())in JS (#8991),__()inraise_message(#8739)Behaviour notes
lastsent = 0or a zero interval) keeps the old behaviour of anchoring to the run minute.flowview_upgrade(), so it reaches anyone upgrading from v4.9. On an existing 5.1 develop install it runs on the next version bump. Until then those rows show as "N Seconds" and keep sending at their old cadence.SELECT * ... WHERE id = ' . $save['id']concatenation insave_schedules()is left alone. It is tracked in Use the core request, SQL, shell and escaping APIs in the Databases, Filters and CLI scripts #321 / fix: use core SQL, shell and escaping APIs in the Databases, Filters and CLI scripts #322.Testing
pest --configuration=plugins/flowview/phpunit.xml: 412 passed, including 6 new cases intests/Unit/ScheduleRunnerTest.phpfor anchoring, refusal of zero/invalid input, whole-interval advance, manual send between slots, and the fallback.tests/bin/patch-coverage.php: 100% of changed library lines.tests/bin/check-i18n-pot.php: passes.cacti.potis regenerated with the two new strings.php -lon all changed files.