Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / auth / query / PhabricatorAuthPasswordQuery.php
blob483936fb30c12d01e604ffc03ccf1b0c5d0aac44
1 <?php
3 final class PhabricatorAuthPasswordQuery
4 extends PhabricatorCursorPagedPolicyAwareQuery {
6 private $ids;
7 private $phids;
8 private $objectPHIDs;
9 private $passwordTypes;
10 private $isRevoked;
12 public function withIDs(array $ids) {
13 $this->ids = $ids;
14 return $this;
17 public function withPHIDs(array $phids) {
18 $this->phids = $phids;
19 return $this;
22 public function withObjectPHIDs(array $object_phids) {
23 $this->objectPHIDs = $object_phids;
24 return $this;
27 public function withPasswordTypes(array $types) {
28 $this->passwordTypes = $types;
29 return $this;
32 public function withIsRevoked($is_revoked) {
33 $this->isRevoked = $is_revoked;
34 return $this;
37 public function newResultObject() {
38 return new PhabricatorAuthPassword();
41 protected function loadPage() {
42 return $this->loadStandardPage($this->newResultObject());
45 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
46 $where = parent::buildWhereClauseParts($conn);
48 if ($this->ids !== null) {
49 $where[] = qsprintf(
50 $conn,
51 'id IN (%Ld)',
52 $this->ids);
55 if ($this->phids !== null) {
56 $where[] = qsprintf(
57 $conn,
58 'phid IN (%Ls)',
59 $this->phids);
62 if ($this->objectPHIDs !== null) {
63 $where[] = qsprintf(
64 $conn,
65 'objectPHID IN (%Ls)',
66 $this->objectPHIDs);
69 if ($this->passwordTypes !== null) {
70 $where[] = qsprintf(
71 $conn,
72 'passwordType IN (%Ls)',
73 $this->passwordTypes);
76 if ($this->isRevoked !== null) {
77 $where[] = qsprintf(
78 $conn,
79 'isRevoked = %d',
80 (int)$this->isRevoked);
83 return $where;
86 protected function willFilterPage(array $passwords) {
87 $object_phids = mpull($passwords, 'getObjectPHID');
89 $objects = id(new PhabricatorObjectQuery())
90 ->setViewer($this->getViewer())
91 ->setParentQuery($this)
92 ->withPHIDs($object_phids)
93 ->execute();
94 $objects = mpull($objects, null, 'getPHID');
96 foreach ($passwords as $key => $password) {
97 $object = idx($objects, $password->getObjectPHID());
98 if (!$object) {
99 unset($passwords[$key]);
100 $this->didRejectResult($password);
101 continue;
104 $password->attachObject($object);
107 return $passwords;
110 public function getQueryApplicationClass() {
111 return 'PhabricatorAuthApplication';