mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-02 11:42:42 +01:00
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
This commit is contained in:
parent
b0fda3be25
commit
8668ecaf54
1 changed files with 4 additions and 39 deletions
|
@ -16,7 +16,7 @@
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
final class PhabricatorProjectQuery {
|
final class PhabricatorProjectQuery extends PhabricatorOffsetPagedQuery {
|
||||||
|
|
||||||
private $ids;
|
private $ids;
|
||||||
private $phids;
|
private $phids;
|
||||||
|
@ -29,9 +29,6 @@ final class PhabricatorProjectQuery {
|
||||||
const STATUS_ACTIVE = 'status-active';
|
const STATUS_ACTIVE = 'status-active';
|
||||||
const STATUS_ARCHIVED = 'status-archived';
|
const STATUS_ARCHIVED = 'status-archived';
|
||||||
|
|
||||||
private $limit;
|
|
||||||
private $offset;
|
|
||||||
|
|
||||||
private $needMembers;
|
private $needMembers;
|
||||||
|
|
||||||
public function withIDs(array $ids) {
|
public function withIDs(array $ids) {
|
||||||
|
@ -49,16 +46,6 @@ final class PhabricatorProjectQuery {
|
||||||
return $this;
|
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) {
|
public function withMemberPHIDs(array $member_phids) {
|
||||||
$this->memberPHIDs = $member_phids;
|
$this->memberPHIDs = $member_phids;
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -70,27 +57,11 @@ final class PhabricatorProjectQuery {
|
||||||
}
|
}
|
||||||
|
|
||||||
public function execute() {
|
public function execute() {
|
||||||
$table = id(new PhabricatorProject());
|
$table = new PhabricatorProject();
|
||||||
$conn_r = $table->establishConnection('r');
|
$conn_r = $table->establishConnection('r');
|
||||||
|
|
||||||
$where = $this->buildWhereClause($conn_r);
|
$where = $this->buildWhereClause($conn_r);
|
||||||
$joins = $this->buildJoinsClause($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';
|
$order = 'ORDER BY name';
|
||||||
|
|
||||||
$data = queryfx_all(
|
$data = queryfx_all(
|
||||||
|
@ -100,7 +71,7 @@ final class PhabricatorProjectQuery {
|
||||||
$joins,
|
$joins,
|
||||||
$where,
|
$where,
|
||||||
$order,
|
$order,
|
||||||
$limit);
|
$this->buildLimitClause($conn_r));
|
||||||
|
|
||||||
$projects = $table->loadAllFromArray($data);
|
$projects = $table->loadAllFromArray($data);
|
||||||
|
|
||||||
|
@ -169,13 +140,7 @@ final class PhabricatorProjectQuery {
|
||||||
$this->phids);
|
$this->phids);
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($where) {
|
return $this->formatWhereClause($where);
|
||||||
$where = 'WHERE ('.implode(') AND (', $where).')';
|
|
||||||
} else {
|
|
||||||
$where = '';
|
|
||||||
}
|
|
||||||
|
|
||||||
return $where;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private function buildJoinsClause($conn_r) {
|
private function buildJoinsClause($conn_r) {
|
||||||
|
|
Loading…
Reference in a new issue