Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / ponder / controller / PonderAnswerSaveController.php
blob53e0f06ea6e4fe9f1bc70e2bb4aba6339cd5e276
1 <?php
3 final class PonderAnswerSaveController extends PonderController {
5 public function handleRequest(AphrontRequest $request) {
6 $viewer = $request->getViewer();
8 if (!$request->isFormPost()) {
9 return new Aphront400Response();
12 $question_id = $request->getInt('question_id');
13 $question = id(new PonderQuestionQuery())
14 ->setViewer($viewer)
15 ->withIDs(array($question_id))
16 ->needAnswers(true)
17 ->executeOne();
18 if (!$question) {
19 return new Aphront404Response();
22 $content = $request->getStr('answer');
24 if (!strlen(trim($content))) {
25 $dialog = id(new AphrontDialogView())
26 ->setUser($viewer)
27 ->setTitle(pht('Empty Answer'))
28 ->appendChild(
29 phutil_tag('p', array(), pht('Your answer must not be empty.')))
30 ->addCancelButton('/Q'.$question_id);
32 return id(new AphrontDialogResponse())->setDialog($dialog);
35 $answer = PonderAnswer::initializeNewAnswer($viewer, $question);
37 // Question Editor
39 $xactions = array();
40 $xactions[] = id(new PonderQuestionTransaction())
41 ->setTransactionType(PonderQuestionAnswerTransaction::TRANSACTIONTYPE)
42 ->setNewValue(
43 array(
44 '+' => array(
45 array('answer' => $answer),
47 ));
49 $editor = id(new PonderQuestionEditor())
50 ->setActor($viewer)
51 ->setContentSourceFromRequest($request);
53 $editor->applyTransactions($question, $xactions);
55 // Answer Editor
57 $template = id(new PonderAnswerTransaction());
58 $xactions = array();
60 $xactions[] = id(clone $template)
61 ->setTransactionType(PonderAnswerQuestionIDTransaction::TRANSACTIONTYPE)
62 ->setNewValue($question->getID());
64 $xactions[] = id(clone $template)
65 ->setTransactionType(PonderAnswerContentTransaction::TRANSACTIONTYPE)
66 ->setNewValue($content);
68 $editor = id(new PonderAnswerEditor())
69 ->setActor($viewer)
70 ->setContentSourceFromRequest($request)
71 ->setContinueOnNoEffect(true);
73 $editor->applyTransactions($answer, $xactions);
76 return id(new AphrontRedirectResponse())->setURI(
77 id(new PhutilURI('/Q'.$question->getID())));