@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 212 lines 4.8 kB view raw
1<?php 2 3/** 4 * @extends PhabricatorCursorPagedPolicyAwareQuery<HarbormasterBuildTarget> 5 */ 6final class HarbormasterBuildTargetQuery 7 extends PhabricatorCursorPagedPolicyAwareQuery { 8 9 private $ids; 10 private $phids; 11 private $buildPHIDs; 12 private $buildGenerations; 13 private $dateCreatedMin; 14 private $dateCreatedMax; 15 private $dateStartedMin; 16 private $dateStartedMax; 17 private $dateCompletedMin; 18 private $dateCompletedMax; 19 private $statuses; 20 21 private $needBuildSteps; 22 23 public function withIDs(array $ids) { 24 $this->ids = $ids; 25 return $this; 26 } 27 28 public function withPHIDs(array $phids) { 29 $this->phids = $phids; 30 return $this; 31 } 32 33 public function withBuildPHIDs(array $build_phids) { 34 $this->buildPHIDs = $build_phids; 35 return $this; 36 } 37 38 public function withBuildGenerations(array $build_generations) { 39 $this->buildGenerations = $build_generations; 40 return $this; 41 } 42 43 public function withDateCreatedBetween($min, $max) { 44 $this->dateCreatedMin = $min; 45 $this->dateCreatedMax = $max; 46 return $this; 47 } 48 49 public function withDateStartedBetween($min, $max) { 50 $this->dateStartedMin = $min; 51 $this->dateStartedMax = $max; 52 return $this; 53 } 54 55 public function withDateCompletedBetween($min, $max) { 56 $this->dateCompletedMin = $min; 57 $this->dateCompletedMax = $max; 58 return $this; 59 } 60 61 public function withTargetStatuses(array $statuses) { 62 $this->statuses = $statuses; 63 return $this; 64 } 65 66 public function needBuildSteps($need_build_steps) { 67 $this->needBuildSteps = $need_build_steps; 68 return $this; 69 } 70 71 public function newResultObject() { 72 return new HarbormasterBuildTarget(); 73 } 74 75 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { 76 $where = parent::buildWhereClauseParts($conn); 77 78 if ($this->ids !== null) { 79 $where[] = qsprintf( 80 $conn, 81 'id IN (%Ld)', 82 $this->ids); 83 } 84 85 if ($this->phids !== null) { 86 $where[] = qsprintf( 87 $conn, 88 'phid in (%Ls)', 89 $this->phids); 90 } 91 92 if ($this->buildPHIDs !== null) { 93 $where[] = qsprintf( 94 $conn, 95 'buildPHID in (%Ls)', 96 $this->buildPHIDs); 97 } 98 99 if ($this->buildGenerations !== null) { 100 $where[] = qsprintf( 101 $conn, 102 'buildGeneration in (%Ld)', 103 $this->buildGenerations); 104 } 105 106 if ($this->dateCreatedMin !== null) { 107 $where[] = qsprintf( 108 $conn, 109 'dateCreated >= %d', 110 $this->dateCreatedMin); 111 } 112 113 if ($this->dateCreatedMax !== null) { 114 $where[] = qsprintf( 115 $conn, 116 'dateCreated <= %d', 117 $this->dateCreatedMax); 118 } 119 120 if ($this->dateStartedMin !== null) { 121 $where[] = qsprintf( 122 $conn, 123 'dateStarted >= %d', 124 $this->dateStartedMin); 125 } 126 127 if ($this->dateStartedMax !== null) { 128 $where[] = qsprintf( 129 $conn, 130 'dateStarted <= %d', 131 $this->dateStartedMax); 132 } 133 134 if ($this->dateCompletedMin !== null) { 135 $where[] = qsprintf( 136 $conn, 137 'dateCompleted >= %d', 138 $this->dateCompletedMin); 139 } 140 141 if ($this->dateCompletedMax !== null) { 142 $where[] = qsprintf( 143 $conn, 144 'dateCompleted <= %d', 145 $this->dateCompletedMax); 146 } 147 148 if ($this->statuses !== null) { 149 $where[] = qsprintf( 150 $conn, 151 'targetStatus IN (%Ls)', 152 $this->statuses); 153 } 154 155 return $where; 156 } 157 158 protected function didFilterPage(array $page) { 159 if ($this->needBuildSteps) { 160 $step_phids = array(); 161 162 foreach ($page as $target) { 163 $step_phids[] = $target->getBuildStepPHID(); 164 } 165 166 $steps = id(new HarbormasterBuildStepQuery()) 167 ->setViewer($this->getViewer()) 168 ->setParentQuery($this) 169 ->withPHIDs($step_phids) 170 ->execute(); 171 172 $steps = mpull($steps, null, 'getPHID'); 173 174 foreach ($page as $target) { 175 $target->attachBuildStep( 176 idx($steps, $target->getBuildStepPHID())); 177 } 178 } 179 180 return $page; 181 } 182 183 protected function willFilterPage(array $page) { 184 $builds = array(); 185 186 $build_phids = array_filter(mpull($page, 'getBuildPHID')); 187 if ($build_phids) { 188 $builds = id(new PhabricatorObjectQuery()) 189 ->setViewer($this->getViewer()) 190 ->withPHIDs($build_phids) 191 ->setParentQuery($this) 192 ->execute(); 193 $builds = mpull($builds, null, 'getPHID'); 194 } 195 196 foreach ($page as $key => $build_target) { 197 $build_phid = $build_target->getBuildPHID(); 198 if (empty($builds[$build_phid])) { 199 unset($page[$key]); 200 continue; 201 } 202 $build_target->attachBuild($builds[$build_phid]); 203 } 204 205 return $page; 206 } 207 208 public function getQueryApplicationClass() { 209 return PhabricatorHarbormasterApplication::class; 210 } 211 212}