Skip to content

fix(schedtc): guard against empty calendar event in debug output#23

Open
icciaaron wants to merge 1 commit intoFreePBX:release/17.0from
icciaaron:fix/schedtc-calendar-debug-crash
Open

fix(schedtc): guard against empty calendar event in debug output#23
icciaaron wants to merge 1 commit intoFreePBX:release/17.0from
icciaaron:fix/schedtc-calendar-debug-crash

Conversation

@icciaaron
Copy link
Copy Markdown

Summary

schedtc.php --debug crashes with Undefined array key "startdate" when processing calendar-mode time conditions that have no upcoming events. The crash terminates the script, preventing all subsequent time conditions from being evaluated.

Root Cause

In the calendar-mode branch of schedtc.php, getNextEventByGroup() returns false and getNextEvent() returns [] when no upcoming calendar events exist. The debug output block unconditionally accesses \$next['startdate'] and \$next['starttime'] without checking whether \$next contains valid data. On PHP 8.x (PBXact 17 / Debian 12), this is a fatal error.

Fix

Add an empty() check on \$next before accessing its array keys. When no upcoming event exists, display "No upcoming calendar events" — useful diagnostic context instead of a crash.

Applied to both:

  • bin/schedtc.php — actively triggered via --debug flag
  • Job.php — defensive fix; \$debug is currently hardcoded false but the same latent bug exists

Reproduction

On any PBXact 17 / FreePBX 17 system with a calendar-mode time condition where the linked calendar has no future events:

php /var/www/html/admin/modules/timeconditions/bin/schedtc.php --debug

Environment

  • PBXact 17 / FreePBX 17
  • timeconditions 17.0.1.18
  • PHP 8.1+ (Debian 12)
  • Asterisk 21/22

Related


Discovered during fleet maintenance by Aaron Salsitz (Master Bitherder) at ICCI, LLC. Analysis and fix developed with Claude Code.

When a calendar-mode time condition has no upcoming events,
getNextEvent() returns [] and getNextEventByGroup() returns false.
Accessing $next['startdate'] on these values crashes with
"Undefined array key" on PHP 8.x, terminating schedtc.php --debug
and preventing all subsequent time conditions from being processed.

Add an empty() check before accessing $next array keys. When no
upcoming event exists, display "No upcoming calendar events" instead
of crashing.

Applied to both bin/schedtc.php (actively triggered via --debug)
and Job.php (defensive — $debug is currently hardcoded false).

Reported-by: Aaron Salsitz <asalsitz@icci.com>
Co-Authored-By: Claude Code <noreply@anthropic.com>
@icciaaron
Copy link
Copy Markdown
Author

Hi @prasanthcode4 @Akarsh04 — small defensive fix: schedtc was throwing a warning when a calendar returned no next event (common case for expired/one-shot calendars). Debug-output-only, no behavior change. Would appreciate a look when convenient.

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.

1 participant