@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<PhabricatorAuthPassword>
5 */
6final class PhabricatorAuthPasswordQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $objectPHIDs;
12 private $passwordTypes;
13 private $isRevoked;
14
15 public function withIDs(array $ids) {
16 $this->ids = $ids;
17 return $this;
18 }
19
20 public function withPHIDs(array $phids) {
21 $this->phids = $phids;
22 return $this;
23 }
24
25 public function withObjectPHIDs(array $object_phids) {
26 $this->objectPHIDs = $object_phids;
27 return $this;
28 }
29
30 public function withPasswordTypes(array $types) {
31 $this->passwordTypes = $types;
32 return $this;
33 }
34
35 public function withIsRevoked($is_revoked) {
36 $this->isRevoked = $is_revoked;
37 return $this;
38 }
39
40 public function newResultObject() {
41 return new PhabricatorAuthPassword();
42 }
43
44 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
45 $where = parent::buildWhereClauseParts($conn);
46
47 if ($this->ids !== null) {
48 $where[] = qsprintf(
49 $conn,
50 'id IN (%Ld)',
51 $this->ids);
52 }
53
54 if ($this->phids !== null) {
55 $where[] = qsprintf(
56 $conn,
57 'phid IN (%Ls)',
58 $this->phids);
59 }
60
61 if ($this->objectPHIDs !== null) {
62 $where[] = qsprintf(
63 $conn,
64 'objectPHID IN (%Ls)',
65 $this->objectPHIDs);
66 }
67
68 if ($this->passwordTypes !== null) {
69 $where[] = qsprintf(
70 $conn,
71 'passwordType IN (%Ls)',
72 $this->passwordTypes);
73 }
74
75 if ($this->isRevoked !== null) {
76 $where[] = qsprintf(
77 $conn,
78 'isRevoked = %d',
79 (int)$this->isRevoked);
80 }
81
82 return $where;
83 }
84
85 protected function willFilterPage(array $passwords) {
86 $object_phids = mpull($passwords, 'getObjectPHID');
87
88 $objects = id(new PhabricatorObjectQuery())
89 ->setViewer($this->getViewer())
90 ->setParentQuery($this)
91 ->withPHIDs($object_phids)
92 ->execute();
93 $objects = mpull($objects, null, 'getPHID');
94
95 foreach ($passwords as $key => $password) {
96 $object = idx($objects, $password->getObjectPHID());
97 if (!$object) {
98 unset($passwords[$key]);
99 $this->didRejectResult($password);
100 continue;
101 }
102
103 $password->attachObject($object);
104 }
105
106 return $passwords;
107 }
108
109 public function getQueryApplicationClass() {
110 return PhabricatorAuthApplication::class;
111 }
112
113}