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 {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = idx($data, 'id');
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
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())
|
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
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->requireCapabilities(
|
|
|
|
array(
|
|
|
|
PhabricatorPolicyCapability::CAN_VIEW,
|
|
|
|
PhabricatorPolicyCapability::CAN_EDIT,
|
|
|
|
))
|
|
|
|
->executeOne();
|
|
|
|
|
2015-06-06 22:03:21 +02:00
|
|
|
if ($sequence) {
|
|
|
|
$parent_event = $event;
|
|
|
|
$event = $parent_event->generateNthGhost($sequence, $user);
|
|
|
|
$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(
|
|
|
|
$user,
|
|
|
|
$event,
|
|
|
|
$sequence);
|
|
|
|
$event->applyViewerTimezone($user);
|
|
|
|
}
|
|
|
|
|
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())
|
|
|
|
->setActor($user)
|
|
|
|
->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-01 23:54:43 +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-01 23:54:43 +02:00
|
|
|
$paragraph = pht('Reinstate the entire series ' .
|
|
|
|
'of recurring events?');
|
2015-06-06 22:03:21 +02:00
|
|
|
$cancel = pht('Don\'t Reinstate Recurrence');
|
|
|
|
$submit = pht('Reinstate Recurrence');
|
|
|
|
} else {
|
|
|
|
$title = pht('Reinstate Event');
|
|
|
|
$paragraph = pht('Reinstate this event?');
|
|
|
|
$cancel = pht('Don\'t Reinstate Event');
|
|
|
|
$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-01 23:54:43 +02:00
|
|
|
$paragraph = pht('Cancel just this instance ' .
|
|
|
|
'of a recurring event.');
|
2015-06-06 22:03:21 +02:00
|
|
|
$cancel = pht('Don\'t Cancel Instance');
|
|
|
|
$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-01 23:54:43 +02:00
|
|
|
$paragraph = pht('Cancel the entire series ' .
|
|
|
|
'of recurring events?');
|
2015-06-06 22:03:21 +02:00
|
|
|
$cancel = pht('Don\'t Cancel Recurrence');
|
|
|
|
$submit = pht('Cancel Recurrence');
|
|
|
|
} else {
|
|
|
|
$title = pht('Cancel Event');
|
2015-07-01 23:54:43 +02:00
|
|
|
$paragraph = pht('You can always reinstate ' .
|
|
|
|
'the event later.');
|
2015-06-06 22:03:21 +02:00
|
|
|
$cancel = pht('Don\'t Cancel Event');
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|