@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Store "start", "end", and "until" event dates as CalendarDateTime objects

Summary:
Ref T10747. This does double-writes and starts generating/writing CalendarDateTimes.

This greater flexibility is necessary to support the full range of ICS-specifiable events, including "floating" events.

This doesn't do anything yet.

Test Plan: Created and edited events, verified sensible representations of corresponding datetimes appeared in the database.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T10747

Differential Revision: https://secure.phabricator.com/D16661

+110 -6
+5
resources/sql/autopatches/20161003.cal.02.parameters.sql
··· 1 + ALTER TABLE {$NAMESPACE}_calendar.calendar_event 2 + ADD parameters LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT}; 3 + 4 + UPDATE {$NAMESPACE}_calendar.calendar_event 5 + SET parameters = '{}' WHERE parameters = '';
+63 -4
src/applications/calendar/storage/PhabricatorCalendarEvent.php
··· 44 44 protected $utcInitialEpoch; 45 45 protected $utcUntilEpoch; 46 46 protected $utcInstanceEpoch; 47 + protected $parameters = array(); 47 48 48 49 private $parentEvent = self::ATTACHABLE; 49 50 private $invitees = self::ATTACHABLE; ··· 87 88 88 89 $default_icon = 'fa-calendar'; 89 90 91 + $datetime_start = PhutilCalendarAbsoluteDateTime::newFromEpoch( 92 + $now, 93 + $actor->getTimezoneIdentifier()); 94 + $datetime_end = $datetime_start->newRelativeDateTime('PT1H'); 95 + 90 96 return id(new PhabricatorCalendarEvent()) 91 97 ->setHostPHID($actor->getPHID()) 92 98 ->setIsCancelled(0) ··· 106 112 ->setDateTo($epoch_max) 107 113 ->setAllDayDateFrom($now_min) 108 114 ->setAllDayDateTo($now_max) 115 + ->setStartDateTime($datetime_start) 116 + ->setEndDateTime($datetime_end) 109 117 ->applyViewerTimezone($actor); 110 118 } 111 119 ··· 443 451 ), 444 452 self::CONFIG_SERIALIZATION => array( 445 453 'recurrenceFrequency' => self::SERIALIZATION_JSON, 454 + 'parameters' => self::SERIALIZATION_JSON, 446 455 ), 447 456 ) + parent::getConfiguration(); 448 457 } ··· 785 794 } 786 795 787 796 public function newStartDateTime() { 797 + $datetime = $this->getParameter('startDateTime'); 798 + if ($datetime) { 799 + return $this->newDateTimeFromDictionary($datetime); 800 + } 801 + 788 802 $epoch = $this->getDateFrom(); 789 803 return $this->newDateTimeFromEpoch($epoch); 790 804 } 791 805 792 806 public function newEndDateTime() { 807 + $datetime = $this->getParameter('endDateTime'); 808 + if ($datetime) { 809 + return $this->newDateTimeFromDictionary($datetime); 810 + } 811 + 793 812 $epoch = $this->getDateTo(); 794 813 return $this->newDateTimeFromEpoch($epoch); 795 814 } 796 815 797 816 public function newUntilDateTime() { 817 + $datetime = $this->getParameter('untilDateTime'); 818 + if ($datetime) { 819 + return $this->newDateTimeFromDictionary($datetime); 820 + } 821 + 798 822 $epoch = $this->getRecurrenceEndDate(); 799 823 if (!$epoch) { 800 824 return null; ··· 824 848 private function newDateTimeFromEpoch($epoch) { 825 849 $datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch($epoch); 826 850 851 + if ($this->getIsAllDay()) { 852 + $datetime->setIsAllDay(true); 853 + } 854 + 855 + return $this->newDateTimeFromDateTime($datetime); 856 + } 857 + 858 + private function newDateTimeFromDictionary(array $dict) { 859 + $datetime = PhutilCalendarAbsoluteDateTime::newFromDictionary($dict); 860 + return $this->newDateTimeFromDateTime($datetime); 861 + } 862 + 863 + private function newDateTimeFromDateTime(PhutilCalendarDateTime $datetime) { 827 864 $viewer_timezone = $this->viewerTimezone; 828 865 if ($viewer_timezone) { 829 866 $datetime->setViewerTimezone($viewer_timezone); 830 867 } 831 868 832 - if ($this->getIsAllDay()) { 833 - $datetime->setIsAllDay(true); 834 - } 869 + return $datetime; 870 + } 871 + 872 + public function getParameter($key, $default = null) { 873 + return idx($this->parameters, $key, $default); 874 + } 875 + 876 + public function setParameter($key, $value) { 877 + $this->parameters[$key] = $value; 878 + return $this; 879 + } 880 + 881 + public function setStartDateTime(PhutilCalendarDateTime $datetime) { 882 + return $this->setParameter( 883 + 'startDateTime', 884 + $datetime->newAbsoluteDateTime()->toDictionary()); 885 + } 835 886 836 - return $datetime; 887 + public function setEndDateTime(PhutilCalendarDateTime $datetime) { 888 + return $this->setParameter( 889 + 'endDateTime', 890 + $datetime->newAbsoluteDateTime()->toDictionary()); 837 891 } 838 892 893 + public function setUntilDateTime(PhutilCalendarDateTime $datetime) { 894 + return $this->setParameter( 895 + 'untilDateTime', 896 + $datetime->newAbsoluteDateTime()->toDictionary()); 897 + } 839 898 840 899 /* -( Markup Interface )--------------------------------------------------- */ 841 900
+19
src/applications/calendar/xaction/PhabricatorCalendarEventAllDayTransaction.php
··· 15 15 16 16 public function applyInternalEffects($object, $value) { 17 17 $object->setIsAllDay($value); 18 + 19 + // Adjust the flags on any other dates the event has. 20 + $keys = array( 21 + 'startDateTime', 22 + 'endDateTime', 23 + 'untilDateTime', 24 + ); 25 + 26 + foreach ($keys as $key) { 27 + $dict = $object->getParameter($key); 28 + if (!$dict) { 29 + continue; 30 + } 31 + 32 + $datetime = PhutilCalendarAbsoluteDateTime::newFromDictionary($dict); 33 + $datetime->setIsAllDay($value); 34 + 35 + $object->setParameter($key, $datetime->toDictionary()); 36 + } 18 37 } 19 38 20 39 public function getTitle() {
+7 -1
src/applications/calendar/xaction/PhabricatorCalendarEventEndDateTransaction.php
··· 12 12 public function applyInternalEffects($object, $value) { 13 13 $actor = $this->getActor(); 14 14 15 + // TODO: DEPRECATED. 15 16 $object->setDateTo($value); 16 - 17 17 $object->setAllDayDateTo( 18 18 $object->getDateEpochForTimezone( 19 19 $value, ··· 21 21 'Y-m-d 23:59:00', 22 22 null, 23 23 new DateTimeZone('UTC'))); 24 + 25 + $datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch( 26 + $value, 27 + $actor->getTimezoneIdentifier()); 28 + $datetime->setIsAllDay($object->getIsAllDay()); 29 + $object->setEndDateTime($datetime); 24 30 } 25 31 26 32 public function getTitle() {
+7 -1
src/applications/calendar/xaction/PhabricatorCalendarEventStartDateTransaction.php
··· 12 12 public function applyInternalEffects($object, $value) { 13 13 $actor = $this->getActor(); 14 14 15 + // TODO: DEPRECATED. 15 16 $object->setDateFrom($value); 16 - 17 17 $object->setAllDayDateFrom( 18 18 $object->getDateEpochForTimezone( 19 19 $value, ··· 21 21 'Y-m-d', 22 22 null, 23 23 new DateTimeZone('UTC'))); 24 + 25 + $datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch( 26 + $value, 27 + $actor->getTimezoneIdentifier()); 28 + $datetime->setIsAllDay($object->getIsAllDay()); 29 + $object->setStartDateTime($datetime); 24 30 } 25 31 26 32 public function getTitle() {
+9
src/applications/calendar/xaction/PhabricatorCalendarEventUntilDateTransaction.php
··· 10 10 } 11 11 12 12 public function applyInternalEffects($object, $value) { 13 + $actor = $this->getActor(); 14 + 15 + // TODO: DEPRECATED. 13 16 $object->setRecurrenceEndDate($value); 17 + 18 + $datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch( 19 + $value, 20 + $actor->getTimezoneIdentifier()); 21 + $datetime->setIsAllDay($object->getIsAllDay()); 22 + $object->setUntilDateTime($datetime); 14 23 } 15 24 16 25 public function getTitle() {