diff --git a/src/applications/ponder/controller/PonderAnswerPreviewController.php b/src/applications/ponder/controller/PonderAnswerPreviewController.php index 3b46580444..68f400dd0e 100644 --- a/src/applications/ponder/controller/PonderAnswerPreviewController.php +++ b/src/applications/ponder/controller/PonderAnswerPreviewController.php @@ -4,17 +4,19 @@ final class PonderAnswerPreviewController extends PonderController { public function processRequest() { - $request = $this->getRequest(); - $user = $request->getUser(); + $viewer = $request->getUser(); $question_id = $request->getInt('question_id'); - $question = PonderQuestionQuery::loadSingle($user, $question_id); + $question = id(new PonderQuestionQuery()) + ->setViewer($viewer) + ->withIDs(array($question_id)) + ->executeOne(); if (!$question) { return new Aphront404Response(); } - $author_phid = $user->getPHID(); + $author_phid = $viewer->getPHID(); $object_phids = array($author_phid); $handles = $this->loadViewerHandles($object_phids); @@ -27,7 +29,7 @@ final class PonderAnswerPreviewController ->setQuestion($question) ->setTarget($answer) ->setPreview(true) - ->setUser($user) + ->setUser($viewer) ->setHandles($handles) ->setAction(PonderLiterals::LITERAL_ANSWERED); diff --git a/src/applications/ponder/controller/PonderAnswerSaveController.php b/src/applications/ponder/controller/PonderAnswerSaveController.php index ce137b7628..97cadbe3cb 100644 --- a/src/applications/ponder/controller/PonderAnswerSaveController.php +++ b/src/applications/ponder/controller/PonderAnswerSaveController.php @@ -4,29 +4,31 @@ final class PonderAnswerSaveController extends PonderController { public function processRequest() { $request = $this->getRequest(); + $viewer = $request->getUser(); + if (!$request->isFormPost()) { return new Aphront400Response(); } - $user = $request->getUser(); $question_id = $request->getInt('question_id'); - $question = PonderQuestionQuery::loadSingle($user, $question_id); - + $question = id(new PonderQuestionQuery()) + ->setViewer($viewer) + ->withIDs(array($question_id)) + ->executeOne(); if (!$question) { return new Aphront404Response(); } $answer = $request->getStr('answer'); - // Only want answers with some non whitespace content if (!strlen(trim($answer))) { - $dialog = new AphrontDialogView(); - $dialog->setUser($request->getUser()); - $dialog->setTitle(pht('Empty Answer')); - $dialog->appendChild( - phutil_tag('p', array(), pht( - 'Your answer must not be empty.'))); - $dialog->addCancelButton('/Q'.$question_id); + $dialog = id(new AphrontDialogView()) + ->setUser($viewer) + ->setTitle(pht('Empty Answer')) + ->appendChild( + phutil_tag('p', array(), pht( + 'Your answer must not be empty.'))) + ->addCancelButton('/Q'.$question_id); return id(new AphrontDialogResponse())->setDialog($dialog); } @@ -40,13 +42,13 @@ final class PonderAnswerSaveController extends PonderController { $res = new PonderAnswer(); $res ->setContent($answer) - ->setAuthorPHID($user->getPHID()) + ->setAuthorPHID($viewer->getPHID()) ->setVoteCount(0) ->setQuestionID($question_id) ->setContentSource($content_source); id(new PonderAnswerEditor()) - ->setActor($user) + ->setActor($viewer) ->setQuestion($question) ->setAnswer($res) ->saveAnswer(); diff --git a/src/applications/ponder/controller/PonderCommentSaveController.php b/src/applications/ponder/controller/PonderCommentSaveController.php index 45c2539101..a3af847977 100644 --- a/src/applications/ponder/controller/PonderCommentSaveController.php +++ b/src/applications/ponder/controller/PonderCommentSaveController.php @@ -10,8 +10,10 @@ final class PonderCommentSaveController extends PonderController { $user = $request->getUser(); $question_id = $request->getInt('question_id'); - $question = PonderQuestionQuery::loadSingle($user, $question_id); - + $question = id(new PonderQuestionQuery()) + ->setViewer($user) + ->withIDs(array($question_id)) + ->executeOne(); if (!$question) { return new Aphront404Response(); } diff --git a/src/applications/ponder/controller/PonderQuestionViewController.php b/src/applications/ponder/controller/PonderQuestionViewController.php index 089dafc5de..f230db1818 100644 --- a/src/applications/ponder/controller/PonderQuestionViewController.php +++ b/src/applications/ponder/controller/PonderQuestionViewController.php @@ -13,7 +13,10 @@ final class PonderQuestionViewController extends PonderController { $request = $this->getRequest(); $user = $request->getUser(); - $question = PonderQuestionQuery::loadSingle($user, $this->questionID); + $question = id(new PonderQuestionQuery()) + ->setViewer($user) + ->withIDs(array($this->questionID)) + ->executeOne(); if (!$question) { return new Aphront404Response(); } diff --git a/src/applications/ponder/controller/PonderVoteSaveController.php b/src/applications/ponder/controller/PonderVoteSaveController.php index d4169f9f4b..2d1e39d9dd 100644 --- a/src/applications/ponder/controller/PonderVoteSaveController.php +++ b/src/applications/ponder/controller/PonderVoteSaveController.php @@ -21,7 +21,10 @@ final class PonderVoteSaveController extends PonderController { $target = null; if ($this->kind == "question") { - $target = PonderQuestionQuery::loadSingleByPHID($user, $phid); + $target = id(new PonderQuestionQuery()) + ->setViewer($user) + ->withPHIDs(array($phid)) + ->executeOne(); } else if ($this->kind == "answer") { $target = id(new PonderAnswerQuery()) ->setViewer($user) diff --git a/src/applications/ponder/query/PonderQuestionQuery.php b/src/applications/ponder/query/PonderQuestionQuery.php index 1fd093821c..ce671fa9f6 100644 --- a/src/applications/ponder/query/PonderQuestionQuery.php +++ b/src/applications/ponder/query/PonderQuestionQuery.php @@ -47,28 +47,6 @@ final class PonderQuestionQuery return $this; } - public static function loadSingle($viewer, $id) { - if (!$viewer) { - throw new Exception("Must set viewer when calling loadSingle"); - } - - return idx(id(new PonderQuestionQuery()) - ->setViewer($viewer) - ->withIDs(array($id)) - ->execute(), $id); - } - - public static function loadSingleByPHID($viewer, $phid) { - if (!$viewer) { - throw new Exception("Must set viewer when calling loadSingle"); - } - - return array_shift(id(new PonderQuestionQuery()) - ->withPHIDs(array($phid)) - ->setViewer($viewer) - ->execute()); - } - private function buildWhereClause(AphrontDatabaseConnection $conn_r) { $where = array();