Files
Grigory Vodyanov c5f328e22a fix(dav): make reminder and recurrence handling robust
Deleting a webcal subscription removed reminders by the subscription
id, but calendar_reminders.calendar_id refers to calendars, so it
removed the pending reminders of an unrelated calendar. Subscriptions
never get reminders, so that cleanup is dropped, and the reminder index
job no longer indexes subscription objects either.

Due reminders were processed in one loop that only caught
MaxInstancesExceededException. A reminder that failed in any other way
aborted the run and stayed queued, so every later run stopped at it
and no reminders were sent. Each reminder is now processed on its own;
one that fails is logged and removed, like reminders of invalid events.

Reminders of shared calendars went to sharees for private events as
well. They now go to the owner only, matching how private events are
shown to sharees.

The last occurrence of a COUNT rule was found by stepping through
every occurrence, and REPEAT alarms were expanded REPEAT times, both
without an upper bound. A COUNT above Sabre's maxRecurrences is now
treated like an endless rule, and REPEAT is only used together with
DURATION, as RFC 5545 requires, capped at 100 additional reminders.

Reminders already removed by a subscription deletion are not restored;
they are recreated when the event is saved again.

Assisted-by: ClaudeCode:claude-opus-5-5
Signed-off-by: Grigory Vodyanov <scratchx@gmx.com>
2026-11-26 14:27:44 +01:00

94 lines
2.6 KiB
PHP

<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\CalDAV;
use DateTime;
use DateTimeInterface;
use Sabre\VObject\Settings;
class EventReaderRRule extends \Sabre\VObject\Recur\RRuleIterator {
public function precision(): string {
return $this->frequency;
}
public function interval(): int {
return $this->interval;
}
public function concludes(): ?DateTime {
// evaluate if until value is a date
if ($this->until instanceof DateTimeInterface) {
return DateTime::createFromInterface($this->until);
}
// evaluate if count value is higher than 0
if ($this->count > 0) {
// finding the last occurrence means iterating over every occurrence, so a
// count above what sabre is allowed to expand is treated like an endless rule
if (Settings::$maxRecurrences !== -1 && $this->count > Settings::$maxRecurrences) {
return new DateTime(CalDavBackend::MAX_DATE);
}
// temporarily store current recurrence date and counter
$currentReccuranceDate = $this->currentDate;
$currentCounter = $this->counter;
// iterate over occurrences until last one (subtract 2 from count for start and end occurrence)
while ($this->counter <= ($this->count - 2)) {
$this->next();
}
// temporary store last reccurance date
$lastReccuranceDate = $this->currentDate;
// restore current recurrence date and counter
$this->currentDate = $currentReccuranceDate;
$this->counter = $currentCounter;
// return last recurrence date
return DateTime::createFromInterface($lastReccuranceDate);
}
return null;
}
public function concludesAfter(): ?int {
return !empty($this->count) ? $this->count : null;
}
public function concludesOn(): ?DateTime {
return isset($this->until) ? DateTime::createFromInterface($this->until) : null;
}
public function daysOfWeek(): array {
return is_array($this->byDay) ? $this->byDay : [];
}
public function daysOfMonth(): array {
return is_array($this->byMonthDay) ? $this->byMonthDay : [];
}
public function daysOfYear(): array {
return is_array($this->byYearDay) ? $this->byYearDay : [];
}
public function weeksOfYear(): array {
return is_array($this->byWeekNo) ? $this->byWeekNo : [];
}
public function monthsOfYear(): array {
return is_array($this->byMonth) ? $this->byMonth : [];
}
public function isRelative(): bool {
return isset($this->bySetPos);
}
public function relativePosition(): array {
return is_array($this->bySetPos) ? $this->bySetPos : [];
}
}