@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
fork

Configure Feed

Select the types of activity you want to include in your feed.

at recaptime-dev/main 183 lines 4.5 kB view raw
1<?php 2 3/** 4 * @extends PhabricatorCursorPagedPolicyAwareQuery<HarbormasterBuildable> 5 */ 6final class HarbormasterBuildableQuery 7 extends PhabricatorCursorPagedPolicyAwareQuery { 8 9 private $ids; 10 private $phids; 11 private $buildablePHIDs; 12 private $containerPHIDs; 13 private $statuses; 14 private $manualBuildables; 15 16 private $needContainerObjects; 17 private $needBuilds; 18 private $needTargets; 19 20 public function withIDs(array $ids) { 21 $this->ids = $ids; 22 return $this; 23 } 24 25 public function withPHIDs(array $phids) { 26 $this->phids = $phids; 27 return $this; 28 } 29 30 public function withBuildablePHIDs(array $buildable_phids) { 31 $this->buildablePHIDs = $buildable_phids; 32 return $this; 33 } 34 35 public function withContainerPHIDs(array $container_phids) { 36 $this->containerPHIDs = $container_phids; 37 return $this; 38 } 39 40 public function withManualBuildables($manual) { 41 $this->manualBuildables = $manual; 42 return $this; 43 } 44 45 public function needContainerObjects($need) { 46 $this->needContainerObjects = $need; 47 return $this; 48 } 49 50 public function withStatuses(array $statuses) { 51 $this->statuses = $statuses; 52 return $this; 53 } 54 55 public function needBuilds($need) { 56 $this->needBuilds = $need; 57 return $this; 58 } 59 60 public function needTargets($need) { 61 $this->needTargets = $need; 62 return $this; 63 } 64 65 public function newResultObject() { 66 return new HarbormasterBuildable(); 67 } 68 69 protected function willFilterPage(array $page) { 70 $buildables = array(); 71 72 $buildable_phids = array_filter(mpull($page, 'getBuildablePHID')); 73 if ($buildable_phids) { 74 $buildables = id(new PhabricatorObjectQuery()) 75 ->setViewer($this->getViewer()) 76 ->withPHIDs($buildable_phids) 77 ->setParentQuery($this) 78 ->execute(); 79 $buildables = mpull($buildables, null, 'getPHID'); 80 } 81 82 foreach ($page as $key => $buildable) { 83 $buildable_phid = $buildable->getBuildablePHID(); 84 if (empty($buildables[$buildable_phid])) { 85 unset($page[$key]); 86 continue; 87 } 88 $buildable->attachBuildableObject($buildables[$buildable_phid]); 89 } 90 91 return $page; 92 } 93 94 protected function didFilterPage(array $page) { 95 if ($this->needContainerObjects) { 96 $container_phids = array_filter(mpull($page, 'getContainerPHID')); 97 98 if ($container_phids) { 99 $containers = id(new PhabricatorObjectQuery()) 100 ->setViewer($this->getViewer()) 101 ->withPHIDs($container_phids) 102 ->setParentQuery($this) 103 ->execute(); 104 $containers = mpull($containers, null, 'getPHID'); 105 } else { 106 $containers = array(); 107 } 108 109 foreach ($page as $key => $buildable) { 110 $container_phid = $buildable->getContainerPHID(); 111 $buildable->attachContainerObject(idx($containers, $container_phid)); 112 } 113 } 114 115 if ($this->needBuilds || $this->needTargets) { 116 $builds = id(new HarbormasterBuildQuery()) 117 ->setViewer($this->getViewer()) 118 ->setParentQuery($this) 119 ->withBuildablePHIDs(mpull($page, 'getPHID')) 120 ->needBuildTargets($this->needTargets) 121 ->execute(); 122 $builds = mgroup($builds, 'getBuildablePHID'); 123 foreach ($page as $key => $buildable) { 124 $buildable->attachBuilds(idx($builds, $buildable->getPHID(), array())); 125 } 126 } 127 128 return $page; 129 } 130 131 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 132 $where = parent::buildWhereClauseParts($conn); 133 134 if ($this->ids !== null) { 135 $where[] = qsprintf( 136 $conn, 137 'id IN (%Ld)', 138 $this->ids); 139 } 140 141 if ($this->phids !== null) { 142 $where[] = qsprintf( 143 $conn, 144 'phid IN (%Ls)', 145 $this->phids); 146 } 147 148 if ($this->buildablePHIDs !== null) { 149 $where[] = qsprintf( 150 $conn, 151 'buildablePHID IN (%Ls)', 152 $this->buildablePHIDs); 153 } 154 155 if ($this->containerPHIDs !== null) { 156 $where[] = qsprintf( 157 $conn, 158 'containerPHID in (%Ls)', 159 $this->containerPHIDs); 160 } 161 162 if ($this->statuses !== null) { 163 $where[] = qsprintf( 164 $conn, 165 'buildableStatus in (%Ls)', 166 $this->statuses); 167 } 168 169 if ($this->manualBuildables !== null) { 170 $where[] = qsprintf( 171 $conn, 172 'isManualBuildable = %d', 173 (int)$this->manualBuildables); 174 } 175 176 return $where; 177 } 178 179 public function getQueryApplicationClass() { 180 return PhabricatorHarbormasterApplication::class; 181 } 182 183}