Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / packages / query / PhabricatorPackagesPackageQuery.php
blob67cd3954c9914062c575a4c0129030df665f2efd
1 <?php
3 final class PhabricatorPackagesPackageQuery
4 extends PhabricatorPackagesQuery {
6 private $ids;
7 private $phids;
8 private $publisherPHIDs;
9 private $packageKeys;
10 private $fullKeys;
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 withPublisherPHIDs(array $phids) {
23 $this->publisherPHIDs = $phids;
24 return $this;
27 public function withPackageKeys(array $keys) {
28 $this->packageKeys = $keys;
29 return $this;
32 public function withFullKeys(array $keys) {
33 $this->fullKeys = $keys;
34 return $this;
37 public function withNameNgrams($ngrams) {
38 return $this->withNgramsConstraint(
39 new PhabricatorPackagesPackageNameNgrams(),
40 $ngrams);
43 public function newResultObject() {
44 return new PhabricatorPackagesPackage();
47 protected function loadPage() {
48 return $this->loadStandardPage($this->newResultObject());
51 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
52 $where = parent::buildWhereClauseParts($conn);
54 if ($this->ids !== null) {
55 $where[] = qsprintf(
56 $conn,
57 'p.id IN (%Ld)',
58 $this->ids);
61 if ($this->phids !== null) {
62 $where[] = qsprintf(
63 $conn,
64 'p.phid IN (%Ls)',
65 $this->phids);
68 if ($this->publisherPHIDs !== null) {
69 $where[] = qsprintf(
70 $conn,
71 'p.publisherPHID IN (%Ls)',
72 $this->publisherPHIDs);
75 if ($this->packageKeys !== null) {
76 $where[] = qsprintf(
77 $conn,
78 'p.packageKey IN (%Ls)',
79 $this->packageKeys);
82 if ($this->fullKeys !== null) {
83 $parts = $this->buildFullKeyClauseParts($conn, $this->fullKeys);
84 $where[] = qsprintf($conn, '%Q', $parts);
87 return $where;
90 protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) {
91 $joins = parent::buildJoinClauseParts($conn);
93 $join_publisher = ($this->fullKeys !== null);
94 if ($join_publisher) {
95 $publisher_table = new PhabricatorPackagesPublisher();
97 $joins[] = qsprintf(
98 $conn,
99 'JOIN %T u ON u.phid = p.publisherPHID',
100 $publisher_table->getTableName());
103 return $joins;
106 protected function willFilterPage(array $packages) {
107 $publisher_phids = mpull($packages, 'getPublisherPHID');
109 $publishers = id(new PhabricatorPackagesPublisherQuery())
110 ->setViewer($this->getViewer())
111 ->setParentQuery($this)
112 ->withPHIDs($publisher_phids)
113 ->execute();
114 $publishers = mpull($publishers, null, 'getPHID');
116 foreach ($packages as $key => $package) {
117 $publisher = idx($publishers, $package->getPublisherPHID());
119 if (!$publisher) {
120 unset($packages[$key]);
121 $this->didRejectResult($package);
122 continue;
125 $package->attachPublisher($publisher);
128 return $packages;
131 protected function getPrimaryTableAlias() {
132 return 'p';