Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorCalendarEventCancelController
|
|
|
|
extends PhabricatorCalendarController {
|
|
|
|
|
2015-08-02 00:43:14 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
|
|
|
$id = $request->getURIData('id');
|
2015-06-06 22:03:21 +02:00
|
|
|
$sequence = $request->getURIData('sequence');
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
|
2015-06-06 22:03:21 +02:00
|
|
|
$event = id(new PhabricatorCalendarEventQuery())
|
2015-08-02 00:43:14 +02:00
|
|
|
->setViewer($viewer)
|
|
|
|
->withIDs(array($id))
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
|
2015-06-06 22:03:21 +02:00
|
|
|
if ($sequence) {
|
|
|
|
$parent_event = $event;
|
2015-08-02 00:43:14 +02:00
|
|
|
$event = $parent_event->generateNthGhost($sequence, $viewer);
|
2015-06-06 22:03:21 +02:00
|
|
|
$event->attachParentEvent($parent_event);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!$event) {
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
2015-06-06 22:03:21 +02:00
|
|
|
if (!$sequence) {
|
|
|
|
$cancel_uri = '/E'.$event->getID();
|
|
|
|
} else {
|
|
|
|
$cancel_uri = '/E'.$event->getID().'/'.$sequence;
|
|
|
|
}
|
|
|
|
|
|
|
|
$is_cancelled = $event->getIsCancelled();
|
|
|
|
$is_parent_cancelled = $event->getIsParentCancelled();
|
2015-06-09 06:40:32 +02:00
|
|
|
$is_parent = $event->getIsRecurrenceParent();
|
2015-06-06 22:03:21 +02:00
|
|
|
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
$validation_exception = null;
|
|
|
|
|
|
|
|
if ($request->isFormPost()) {
|
2015-06-06 22:03:21 +02:00
|
|
|
if ($is_cancelled && $sequence) {
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
|
|
|
|
} else if ($sequence) {
|
|
|
|
$event = $this->createEventFromGhost(
|
2015-08-02 00:43:14 +02:00
|
|
|
$viewer,
|
2015-06-06 22:03:21 +02:00
|
|
|
$event,
|
|
|
|
$sequence);
|
2015-08-02 00:43:14 +02:00
|
|
|
$event->applyViewerTimezone($viewer);
|
2015-06-06 22:03:21 +02:00
|
|
|
}
|
|
|
|
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
$xactions = array();
|
|
|
|
|
|
|
|
$xaction = id(new PhabricatorCalendarEventTransaction())
|
|
|
|
->setTransactionType(
|
|
|
|
PhabricatorCalendarEventTransaction::TYPE_CANCEL)
|
|
|
|
->setNewValue(!$is_cancelled);
|
|
|
|
|
|
|
|
$editor = id(new PhabricatorCalendarEventEditor())
|
2015-08-02 00:43:14 +02:00
|
|
|
->setActor($viewer)
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
->setContentSourceFromRequest($request)
|
|
|
|
->setContinueOnNoEffect(true)
|
|
|
|
->setContinueOnMissingFields(true);
|
|
|
|
|
|
|
|
try {
|
2015-06-06 22:03:21 +02:00
|
|
|
$editor->applyTransactions($event, array($xaction));
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
return id(new AphrontRedirectResponse())->setURI($cancel_uri);
|
|
|
|
} catch (PhabricatorApplicationTransactionValidationException $ex) {
|
|
|
|
$validation_exception = $ex;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($is_cancelled) {
|
2015-06-06 22:03:21 +02:00
|
|
|
if ($sequence || $is_parent_cancelled) {
|
|
|
|
$title = pht('Cannot Reinstate Instance');
|
2015-07-07 14:52:59 +02:00
|
|
|
$paragraph = pht(
|
|
|
|
'Cannot reinstate an instance of a cancelled recurring event.');
|
2015-06-06 22:03:21 +02:00
|
|
|
$cancel = pht('Cancel');
|
|
|
|
$submit = null;
|
2015-06-09 06:40:32 +02:00
|
|
|
} else if ($is_parent) {
|
2015-06-06 22:03:21 +02:00
|
|
|
$title = pht('Reinstate Recurrence');
|
2015-07-07 14:52:59 +02:00
|
|
|
$paragraph = pht(
|
|
|
|
'Reinstate the entire series of recurring events?');
|
|
|
|
$cancel = pht("Don't Reinstate Recurrence");
|
2015-06-06 22:03:21 +02:00
|
|
|
$submit = pht('Reinstate Recurrence');
|
|
|
|
} else {
|
|
|
|
$title = pht('Reinstate Event');
|
|
|
|
$paragraph = pht('Reinstate this event?');
|
2015-07-07 14:52:59 +02:00
|
|
|
$cancel = pht("Don't Reinstate Event");
|
2015-06-06 22:03:21 +02:00
|
|
|
$submit = pht('Reinstate Event');
|
|
|
|
}
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
} else {
|
2015-06-06 22:03:21 +02:00
|
|
|
if ($sequence) {
|
|
|
|
$title = pht('Cancel Instance');
|
2015-07-07 14:52:59 +02:00
|
|
|
$paragraph = pht(
|
|
|
|
'Cancel just this instance of a recurring event.');
|
|
|
|
$cancel = pht("Don't Cancel Instance");
|
2015-06-06 22:03:21 +02:00
|
|
|
$submit = pht('Cancel Instance');
|
2015-06-09 06:40:32 +02:00
|
|
|
} else if ($is_parent) {
|
2015-06-06 22:03:21 +02:00
|
|
|
$title = pht('Cancel Recurrence');
|
2015-07-07 14:52:59 +02:00
|
|
|
$paragraph = pht(
|
|
|
|
'Cancel the entire series of recurring events?');
|
|
|
|
$cancel = pht("Don't Cancel Recurrence");
|
2015-06-06 22:03:21 +02:00
|
|
|
$submit = pht('Cancel Recurrence');
|
|
|
|
} else {
|
|
|
|
$title = pht('Cancel Event');
|
2015-07-07 14:52:59 +02:00
|
|
|
$paragraph = pht(
|
|
|
|
'You can always reinstate the event later.');
|
|
|
|
$cancel = pht("Don't Cancel Event");
|
2015-06-06 22:03:21 +02:00
|
|
|
$submit = pht('Cancel Event');
|
|
|
|
}
|
Canceling calendar events should deactivate the event
Summary: Closes T7943, Canceling calendar event should deactivate the event instead of destroying data.
Test Plan: Create an event, cancel it, see changed status icon, query for active events, event should not appear, query for deactivated events, event should appear in results.
Reviewers: #blessed_reviewers, epriestley
Reviewed By: #blessed_reviewers, epriestley
Subscribers: Korvin, epriestley
Maniphest Tasks: T7943
Differential Revision: https://secure.phabricator.com/D12604
2015-04-29 17:39:39 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return $this->newDialog()
|
|
|
|
->setTitle($title)
|
|
|
|
->setValidationException($validation_exception)
|
|
|
|
->appendParagraph($paragraph)
|
|
|
|
->addCancelButton($cancel_uri, $cancel)
|
|
|
|
->addSubmitButton($submit);
|
|
|
|
}
|
|
|
|
}
|