From 3d9d1429bce2ce054b4fc300231661021aa7fa34 Mon Sep 17 00:00:00 2001 From: icciAaron Date: Thu, 16 Apr 2026 10:38:18 -0400 Subject: [PATCH] fix(calendar): getNextEventByGroup returns false instead of empty array MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When no calendars in a group have upcoming events, the $events array is empty after the foreach loop. PHP's reset() on an empty array returns false, not []. This is inconsistent with Base::getNextEvent() which correctly returns [] when no events are found. The false return value causes a downstream crash in the timeconditions module (schedtc.php, Job.php) when it accesses $next['startdate'] — PHP 8.x throws "Undefined array key" on false. Return [] explicitly when $events is empty to honor the @return docblock contract ("the Found event or empty") and match the behavior of getNextEvent(). Also remove spurious $cal argument passed to the driver-level getNextEvent() which accepts zero parameters. Reported-by: Aaron Salsitz Co-Authored-By: Claude Code --- Calendar.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Calendar.class.php b/Calendar.class.php index 3fe88c71..f4cd5ae1 100644 --- a/Calendar.class.php +++ b/Calendar.class.php @@ -1112,13 +1112,13 @@ public function getNextEventByGroup($groupid, $now = null, $timezone = null) $cal = $this->getDriverById($calid); $cal->setTimezone($timezone); $cal->setNow($now); - $ev = $cal->getNextEvent($cal); + $ev = $cal->getNextEvent(); if (!empty($ev)) { $events[$ev['startdate']] = $ev; } } ksort($events); - return reset($events); + return !empty($events) ? reset($events) : []; } /**