From 48666839feb52d4de11641fc757b6d7d506ccf2e Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 25 Oct 2016 10:31:10 -0700 Subject: [PATCH] Support RRULE "COUNT" for recurring events Summary: Ref T10747. RRULE events can repeat "UNTIL" a certain time, or a certain "COUNT" of times. In the UI, we only support "UNTIL". Also support "COUNT". Test Plan: Imported an event which repeats every other day, 5 times. Got 5 instances. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10747 Differential Revision: https://secure.phabricator.com/D16749 --- .../PhabricatorCalendarImportEngine.php | 3 +++ .../query/PhabricatorCalendarEventQuery.php | 5 ++++ .../storage/PhabricatorCalendarEvent.php | 23 ++++++++++++++++++- 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php index aaedf3e2fd..0b91a6244c 100644 --- a/src/applications/calendar/import/PhabricatorCalendarImportEngine.php +++ b/src/applications/calendar/import/PhabricatorCalendarImportEngine.php @@ -403,6 +403,9 @@ abstract class PhabricatorCalendarImportEngine $until_datetime->setViewerTimezone($timezone); $event->setUntilDateTime($until_datetime); } + + $count = $rrule->getCount(); + $event->setParameter('recurrenceCount', $count); } return $event; diff --git a/src/applications/calendar/query/PhabricatorCalendarEventQuery.php b/src/applications/calendar/query/PhabricatorCalendarEventQuery.php index 9949ee2f5a..5c6b34c9fb 100644 --- a/src/applications/calendar/query/PhabricatorCalendarEventQuery.php +++ b/src/applications/calendar/query/PhabricatorCalendarEventQuery.php @@ -633,6 +633,11 @@ final class PhabricatorCalendarEventQuery PhabricatorCalendarEvent $event, $raw_limit) { + $count = $event->getRecurrenceCount(); + if ($count && ($count <= $raw_limit)) { + return ($count - 1); + } + return $raw_limit; } diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php index 64bdf07d46..37b45a2a3f 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -226,10 +226,16 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO return null; } + $limit = $sequence + 1; + $count = $this->getRecurrenceCount(); + if ($count && ($count < $limit)) { + return null; + } + $instances = $set->getEventsBetween( null, $this->newUntilDateTime(), - $sequence + 1); + $limit); return idx($instances, $sequence, null); } @@ -907,9 +913,24 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO $rrule->setUntil($until); } + $count = $this->getRecurrenceCount(); + if ($count) { + $rrule->setCount($count); + } + return $rrule; } + public function getRecurrenceCount() { + $count = (int)$this->getParameter('recurrenceCount'); + + if (!$count) { + return null; + } + + return $count; + } + public function newRecurrenceSet() { if ($this->isChildEvent()) { return $this->getParentEvent()->newRecurrenceSet(); -- 2.51.2