diff --git a/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php b/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php --- a/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php +++ b/src/applications/calendar/editor/PhabricatorCalendarEventEditor.php @@ -34,25 +34,22 @@ } $actor = $this->getActor(); + + $invitees = $event->getInvitees(); + $event->copyFromParent($actor); $event->setIsStub(0); - $invitees = $event->getParentEvent()->getInvitees(); - - $new_invitees = array(); - foreach ($invitees as $invitee) { - $invitee = id(new PhabricatorCalendarEventInvitee()) - ->setEventPHID($event->getPHID()) - ->setInviteePHID($invitee->getInviteePHID()) - ->setInviterPHID($invitee->getInviterPHID()) - ->setStatus($invitee->getStatus()) - ->save(); - - $new_invitees[] = $invitee; - } + $event->openTransaction(); + $event->save(); + foreach ($invitees as $invitee) { + $invitee + ->setEventPHID($event->getPHID()) + ->save(); + } + $event->saveTransaction(); - $event->save(); - $event->attachInvitees($new_invitees); + $event->attachInvitees($invitees); } public function getTransactionTypes() { diff --git a/src/applications/calendar/storage/PhabricatorCalendarEvent.php b/src/applications/calendar/storage/PhabricatorCalendarEvent.php --- a/src/applications/calendar/storage/PhabricatorCalendarEvent.php +++ b/src/applications/calendar/storage/PhabricatorCalendarEvent.php @@ -27,7 +27,6 @@ protected $isRecurring = 0; - private $isGhostEvent = false; protected $instanceOfEventPHID; protected $sequenceIndex; @@ -60,6 +59,9 @@ protected $recurrenceEndDate; protected $recurrenceFrequency = array(); + private $isGhostEvent = false; + private $stubInvitees; + public static function initializeNewCalendarEvent(PhabricatorUser $actor) { $app = id(new PhabricatorApplicationQuery()) ->setViewer($actor) @@ -449,9 +451,34 @@ } public function getInvitees() { + if ($this->getIsGhostEvent() || $this->getIsStub()) { + if ($this->stubInvitees === null) { + $this->stubInvitees = $this->newStubInvitees(); + } + return $this->stubInvitees; + } + return $this->assertAttached($this->invitees); } + private function newStubInvitees() { + $parent = $this->getParentEvent(); + + $parent_invitees = $parent->getInvitees(); + $stub_invitees = array(); + + foreach ($parent_invitees as $invitee) { + $stub_invitee = id(new PhabricatorCalendarEventInvitee()) + ->setInviteePHID($invitee->getInviteePHID()) + ->setInviterPHID($invitee->getInviterPHID()) + ->setStatus(PhabricatorCalendarEventInvitee::STATUS_INVITED); + + $stub_invitees[] = $stub_invitee; + } + + return $stub_invitees; + } + public function attachInvitees(array $invitees) { $this->invitees = $invitees; return $this; @@ -478,6 +505,7 @@ if (!$invited) { return PhabricatorCalendarEventInvitee::STATUS_UNINVITED; } + $invited = $invited->getStatus(); return $invited; }