1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-18 19:40:55 +01:00

Cancelled recurring events should propogate to real child events

Summary: Ref T8371, Cancelled recurring events should propogate to real child events

Test Plan: Create recurring event, create and exception to a ghost event, cancel recurring event, real ghost event should be treated as cancelled while the recurring event remains cancelled.

Reviewers: epriestley, #blessed_reviewers

Reviewed By: epriestley, #blessed_reviewers

Subscribers: Korvin, epriestley

Maniphest Tasks: T8371

Differential Revision: https://secure.phabricator.com/D13121
This commit is contained in:
lkassianik 2015-06-02 19:44:31 -07:00
parent 5e168b629d
commit 446611e2e3
3 changed files with 82 additions and 7 deletions

View file

@ -28,7 +28,9 @@ final class PhabricatorCalendarEventViewController
}
if ($sequence && $event->getIsRecurring()) {
$parent_event = $event;
$event = $event->generateNthGhost($sequence, $viewer);
$event->attachParentEvent($parent_event);
} else if ($sequence) {
return new Aphront404Response();
}

View file

@ -12,7 +12,6 @@ final class PhabricatorCalendarEventQuery
private $isCancelled;
private $instanceSequencePairs;
private $generateGhosts = false;
public function setGenerateGhosts($generate_ghosts) {
@ -108,13 +107,22 @@ final class PhabricatorCalendarEventQuery
$map = array();
$instance_sequence_pairs = array();
foreach ($events as $event) {
foreach ($events as $key => $event) {
$sequence_start = 0;
$sequence_end = null;
$duration = $event->getDateTo() - $event->getDateFrom();
$end = null;
if ($event->getIsRecurring() && !$event->getInstanceOfEventPHID()) {
$instance_of = $event->getInstanceOfEventPHID();
if ($instance_of == null && $this->isCancelled !== null) {
if ($event->getIsCancelled() != $this->isCancelled) {
unset($events[$key]);
continue;
}
}
if ($event->getIsRecurring() && $instance_of == null) {
$frequency = $event->getFrequencyUnit();
$modify_key = '+1 '.$frequency;
@ -164,8 +172,8 @@ final class PhabricatorCalendarEventQuery
$instance_sequence_pairs[] = array($event->getPHID(), $index);
$events[] = $event->generateNthGhost($index, $viewer);
$key = last_key($events);
$map[$event->getPHID()][$index] = $key;
$last_key = last_key($events);
$map[$event->getPHID()][$index] = $last_key;
}
}
}
@ -308,6 +316,9 @@ final class PhabricatorCalendarEventQuery
protected function willFilterPage(array $events) {
$range_start = $this->rangeBegin;
$range_end = $this->rangeEnd;
$instance_of_event_phids = array();
$recurring_events = array();
$viewer = $this->getViewer();
foreach ($events as $key => $event) {
$event_start = $event->getDateFrom();
@ -325,11 +336,27 @@ final class PhabricatorCalendarEventQuery
foreach ($events as $event) {
$phids[] = $event->getPHID();
$instance_of = $event->getInstanceOfEventPHID();
if ($instance_of) {
if ($instance_of != $event->getPHID() || $event->getIsGhostEvent()) {
$instance_of_event_phids[] = $event->getInstanceOfEventPHID();
}
}
}
if (count($instance_of_event_phids) > 0) {
$recurring_events = id(new PhabricatorCalendarEventQuery())
->setViewer($viewer)
->withPHIDs($instance_of_event_phids)
->execute();
$recurring_events = mpull($recurring_events, null, 'getPHID');
}
if ($events) {
$invitees = id(new PhabricatorCalendarEventInviteeQuery())
->setViewer($this->getViewer())
->setViewer($viewer)
->withEventPHIDs($phids)
->execute();
$invitees = mgroup($invitees, 'getEventPHID');
@ -337,9 +364,29 @@ final class PhabricatorCalendarEventQuery
$invitees = array();
}
foreach ($events as $event) {
foreach ($events as $key => $event) {
$event_invitees = idx($invitees, $event->getPHID(), array());
$event->attachInvitees($event_invitees);
$instance_of = $event->getInstanceOfEventPHID();
if (!$instance_of) {
continue;
}
$parent = idx($recurring_events, $instance_of);
// should never get here
if (!$parent) {
unset($events[$key]);
continue;
}
$event->attachParentEvent($parent);
if ($this->isCancelled !== null) {
if ($event->getIsCancelled() != $this->isCancelled) {
unset($events[$key]);
continue;
}
}
}
$events = msort($events, 'getDateFrom');

View file

@ -33,6 +33,7 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
const DEFAULT_ICON = 'fa-calendar';
private $parentEvent = self::ATTACHABLE;
private $invitees = self::ATTACHABLE;
private $appliedViewer;
@ -329,6 +330,31 @@ final class PhabricatorCalendarEvent extends PhabricatorCalendarDAO
return $uri;
}
public function getParentEvent() {
return $this->assertAttached($this->parentEvent);
}
public function attachParentEvent($event) {
$this->parentEvent = $event;
return $this;
}
public function getIsCancelled() {
$instance_of = $this->instanceOfEventPHID;
if ($instance_of != null && $this->getIsParentCancelled()) {
return true;
}
return $this->isCancelled;
}
public function getIsParentCancelled() {
$recurring_event = $this->getParentEvent();
if ($recurring_event->getIsCancelled()) {
return true;
}
return false;
}
/* -( Markup Interface )--------------------------------------------------- */