@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3/**
4 * @extends PhabricatorCursorPagedPolicyAwareQuery<PhluxVariable>
5 */
6final class PhluxVariableQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $keys;
11 private $phids;
12
13 public function withIDs(array $ids) {
14 $this->ids = $ids;
15 return $this;
16 }
17
18 public function withPHIDs(array $phids) {
19 $this->phids = $phids;
20 return $this;
21 }
22
23 public function withKeys(array $keys) {
24 $this->keys = $keys;
25 return $this;
26 }
27
28 protected function loadPage() {
29 $table = new PhluxVariable();
30 $conn_r = $table->establishConnection('r');
31
32 $rows = queryfx_all(
33 $conn_r,
34 'SELECT * FROM %T %Q %Q %Q',
35 $table->getTableName(),
36 $this->buildWhereClause($conn_r),
37 $this->buildOrderClause($conn_r),
38 $this->buildLimitClause($conn_r));
39
40 return $table->loadAllFromArray($rows);
41 }
42
43 protected function buildWhereClause(AphrontDatabaseConnection $conn) {
44 $where = array();
45
46 if ($this->ids !== null) {
47 $where[] = qsprintf(
48 $conn,
49 'id IN (%Ld)',
50 $this->ids);
51 }
52
53 if ($this->keys !== null) {
54 $where[] = qsprintf(
55 $conn,
56 'variableKey IN (%Ls)',
57 $this->keys);
58 }
59
60 if ($this->phids !== null) {
61 $where[] = qsprintf(
62 $conn,
63 'phid IN (%Ls)',
64 $this->phids);
65 }
66
67 $where[] = $this->buildPagingClause($conn);
68
69 return $this->formatWhereClause($conn, $where);
70 }
71
72 protected function getDefaultOrderVector() {
73 return array('key');
74 }
75
76 public function getOrderableColumns() {
77 return array(
78 'key' => array(
79 'column' => 'variableKey',
80 'type' => 'string',
81 'reverse' => true,
82 'unique' => true,
83 ),
84 );
85 }
86
87 protected function newPagingMapFromPartialObject($object) {
88 return array(
89 'id' => (int)$object->getID(),
90 'key' => $object->getVariableKey(),
91 );
92 }
93
94 public function getQueryApplicationClass() {
95 return PhabricatorPhluxApplication::class;
96 }
97
98}