@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
at upstream/main 146 lines 3.3 kB view raw
1<?php 2 3/** 4 * @extends PhabricatorPackagesQuery<PhabricatorPackagesVersion> 5 */ 6final class PhabricatorPackagesVersionQuery 7 extends PhabricatorPackagesQuery { 8 9 private $ids; 10 private $phids; 11 private $packagePHIDs; 12 private $fullKeys; 13 private $names; 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 withPackagePHIDs(array $phids) { 26 $this->packagePHIDs = $phids; 27 return $this; 28 } 29 30 public function withFullKeys(array $keys) { 31 $this->fullKeys = $keys; 32 return $this; 33 } 34 35 public function withNames(array $names) { 36 $this->names = $names; 37 return $this; 38 } 39 40 public function withNameNgrams($ngrams) { 41 return $this->withNgramsConstraint( 42 new PhabricatorPackagesVersionNameNgrams(), 43 $ngrams); 44 } 45 46 public function newResultObject() { 47 return new PhabricatorPackagesVersion(); 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 'v.id IN (%Ld)', 57 $this->ids); 58 } 59 60 if ($this->phids !== null) { 61 $where[] = qsprintf( 62 $conn, 63 'v.phid IN (%Ls)', 64 $this->phids); 65 } 66 67 if ($this->packagePHIDs !== null) { 68 $where[] = qsprintf( 69 $conn, 70 'v.packagePHID IN (%Ls)', 71 $this->packagePHIDs); 72 } 73 74 if ($this->names !== null) { 75 $where[] = qsprintf( 76 $conn, 77 'v.name IN (%Ls)', 78 $this->names); 79 } 80 81 if ($this->fullKeys !== null) { 82 $parts = $this->buildFullKeyClauseParts($conn, $this->fullKeys); 83 $where[] = qsprintf($conn, '%Q', $parts); 84 } 85 86 return $where; 87 } 88 89 protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { 90 $joins = parent::buildJoinClauseParts($conn); 91 92 $join_publisher = ($this->fullKeys !== null); 93 $join_package = ($this->fullKeys !== null) || $join_publisher; 94 95 if ($join_package) { 96 $package_table = new PhabricatorPackagesPackage(); 97 98 $joins[] = qsprintf( 99 $conn, 100 'JOIN %T p ON v.packagePHID = p.phid', 101 $package_table->getTableName()); 102 } 103 104 if ($join_publisher) { 105 $publisher_table = new PhabricatorPackagesPublisher(); 106 107 $joins[] = qsprintf( 108 $conn, 109 'JOIN %T u ON u.phid = p.publisherPHID', 110 $publisher_table->getTableName()); 111 } 112 113 return $joins; 114 } 115 116 protected function willFilterPage(array $versions) { 117 $package_phids = mpull($versions, 'getPackagePHID'); 118 119 $packages = id(new PhabricatorPackagesPackageQuery()) 120 ->setViewer($this->getViewer()) 121 ->setParentQuery($this) 122 ->withPHIDs($package_phids) 123 ->execute(); 124 $packages = mpull($packages, null, 'getPHID'); 125 126 foreach ($versions as $key => $version) { 127 $package = idx($packages, $version->getPackagePHID()); 128 129 if (!$package) { 130 unset($versions[$key]); 131 $this->didRejectResult($version); 132 continue; 133 } 134 135 $version->attachPackage($package); 136 } 137 138 return $versions; 139 } 140 141 protected function getPrimaryTableAlias() { 142 return 'v'; 143 } 144 145 146}