1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-29 02:02:41 +01:00
phorge-phorge/src/applications/calendar/controller/PhabricatorCalendarEventCommentController.php
Chad Little 2ff4601584 Update Calendar for handleRequest
Summary: Run through Calendar and update/cleanup processRequest

Test Plan: New Event, Edit, etc.

Reviewers: epriestley

Reviewed By: epriestley

Subscribers: epriestley, Korvin

Maniphest Tasks: T8628

Differential Revision: https://secure.phabricator.com/D13747
2015-08-01 15:43:14 -07:00

81 lines
2.2 KiB
PHP

<?php
final class PhabricatorCalendarEventCommentController
extends PhabricatorCalendarController {
public function handleRequest(AphrontRequest $request) {
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$viewer = $request->getViewer();
$id = $request->getURIData('id');
$is_preview = $request->isPreviewRequest();
$draft = PhabricatorDraft::buildFromRequest($request);
$event = id(new PhabricatorCalendarEventQuery())
->setViewer($viewer)
->withIDs(array($id))
->executeOne();
if (!$event) {
return new Aphront404Response();
}
$index = $request->getURIData('sequence');
if ($index && !$is_preview) {
$result = $this->getEventAtIndexForGhostPHID(
$viewer,
$event->getPHID(),
$index);
if ($result) {
$event = $result;
} else {
$event = $this->createEventFromGhost(
$viewer,
$event,
$index);
$event->applyViewerTimezone($viewer);
}
}
$view_uri = '/'.$event->getMonogram();
$xactions = array();
$xactions[] = id(new PhabricatorCalendarEventTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
->attachComment(
id(new PhabricatorCalendarEventTransactionComment())
->setContent($request->getStr('comment')));
$editor = id(new PhabricatorCalendarEventEditor())
->setActor($viewer)
->setContinueOnNoEffect($request->isContinueRequest())
->setContentSourceFromRequest($request)
->setIsPreview($is_preview);
try {
$xactions = $editor->applyTransactions($event, $xactions);
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
return id(new PhabricatorApplicationTransactionNoEffectResponse())
->setCancelURI($view_uri)
->setException($ex);
}
if ($draft) {
$draft->replaceOrDelete();
}
if ($request->isAjax() && $is_preview) {
return id(new PhabricatorApplicationTransactionResponse())
->setViewer($viewer)
->setTransactions($xactions)
->setIsPreview($is_preview);
} else {
return id(new AphrontRedirectResponse())
->setURI($view_uri);
}
}
}