@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<?php
2
3/**
4 * @extends PhabricatorCursorPagedPolicyAwareQuery<HarbormasterBuildLog>
5 */
6final class HarbormasterBuildLogQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $buildPHIDs;
12 private $buildTargetPHIDs;
13
14 public function withIDs(array $ids) {
15 $this->ids = $ids;
16 return $this;
17 }
18
19 public function withPHIDs(array $phids) {
20 $this->phids = $phids;
21 return $this;
22 }
23
24 public function withBuildTargetPHIDs(array $build_target_phids) {
25 $this->buildTargetPHIDs = $build_target_phids;
26 return $this;
27 }
28
29 public function newResultObject() {
30 return new HarbormasterBuildLog();
31 }
32
33 protected function willFilterPage(array $page) {
34 $build_targets = array();
35
36 $build_target_phids = array_filter(mpull($page, 'getBuildTargetPHID'));
37 if ($build_target_phids) {
38 $build_targets = id(new HarbormasterBuildTargetQuery())
39 ->setViewer($this->getViewer())
40 ->withPHIDs($build_target_phids)
41 ->setParentQuery($this)
42 ->execute();
43 $build_targets = mpull($build_targets, null, 'getPHID');
44 }
45
46 foreach ($page as $key => $build_log) {
47 $build_target_phid = $build_log->getBuildTargetPHID();
48 if (empty($build_targets[$build_target_phid])) {
49 unset($page[$key]);
50 continue;
51 }
52 $build_log->attachBuildTarget($build_targets[$build_target_phid]);
53 }
54
55 return $page;
56 }
57
58 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
59 $where = parent::buildWhereClauseParts($conn);
60
61 if ($this->ids !== null) {
62 $where[] = qsprintf(
63 $conn,
64 'id IN (%Ld)',
65 $this->ids);
66 }
67
68 if ($this->phids !== null) {
69 $where[] = qsprintf(
70 $conn,
71 'phid IN (%Ls)',
72 $this->phids);
73 }
74
75 if ($this->buildTargetPHIDs !== null) {
76 $where[] = qsprintf(
77 $conn,
78 'buildTargetPHID IN (%Ls)',
79 $this->buildTargetPHIDs);
80 }
81
82 return $where;
83 }
84
85 public function getQueryApplicationClass() {
86 return PhabricatorHarbormasterApplication::class;
87 }
88
89}