From 8668ecaf5416ac16a5bbe2cefa2c5f9eb84adb94 Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 7 Aug 2012 11:54:39 -0700 Subject: [PATCH] Make PhabricatorProjectQuery extend PhabricatorOffsetPagedQuery Summary: This class predates PhabricatorQuery; reduce code duplication. Test Plan: Loaded projects, ran conduit call with offset and limit. Reviewers: vrana, btrahan Reviewed By: vrana CC: aran Maniphest Tasks: T603 Differential Revision: https://secure.phabricator.com/D3180 --- .../project/query/PhabricatorProjectQuery.php | 43 ++----------------- 1 file changed, 4 insertions(+), 39 deletions(-) diff --git a/src/applications/project/query/PhabricatorProjectQuery.php b/src/applications/project/query/PhabricatorProjectQuery.php index cb28027046..4a87a723ca 100644 --- a/src/applications/project/query/PhabricatorProjectQuery.php +++ b/src/applications/project/query/PhabricatorProjectQuery.php @@ -16,7 +16,7 @@ * limitations under the License. */ -final class PhabricatorProjectQuery { +final class PhabricatorProjectQuery extends PhabricatorOffsetPagedQuery { private $ids; private $phids; @@ -29,9 +29,6 @@ final class PhabricatorProjectQuery { const STATUS_ACTIVE = 'status-active'; const STATUS_ARCHIVED = 'status-archived'; - private $limit; - private $offset; - private $needMembers; public function withIDs(array $ids) { @@ -49,16 +46,6 @@ final class PhabricatorProjectQuery { return $this; } - public function setLimit($limit) { - $this->limit = $limit; - return $this; - } - - public function setOffset($offset) { - $this->offset = $offset; - return $this; - } - public function withMemberPHIDs(array $member_phids) { $this->memberPHIDs = $member_phids; return $this; @@ -70,27 +57,11 @@ final class PhabricatorProjectQuery { } public function execute() { - $table = id(new PhabricatorProject()); + $table = new PhabricatorProject(); $conn_r = $table->establishConnection('r'); $where = $this->buildWhereClause($conn_r); $joins = $this->buildJoinsClause($conn_r); - - $limit = ''; - if ($this->limit) { - $limit = qsprintf( - $conn_r, - 'LIMIT %d, %d', - $this->offset, - $this->limit); - } else if ($this->offset) { - $limit = qsprintf( - $conn_r, - 'LIMIT %d, %d', - $this->offset, - PHP_INT_MAX); - } - $order = 'ORDER BY name'; $data = queryfx_all( @@ -100,7 +71,7 @@ final class PhabricatorProjectQuery { $joins, $where, $order, - $limit); + $this->buildLimitClause($conn_r)); $projects = $table->loadAllFromArray($data); @@ -169,13 +140,7 @@ final class PhabricatorProjectQuery { $this->phids); } - if ($where) { - $where = 'WHERE ('.implode(') AND (', $where).')'; - } else { - $where = ''; - } - - return $where; + return $this->formatWhereClause($where); } private function buildJoinsClause($conn_r) {