mirror of
https://we.phorge.it/source/phorge.git
synced 2024-11-13 18:32:41 +01:00
bad576db92
Summary: Add a `setViewer()` so that PHID loading doesn't throw. Also remove a period from a button because none of the others have one. Test Plan: Saved a comment successfully. Reviewers: epriestley Reviewed By: epriestley CC: aran, Korvin Differential Revision: https://secure.phabricator.com/D4202
57 lines
1.5 KiB
PHP
57 lines
1.5 KiB
PHP
<?php
|
|
|
|
final class PonderCommentSaveController extends PonderController {
|
|
|
|
public function processRequest() {
|
|
$request = $this->getRequest();
|
|
if (!$request->isFormPost()) {
|
|
return new Aphront400Response();
|
|
}
|
|
|
|
$user = $request->getUser();
|
|
$question_id = $request->getInt('question_id');
|
|
$question = PonderQuestionQuery::loadSingle($user, $question_id);
|
|
|
|
if (!$question) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$target = $request->getStr('target');
|
|
$objects = id(new PhabricatorObjectHandleData(array($target)))
|
|
->setViewer($user)
|
|
->loadHandles();
|
|
if (!$objects) {
|
|
return new Aphront404Response();
|
|
}
|
|
|
|
$content = $request->getStr('content');
|
|
|
|
if (!strlen(trim($content))) {
|
|
$dialog = new AphrontDialogView();
|
|
$dialog->setUser($request->getUser());
|
|
$dialog->setTitle('Empty comment');
|
|
$dialog->appendChild('<p>Your comment must not be empty.</p>');
|
|
$dialog->addCancelButton('/Q'.$question_id);
|
|
|
|
return id(new AphrontDialogResponse())->setDialog($dialog);
|
|
}
|
|
|
|
$res = new PonderComment();
|
|
$res
|
|
->setContent($content)
|
|
->setAuthorPHID($user->getPHID())
|
|
->setTargetPHID($target);
|
|
|
|
id(new PonderCommentEditor())
|
|
->setQuestion($question)
|
|
->setComment($res)
|
|
->setTargetPHID($target)
|
|
->setActor($user)
|
|
->save();
|
|
|
|
return id(new AphrontRedirectResponse())
|
|
->setURI(
|
|
id(new PhutilURI('/Q'. $question->getID())));
|
|
}
|
|
|
|
}
|