From b084efb36290cb19d37e6db2145fd4edf30cd46c Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 31 Oct 2016 13:47:45 -0700 Subject: [PATCH] Record a "series parent PHID" on Calendar events that retains relationships after forks Summary: When you edit "X and all future events", X becomes the new parent of an event series. Currently, it loses its relationship to its original parent. Instead, retain that relationship -- it's separate from the normal "parent", but we can use it to make the UI more clear or tweak behaviors later. This mostly just keeps us from losing/destroying data that we might need/want later. Test Plan: - Ran migrations. - Cancelled "X and all future events", saw sensible-appearing beahvior in the database for "seriesParentPHID". Reviewers: chad Reviewed By: chad Differential Revision: https://secure.phabricator.com/D16780 --- .../autopatches/20161031.calendar.01.seriesparent.sql | 5 +++++ .../PhabricatorCalendarEventCancelController.php | 7 +++++++ .../calendar/storage/PhabricatorCalendarEvent.php | 11 +++++++++++ 3 files changed, 23 insertions(+) create mode 100644 resources/sql/autopatches/20161031.calendar.01.seriesparent.sql diff --git a/resources/sql/autopatches/20161031.calendar.01.seriesparent.sql b/resources/sql/autopatches/20161031.calendar.01.seriesparent.sql new file mode 100644 index 0000000000..7589a161bc --- /dev/null +++ b/resources/sql/autopatches/20161031.calendar.01.seriesparent.sql @@ -0,0 +1,5 @@ +ALTER TABLE {$NAMESPACE}_calendar.calendar_event + ADD seriesParentPHID VARBINARY(64); + +UPDATE {$NAMESPACE}_calendar.calendar_event + SET seriesParentPHID = instanceOfEventPHID; diff --git a/src/applications/calendar/controller/PhabricatorCalendarEventCancelController.php b/src/applications/calendar/controller/PhabricatorCalendarEventCancelController.php index 9f4e0e508e..447e3a3c74 100644 --- a/src/applications/calendar/controller/PhabricatorCalendarEventCancelController.php +++ b/src/applications/calendar/controller/PhabricatorCalendarEventCancelController.php @@ -84,6 +84,13 @@ final class PhabricatorCalendarEventCancelController // NOTE: If you can't edit some of the future events, we just // don't try to update them. This seems like it's probably what // users are likely to expect. + + // NOTE: This only affects events that are currently in the same + // series, not all events that were ever in the original series. + // We could use series PHIDs instead of parent PHIDs to affect more + // events if this turns out to be counterintuitive. Other + // applications differ in their behavior. + $future = id(new PhabricatorCalendarEventQuery()) ->setViewer($viewer) ->withParentEventPHIDs(array($event->getPHID())) diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php index 7ebcbced72..1a629e07cb 100644 --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -27,6 +27,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO protected $isRecurring = 0; + protected $seriesParentPHID; protected $instanceOfEventPHID; protected $sequenceIndex; @@ -140,10 +141,16 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO 'a recurring parent event!')); } + $series_phid = $this->getSeriesParentPHID(); + if (!$series_phid) { + $series_phid = $this->getPHID(); + } + $child = id(new self()) ->setIsCancelled(0) ->setIsStub(0) ->setInstanceOfEventPHID($this->getPHID()) + ->setSeriesParentPHID($series_phid) ->setSequenceIndex($sequence) ->setIsRecurring(true) ->attachParentEvent($this) @@ -401,6 +408,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO 'icon' => 'text32', 'mailKey' => 'bytes20', 'isRecurring' => 'bool', + 'seriesParentPHID' => 'phid?', 'instanceOfEventPHID' => 'phid?', 'sequenceIndex' => 'uint32?', 'isStub' => 'bool', @@ -435,6 +443,9 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO 'columns' => array('instanceOfEventPHID', 'utcInstanceEpoch'), 'unique' => true, ), + 'key_series' => array( + 'columns' => array('seriesParentPHID', 'utcInitialEpoch'), + ), ), self::CONFIG_SERIALIZATION => array( 'recurrenceFrequency' => self::SERIALIZATION_JSON,