mirror of
https://we.phorge.it/source/phorge.git
synced 2025-01-05 12:21:02 +01:00
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
This commit is contained in:
parent
0ce7eacaf1
commit
e042533375
6 changed files with 110 additions and 6 deletions
5
resources/sql/autopatches/20161003.cal.02.parameters.sql
Normal file
5
resources/sql/autopatches/20161003.cal.02.parameters.sql
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
ALTER TABLE {$NAMESPACE}_calendar.calendar_event
|
||||||
|
ADD parameters LONGTEXT NOT NULL COLLATE {$COLLATE_TEXT};
|
||||||
|
|
||||||
|
UPDATE {$NAMESPACE}_calendar.calendar_event
|
||||||
|
SET parameters = '{}' WHERE parameters = '';
|
|
@ -44,6 +44,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
||||||
protected $utcInitialEpoch;
|
protected $utcInitialEpoch;
|
||||||
protected $utcUntilEpoch;
|
protected $utcUntilEpoch;
|
||||||
protected $utcInstanceEpoch;
|
protected $utcInstanceEpoch;
|
||||||
|
protected $parameters = array();
|
||||||
|
|
||||||
private $parentEvent = self::ATTACHABLE;
|
private $parentEvent = self::ATTACHABLE;
|
||||||
private $invitees = self::ATTACHABLE;
|
private $invitees = self::ATTACHABLE;
|
||||||
|
@ -87,6 +88,11 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
||||||
|
|
||||||
$default_icon = 'fa-calendar';
|
$default_icon = 'fa-calendar';
|
||||||
|
|
||||||
|
$datetime_start = PhutilCalendarAbsoluteDateTime::newFromEpoch(
|
||||||
|
$now,
|
||||||
|
$actor->getTimezoneIdentifier());
|
||||||
|
$datetime_end = $datetime_start->newRelativeDateTime('PT1H');
|
||||||
|
|
||||||
return id(new PhabricatorCalendarEvent())
|
return id(new PhabricatorCalendarEvent())
|
||||||
->setHostPHID($actor->getPHID())
|
->setHostPHID($actor->getPHID())
|
||||||
->setIsCancelled(0)
|
->setIsCancelled(0)
|
||||||
|
@ -106,6 +112,8 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
||||||
->setDateTo($epoch_max)
|
->setDateTo($epoch_max)
|
||||||
->setAllDayDateFrom($now_min)
|
->setAllDayDateFrom($now_min)
|
||||||
->setAllDayDateTo($now_max)
|
->setAllDayDateTo($now_max)
|
||||||
|
->setStartDateTime($datetime_start)
|
||||||
|
->setEndDateTime($datetime_end)
|
||||||
->applyViewerTimezone($actor);
|
->applyViewerTimezone($actor);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -443,6 +451,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
||||||
),
|
),
|
||||||
self::CONFIG_SERIALIZATION => array(
|
self::CONFIG_SERIALIZATION => array(
|
||||||
'recurrenceFrequency' => self::SERIALIZATION_JSON,
|
'recurrenceFrequency' => self::SERIALIZATION_JSON,
|
||||||
|
'parameters' => self::SERIALIZATION_JSON,
|
||||||
),
|
),
|
||||||
) + parent::getConfiguration();
|
) + parent::getConfiguration();
|
||||||
}
|
}
|
||||||
|
@ -785,16 +794,31 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newStartDateTime() {
|
public function newStartDateTime() {
|
||||||
|
$datetime = $this->getParameter('startDateTime');
|
||||||
|
if ($datetime) {
|
||||||
|
return $this->newDateTimeFromDictionary($datetime);
|
||||||
|
}
|
||||||
|
|
||||||
$epoch = $this->getDateFrom();
|
$epoch = $this->getDateFrom();
|
||||||
return $this->newDateTimeFromEpoch($epoch);
|
return $this->newDateTimeFromEpoch($epoch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newEndDateTime() {
|
public function newEndDateTime() {
|
||||||
|
$datetime = $this->getParameter('endDateTime');
|
||||||
|
if ($datetime) {
|
||||||
|
return $this->newDateTimeFromDictionary($datetime);
|
||||||
|
}
|
||||||
|
|
||||||
$epoch = $this->getDateTo();
|
$epoch = $this->getDateTo();
|
||||||
return $this->newDateTimeFromEpoch($epoch);
|
return $this->newDateTimeFromEpoch($epoch);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function newUntilDateTime() {
|
public function newUntilDateTime() {
|
||||||
|
$datetime = $this->getParameter('untilDateTime');
|
||||||
|
if ($datetime) {
|
||||||
|
return $this->newDateTimeFromDictionary($datetime);
|
||||||
|
}
|
||||||
|
|
||||||
$epoch = $this->getRecurrenceEndDate();
|
$epoch = $this->getRecurrenceEndDate();
|
||||||
if (!$epoch) {
|
if (!$epoch) {
|
||||||
return null;
|
return null;
|
||||||
|
@ -824,18 +848,53 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
|
||||||
private function newDateTimeFromEpoch($epoch) {
|
private function newDateTimeFromEpoch($epoch) {
|
||||||
$datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch($epoch);
|
$datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch($epoch);
|
||||||
|
|
||||||
|
if ($this->getIsAllDay()) {
|
||||||
|
$datetime->setIsAllDay(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->newDateTimeFromDateTime($datetime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function newDateTimeFromDictionary(array $dict) {
|
||||||
|
$datetime = PhutilCalendarAbsoluteDateTime::newFromDictionary($dict);
|
||||||
|
return $this->newDateTimeFromDateTime($datetime);
|
||||||
|
}
|
||||||
|
|
||||||
|
private function newDateTimeFromDateTime(PhutilCalendarDateTime $datetime) {
|
||||||
$viewer_timezone = $this->viewerTimezone;
|
$viewer_timezone = $this->viewerTimezone;
|
||||||
if ($viewer_timezone) {
|
if ($viewer_timezone) {
|
||||||
$datetime->setViewerTimezone($viewer_timezone);
|
$datetime->setViewerTimezone($viewer_timezone);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($this->getIsAllDay()) {
|
|
||||||
$datetime->setIsAllDay(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $datetime;
|
return $datetime;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getParameter($key, $default = null) {
|
||||||
|
return idx($this->parameters, $key, $default);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setParameter($key, $value) {
|
||||||
|
$this->parameters[$key] = $value;
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setStartDateTime(PhutilCalendarDateTime $datetime) {
|
||||||
|
return $this->setParameter(
|
||||||
|
'startDateTime',
|
||||||
|
$datetime->newAbsoluteDateTime()->toDictionary());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setEndDateTime(PhutilCalendarDateTime $datetime) {
|
||||||
|
return $this->setParameter(
|
||||||
|
'endDateTime',
|
||||||
|
$datetime->newAbsoluteDateTime()->toDictionary());
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUntilDateTime(PhutilCalendarDateTime $datetime) {
|
||||||
|
return $this->setParameter(
|
||||||
|
'untilDateTime',
|
||||||
|
$datetime->newAbsoluteDateTime()->toDictionary());
|
||||||
|
}
|
||||||
|
|
||||||
/* -( Markup Interface )--------------------------------------------------- */
|
/* -( Markup Interface )--------------------------------------------------- */
|
||||||
|
|
||||||
|
|
|
@ -15,6 +15,25 @@ final class PhabricatorCalendarEventAllDayTransaction
|
||||||
|
|
||||||
public function applyInternalEffects($object, $value) {
|
public function applyInternalEffects($object, $value) {
|
||||||
$object->setIsAllDay($value);
|
$object->setIsAllDay($value);
|
||||||
|
|
||||||
|
// Adjust the flags on any other dates the event has.
|
||||||
|
$keys = array(
|
||||||
|
'startDateTime',
|
||||||
|
'endDateTime',
|
||||||
|
'untilDateTime',
|
||||||
|
);
|
||||||
|
|
||||||
|
foreach ($keys as $key) {
|
||||||
|
$dict = $object->getParameter($key);
|
||||||
|
if (!$dict) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
$datetime = PhutilCalendarAbsoluteDateTime::newFromDictionary($dict);
|
||||||
|
$datetime->setIsAllDay($value);
|
||||||
|
|
||||||
|
$object->setParameter($key, $datetime->toDictionary());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle() {
|
public function getTitle() {
|
||||||
|
|
|
@ -12,8 +12,8 @@ final class PhabricatorCalendarEventEndDateTransaction
|
||||||
public function applyInternalEffects($object, $value) {
|
public function applyInternalEffects($object, $value) {
|
||||||
$actor = $this->getActor();
|
$actor = $this->getActor();
|
||||||
|
|
||||||
|
// TODO: DEPRECATED.
|
||||||
$object->setDateTo($value);
|
$object->setDateTo($value);
|
||||||
|
|
||||||
$object->setAllDayDateTo(
|
$object->setAllDayDateTo(
|
||||||
$object->getDateEpochForTimezone(
|
$object->getDateEpochForTimezone(
|
||||||
$value,
|
$value,
|
||||||
|
@ -21,6 +21,12 @@ final class PhabricatorCalendarEventEndDateTransaction
|
||||||
'Y-m-d 23:59:00',
|
'Y-m-d 23:59:00',
|
||||||
null,
|
null,
|
||||||
new DateTimeZone('UTC')));
|
new DateTimeZone('UTC')));
|
||||||
|
|
||||||
|
$datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch(
|
||||||
|
$value,
|
||||||
|
$actor->getTimezoneIdentifier());
|
||||||
|
$datetime->setIsAllDay($object->getIsAllDay());
|
||||||
|
$object->setEndDateTime($datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle() {
|
public function getTitle() {
|
||||||
|
|
|
@ -12,8 +12,8 @@ final class PhabricatorCalendarEventStartDateTransaction
|
||||||
public function applyInternalEffects($object, $value) {
|
public function applyInternalEffects($object, $value) {
|
||||||
$actor = $this->getActor();
|
$actor = $this->getActor();
|
||||||
|
|
||||||
|
// TODO: DEPRECATED.
|
||||||
$object->setDateFrom($value);
|
$object->setDateFrom($value);
|
||||||
|
|
||||||
$object->setAllDayDateFrom(
|
$object->setAllDayDateFrom(
|
||||||
$object->getDateEpochForTimezone(
|
$object->getDateEpochForTimezone(
|
||||||
$value,
|
$value,
|
||||||
|
@ -21,6 +21,12 @@ final class PhabricatorCalendarEventStartDateTransaction
|
||||||
'Y-m-d',
|
'Y-m-d',
|
||||||
null,
|
null,
|
||||||
new DateTimeZone('UTC')));
|
new DateTimeZone('UTC')));
|
||||||
|
|
||||||
|
$datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch(
|
||||||
|
$value,
|
||||||
|
$actor->getTimezoneIdentifier());
|
||||||
|
$datetime->setIsAllDay($object->getIsAllDay());
|
||||||
|
$object->setStartDateTime($datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle() {
|
public function getTitle() {
|
||||||
|
|
|
@ -10,7 +10,16 @@ final class PhabricatorCalendarEventUntilDateTransaction
|
||||||
}
|
}
|
||||||
|
|
||||||
public function applyInternalEffects($object, $value) {
|
public function applyInternalEffects($object, $value) {
|
||||||
|
$actor = $this->getActor();
|
||||||
|
|
||||||
|
// TODO: DEPRECATED.
|
||||||
$object->setRecurrenceEndDate($value);
|
$object->setRecurrenceEndDate($value);
|
||||||
|
|
||||||
|
$datetime = PhutilCalendarAbsoluteDateTime::newFromEpoch(
|
||||||
|
$value,
|
||||||
|
$actor->getTimezoneIdentifier());
|
||||||
|
$datetime->setIsAllDay($object->getIsAllDay());
|
||||||
|
$object->setUntilDateTime($datetime);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle() {
|
public function getTitle() {
|
||||||
|
|
Loading…
Reference in a new issue