1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-09-22 10:18:48 +02:00
phorge-phorge/src/applications/calendar/controller/PhabricatorCalendarEventCancelController.php
epriestley 3ab6a7e19f Generate "stub" events earlier, so more infrastructure works with Calendar
Summary:
Ref T9275. When you create a recurring event which recurs forever, we want to avoid writing an infinite number of rows to the database.

Currently, we write a row to the database right before you edit the event. Until then, we refer to it as `E123/999` or whatever ("instance 999 of event 123").

This creates a big mess with trying to make recurring events work with EditEngine, Subscriptions, Projects, Flags, Tokens, etc -- all of this stuff assumes that whatever you're working with has a PHID.

I poked at letting this stuff work without a PHID a little bit, but that looked like a gigantic mess.

Instead, generate an event "stub" a little sooner (when you look at the event detail page). This is basically just an ID/PHID to refer to the instance.

Then, when you edit the stub, "materialize" it into a real event.

This still has some issues, but I think it's more promising than the other approach was.

Also:

  - Removes dead user profile calendar controller.
  - Replaces comments with EditEngine comments.

Test Plan:
  - Commented on a recurring event.
  - Awarded tokens to a recurring event.

Reviewers: chad

Reviewed By: chad

Maniphest Tasks: T9275

Differential Revision: https://secure.phabricator.com/D16248
2016-07-13 07:41:16 -07:00

111 lines
3.5 KiB
PHP

<?php
final class PhabricatorCalendarEventCancelController
extends PhabricatorCalendarController {
public function handleRequest(AphrontRequest $request) {
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$event = id(new PhabricatorCalendarEventQuery())
->setViewer($viewer)
->withIDs(array($id))
->requireCapabilities(
array(
PhabricatorPolicyCapability::CAN_VIEW,
PhabricatorPolicyCapability::CAN_EDIT,
))
->executeOne();
if (!$event) {
return new Aphront404Response();
}
$cancel_uri = $event->getURI();
$is_parent = $event->isParentEvent();
$is_child = $event->isChildEvent();
$is_cancelled = $event->getIsCancelled();
if ($is_child) {
$is_parent_cancelled = $event->getParentEvent()->getIsCancelled();
} else {
$is_parent_cancelled = false;
}
$validation_exception = null;
if ($request->isFormPost()) {
$xactions = array();
$xaction = id(new PhabricatorCalendarEventTransaction())
->setTransactionType(
PhabricatorCalendarEventTransaction::TYPE_CANCEL)
->setNewValue(!$is_cancelled);
$editor = id(new PhabricatorCalendarEventEditor())
->setActor($viewer)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect(true)
->setContinueOnMissingFields(true);
try {
$editor->applyTransactions($event, array($xaction));
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
} catch (PhabricatorApplicationTransactionValidationException $ex) {
$validation_exception = $ex;
}
}
if ($is_cancelled) {
if ($is_parent_cancelled) {
$title = pht('Cannot Reinstate Instance');
$paragraph = pht(
'You cannot reinstate an instance of a cancelled recurring event.');
$cancel = pht('Back');
$submit = null;
} else if ($is_child) {
$title = pht('Reinstate Instance');
$paragraph = pht(
'Reinstate this instance of this recurring event?');
$cancel = pht('Back');
$submit = pht('Reinstate Instance');
} else if ($is_parent) {
$title = pht('Reinstate Recurring Event');
$paragraph = pht(
'Reinstate all instances of this recurring event which have not '.
'been individually cancelled?');
$cancel = pht('Back');
$submit = pht('Reinstate Recurring Event');
} else {
$title = pht('Reinstate Event');
$paragraph = pht('Reinstate this event?');
$cancel = pht('Back');
$submit = pht('Reinstate Event');
}
} else {
if ($is_child) {
$title = pht('Cancel Instance');
$paragraph = pht('Cancel this instance of this recurring event?');
$cancel = pht('Back');
$submit = pht('Cancel Instance');
} else if ($is_parent) {
$title = pht('Cancel Recurrin Event');
$paragraph = pht('Cancel this entire series of recurring events?');
$cancel = pht('Back');
$submit = pht('Cancel Recurring Event');
} else {
$title = pht('Cancel Event');
$paragraph = pht(
'Cancel this event? You can always reinstate the event later.');
$cancel = pht('Back');
$submit = pht('Cancel Event');
}
}
return $this->newDialog()
->setTitle($title)
->setValidationException($validation_exception)
->appendParagraph($paragraph)
->addCancelButton($cancel_uri, $cancel)
->addSubmitButton($submit);
}
}