From 7522b45ef2c3d5a1ce07ad803f1e9c5d47fc5c7e Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 26 Jul 2013 13:00:01 -0700 Subject: [PATCH] Clean up some PonderAnswer / PonderAnswerQuery cruft Summary: Ref T3578. Ref T2715. Clean up some cruft so we can use Application PHIDs for "ANSW" and eventually unbeta Ponder. Test Plan: Grep, voted on an answer. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2715, T3578 Differential Revision: https://secure.phabricator.com/D6580 --- .../controller/PonderVoteSaveController.php | 5 +- .../ponder/query/PonderAnswerQuery.php | 47 ++++++------------- .../ponder/storage/PonderAnswer.php | 12 ----- 3 files changed, 19 insertions(+), 45 deletions(-) diff --git a/src/applications/ponder/controller/PonderVoteSaveController.php b/src/applications/ponder/controller/PonderVoteSaveController.php index 5becd6fc56..24ef3c4c55 100644 --- a/src/applications/ponder/controller/PonderVoteSaveController.php +++ b/src/applications/ponder/controller/PonderVoteSaveController.php @@ -23,7 +23,10 @@ final class PonderVoteSaveController extends PonderController { if ($this->kind == "question") { $target = PonderQuestionQuery::loadSingleByPHID($user, $phid); } else if ($this->kind == "answer") { - $target = PonderAnswerQuery::loadSingleByPHID($user, $phid); + $target = id(new PonderAnswerQuery()) + ->setViewer($user) + ->withPHID($phid) + ->executeOne(); } if (!$target) { diff --git a/src/applications/ponder/query/PonderAnswerQuery.php b/src/applications/ponder/query/PonderAnswerQuery.php index e0ba550600..608c3c62e5 100644 --- a/src/applications/ponder/query/PonderAnswerQuery.php +++ b/src/applications/ponder/query/PonderAnswerQuery.php @@ -7,6 +7,21 @@ final class PonderAnswerQuery extends PhabricatorOffsetPagedQuery { private $authorPHID; private $orderNewest; + private $viewer; + + public function setViewer(PhabricatorUser $viewer) { + $this->viewer = $viewer; + return $this; + } + + public function getViewer() { + return $this->viewer; + } + + public function executeOne() { + return head($this->execute()); + } + public function withID($qid) { $this->id = $qid; return $this; @@ -27,38 +42,6 @@ final class PonderAnswerQuery extends PhabricatorOffsetPagedQuery { return $this; } - public static function loadByAuthor($viewer, $author_phid, $offset, $count) { - if (!$viewer) { - throw new Exception("Must set viewer when calling loadByAuthor"); - } - - return id(new PonderAnswerQuery()) - ->withAuthorPHID($author_phid) - ->setOffset($offset) - ->setLimit($count) - ->orderByNewest(true) - ->execute(); - } - - public static function loadSingle($viewer, $id) { - if (!$viewer) { - throw new Exception("Must set viewer when calling loadSingle"); - } - return idx(id(new PonderAnswerQuery()) - ->withID($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 PonderAnswerQuery()) - ->withPHID($phid) - ->execute()); - } - private function buildWhereClause($conn_r) { $where = array(); if ($this->id) { diff --git a/src/applications/ponder/storage/PonderAnswer.php b/src/applications/ponder/storage/PonderAnswer.php index 11490b2dae..fd4b0ad988 100644 --- a/src/applications/ponder/storage/PonderAnswer.php +++ b/src/applications/ponder/storage/PonderAnswer.php @@ -53,14 +53,6 @@ final class PonderAnswer extends PonderDAO ) + parent::getConfiguration(); } - public function setTitle($title) { - $this->title = $title; - if (!$this->getID()) { - $this->originalTitle = $title; - } - return $this; - } - public function generatePHID() { return PhabricatorPHID::generateNewPHID( PhabricatorPHIDConstants::PHID_TYPE_ANSW); @@ -75,10 +67,6 @@ final class PonderAnswer extends PonderDAO return PhabricatorContentSource::newFromSerialized($this->contentSource); } - public function getAnswers() { - return $this->loadRelatives(new PonderAnswer(), "questionID"); - } - public function getMarkupField() { return self::MARKUP_FIELD_CONTENT; }