2012-11-22 02:27:20 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @group pholio
|
|
|
|
*/
|
|
|
|
final class PholioMockCommentController extends PholioController {
|
|
|
|
|
|
|
|
private $id;
|
|
|
|
|
|
|
|
public function willProcessRequest(array $data) {
|
|
|
|
$this->id = $data['id'];
|
|
|
|
}
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
$request = $this->getRequest();
|
|
|
|
$user = $request->getUser();
|
|
|
|
|
|
|
|
$mock = id(new PholioMockQuery())
|
|
|
|
->setViewer($user)
|
|
|
|
->withIDs(array($this->id))
|
|
|
|
->executeOne();
|
|
|
|
|
|
|
|
if (!$mock) {
|
|
|
|
return new Aphront404Response();
|
|
|
|
}
|
|
|
|
|
|
|
|
$mock_uri = '/M'.$mock->getID();
|
|
|
|
|
|
|
|
$comment = $request->getStr('comment');
|
|
|
|
if (!strlen($comment)) {
|
|
|
|
$dialog = id(new AphrontDialogView())
|
|
|
|
->setUser($user)
|
|
|
|
->setTitle(pht('Empty Comment'))
|
|
|
|
->appendChild('You did not provide a comment!')
|
|
|
|
->addCancelButton($mock_uri);
|
|
|
|
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
|
|
}
|
|
|
|
|
|
|
|
$content_source = PhabricatorContentSource::newForSource(
|
|
|
|
PhabricatorContentSource::SOURCE_WEB,
|
|
|
|
array(
|
|
|
|
'ip' => $request->getRemoteAddr(),
|
|
|
|
));
|
|
|
|
|
2012-12-11 23:02:29 +01:00
|
|
|
$xactions = array();
|
|
|
|
$xactions[] = id(new PholioTransaction())
|
2012-12-11 22:59:20 +01:00
|
|
|
->setTransactionType(PhabricatorTransactions::TYPE_COMMENT)
|
|
|
|
->attachComment(
|
|
|
|
id(new PholioTransactionComment())
|
|
|
|
->setContent($comment));
|
2012-11-22 02:27:20 +01:00
|
|
|
|
2012-11-22 02:27:44 +01:00
|
|
|
id(new PholioMockEditor())
|
|
|
|
->setActor($user)
|
|
|
|
->setContentSource($content_source)
|
2012-12-11 23:02:29 +01:00
|
|
|
->applyTransactions($mock, $xactions);
|
2012-11-22 02:27:20 +01:00
|
|
|
|
2012-12-11 23:02:29 +01:00
|
|
|
if ($request->isAjax()) {
|
|
|
|
return id(new PhabricatorApplicationTransactionResponse())
|
|
|
|
->setViewer($user)
|
|
|
|
->setTransactions($xactions)
|
|
|
|
->setAnchorOffset($request->getStr('anchor'));
|
|
|
|
} else {
|
|
|
|
return id(new AphrontRedirectResponse())->setURI($mock_uri);
|
|
|
|
}
|
2012-11-22 02:27:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|