1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-14 10:52:41 +01:00
phorge-phorge/src/applications/legalpad/controller/LegalpadDocumentCommentController.php
Bob Trahan 70e7708aff Legalpad V0.1
Summary:
got some basics here --

 - can create document
   - creates document object and document body object and cross-reference
 - can update document
   - creates document body object and updates reference from document object
 - contributors stored correctly
   - a contributor is anyone who has created or updated a legal document
 - can subscribe to documents
 - can flag documents
 - can comment on documents
 - can query for documents based on creator and create range
 - uses basically modern stuff

Missing stuff --

 - T3488
 - T3483
 - T3482
 - T3481
 - T3480
 - T3479

Test Plan: TRUNCATED the database. From scratch made 3 legal docs. Verified versions and version were correct in document and document body database entries respectively. Left comments and verified versions and version did not update. Left updates and verified those updated versions and version. Flagged document and verified it showed up on homepage. Subscribed and verified transaction showed up.

Reviewers: epriestley

Reviewed By: epriestley

CC: chad, aran, Korvin

Maniphest Tasks: T3116

Differential Revision: https://secure.phabricator.com/D6351
2013-07-03 11:15:45 -07:00

81 lines
2.1 KiB
PHP

<?php
/**
* @group legalpad
*/
final class LegalpadDocumentCommentController extends LegalpadController {
private $id;
public function willProcessRequest(array $data) {
$this->id = $data['id'];
}
public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
if (!$request->isFormPost()) {
return new Aphront400Response();
}
$document = id(new LegalpadDocumentQuery())
->setViewer($user)
->withIDs(array($this->id))
->executeOne();
if (!$document) {
return new Aphront404Response();
}
$is_preview = $request->isPreviewRequest();
$draft = PhabricatorDraft::buildFromRequest($request);
$document_uri = $this->getApplicationURI('view/'.$document->getID());
$comment = $request->getStr('comment');
$xactions = array();
if (strlen($comment)) {
$xactions[] = id(new LegalpadTransaction())
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
->attachComment(
id(new LegalpadTransactionComment())
->setDocumentID($document->getID())
->setLineNumber(0)
->setLineLength(0)
->setContent($comment));
}
$editor = id(new LegalpadDocumentEditor())
->setActor($user)
->setContentSourceFromRequest($request)
->setContinueOnNoEffect($request->isContinueRequest())
->setIsPreview($is_preview);
try {
$xactions = $editor->applyTransactions($document, $xactions);
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
return id(new PhabricatorApplicationTransactionNoEffectResponse())
->setCancelURI($document_uri)
->setException($ex);
}
if ($draft) {
$draft->replaceOrDelete();
}
if ($request->isAjax()) {
return id(new PhabricatorApplicationTransactionResponse())
->setViewer($user)
->setTransactions($xactions)
->setIsPreview($is_preview)
->setAnchorOffset($request->getStr('anchor'));
} else {
return id(new AphrontRedirectResponse())->setURI($document_uri);
}
}
}