Skip to content

fix(schedules): carry Cacti core scheduler fixes into FlowView schedules - #348

Open
TheWitness wants to merge 2 commits into
developfrom
fix/schedule-core-parity
Open

TheWitness wants to merge 2 commits into
developfrom
fix/schedule-core-parity

Conversation

@TheWitness

Copy link
Copy Markdown
Member

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's lib/api_scheduler.php on develop (Cacti/cacti#7568, #9063, #9153, #7995; see also Cacti/cacti#9241).

Core fix FlowView change
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.
Strict === false guards, no 1970 next start (#7568, #9241) An empty or unparsable Scheduled Base Time is refused instead of being counted forward from the epoch.
Whole-interval advance (#9063) New flowview_schedule_initial_lastsent() computes the anchor arithmetically. New flowview_schedule_advance_lastsent() moves lastsent to the latest slot at or before the run, so sends stay on the base time instead of drifting with poller lag.
$week = $day * 7 Every Week, Every 2 Weeks and Every Month were 5, 10 and 20 days. They are now 7, 14 and 30 days. flowview_upgrade.php migrates existing rows, and the list page falls back to "N Seconds" for any interval not in the list.
Picker timezone server offset (#9153, #7995) Added to the #start datetimepicker.
json_encode(__()) in JS (#8991), __() in raise_message (#8739) Already compliant. No change.

Behaviour notes

Testing

  • pest --configuration=plugins/flowview/phpunit.xml: 412 passed, including 6 new cases in tests/Unit/ScheduleRunnerTest.php for 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.pot is regenerated with the two new strings.
  • php -l on all changed files.

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>
Copilot AI balanced review requested due to automatic review settings December 5, 2026 14:03
xmacan
xmacan previously approved these changes Dec 5, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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

Comment thread flowview_upgrade.php Resolved
Comment thread includes/functions.php Resolved
…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>
@sonarqubecloud

sonarqubecloud Bot commented Dec 5, 2026

Copy link
Copy Markdown

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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:

  1. Send Now still moves the base time after an edit. run_schedule.php:179-182 overwrites start on every run, including a manual send, and start is both "Scheduled Base Time" and "Last Sent". save_schedules() (flowview_schedules.php:468) re-anchors from start when 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 from lastsent + sendinterval when only the interval changes, would keep the base time fixed.
  2. A failed validation on a new schedule loses the form. flowview_schedules.php:458-461 redirects before saving to action=edit&id=, and nothing restores the fields. Keeping the posted values in the session for the reload would preserve them.

Nits:

  • The timezone: option at flowview_schedules.php:829 has little effect while showButtonPanel is false (the add-on uses it mainly for the Now button).
  • The base time accepts relative text (now, tomorrow, +1 week), and 0000-00-00 00:00:00 anchors at an odd seconds offset; storing date('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:388 reuses $old as the loop variable, shadowing the version parameter.

@somethingwithproof somethingwithproof left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Schedules: carry Cacti core scheduler fixes into FlowView (zero interval loop, epoch start, drift, week length, picker timezone)

4 participants