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();
|
|
|
|
$is_recurring = $event->getIsRecurring();
|
|
|
|
$instance_of = $event->getInstanceOfEventPHID();
|
|
|
|
|
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');
|
|
|
|
$paragraph = pht('Cannot reinstate an instance of a
|
|
|
|
cancelled recurring event.');
|
|
|
|
$cancel = pht('Cancel');
|
|
|
|
$submit = null;
|
|
|
|
} else if ($is_recurring && !$instance_of) {
|
|
|
|
$title = pht('Reinstate Recurrence');
|
|
|
|
$paragraph = pht('Reinstate the entire series
|
|
|
|
of recurring events?');
|
|
|
|
$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');
|
|
|
|
$paragraph = pht('Cancel just this instance
|
|
|
|
of a recurring event.');
|
|
|
|
$cancel = pht('Don\'t Cancel Instance');
|
|
|
|
$submit = pht('Cancel Instance');
|
|
|
|
} else if ($is_recurring && !$instance_of) {
|
|
|
|
$title = pht('Cancel Recurrence');
|
|
|
|
$paragraph = pht('Cancel the entire series
|
|
|
|
of recurring events?');
|
|
|
|
$cancel = pht('Don\'t Cancel Recurrence');
|
|
|
|
$submit = pht('Cancel Recurrence');
|
|
|
|
} else {
|
|
|
|
$title = pht('Cancel Event');
|
|
|
|
$paragraph = pht('You can always reinstate
|
|
|
|
the event later.');
|
|
|
|
$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);
|
|
|
|
}
|
|
|
|
}
|