@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<PhabricatorUserEmail>
5 */
6final class PhabricatorPeopleUserEmailQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $userPhids;
12 private $isVerified;
13
14 public function withIDs(array $ids) {
15 $this->ids = $ids;
16 return $this;
17 }
18
19 public function withPHIDs(array $phids) {
20 $this->phids = $phids;
21 return $this;
22 }
23
24 /**
25 * With the specified User PHIDs.
26 * @param array<string|null> $phids User PHIDs
27 */
28 public function withUserPHIDs(array $phids) {
29 $this->userPhids = $phids;
30 return $this;
31 }
32
33 /**
34 * With a verified email or not.
35 * @param bool|null $verified
36 */
37 public function withIsVerified($verified) {
38 $this->isVerified = $verified;
39 return $this;
40 }
41
42 public function newResultObject() {
43 return new PhabricatorUserEmail();
44 }
45
46 protected function getPrimaryTableAlias() {
47 return 'email';
48 }
49
50 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
51 $where = parent::buildWhereClauseParts($conn);
52
53 if ($this->ids !== null) {
54 $where[] = qsprintf(
55 $conn,
56 'email.id IN (%Ld)',
57 $this->ids);
58 }
59
60 if ($this->phids !== null) {
61 $where[] = qsprintf(
62 $conn,
63 'email.phid IN (%Ls)',
64 $this->phids);
65 }
66
67 if ($this->userPhids !== null) {
68 $where[] = qsprintf(
69 $conn,
70 'email.userPHID IN (%Ls)',
71 $this->userPhids);
72 }
73
74 if ($this->isVerified !== null) {
75 $where[] = qsprintf(
76 $conn,
77 'email.isVerified = %d',
78 (int)$this->isVerified);
79 }
80
81 return $where;
82 }
83
84 protected function willLoadPage(array $page) {
85
86 $user_phids = mpull($page, 'getUserPHID');
87
88 $users = id(new PhabricatorPeopleQuery())
89 ->setViewer($this->getViewer())
90 ->setParentQuery($this)
91 ->withPHIDs($user_phids)
92 ->execute();
93 $users = mpull($users, null, 'getPHID');
94
95 foreach ($page as $key => $address) {
96 $user = idx($users, $address->getUserPHID());
97
98 if (!$user) {
99 unset($page[$key]);
100 $this->didRejectResult($address);
101 continue;
102 }
103
104 $address->attachUser($user);
105 }
106
107 return $page;
108 }
109
110 public function getQueryApplicationClass() {
111 return PhabricatorPeopleApplication::class;
112 }
113
114}