@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<HarbormasterBuildUnitMessage>
5 */
6final class HarbormasterBuildUnitMessageQuery
7 extends PhabricatorCursorPagedPolicyAwareQuery {
8
9 private $ids;
10 private $phids;
11 private $targetPHIDs;
12
13 public function withIDs(array $ids) {
14 $this->ids = $ids;
15 return $this;
16 }
17
18 public function withPHIDs(array $phids) {
19 $this->phids = $phids;
20 return $this;
21 }
22
23 public function withBuildTargetPHIDs(array $target_phids) {
24 $this->targetPHIDs = $target_phids;
25 return $this;
26 }
27
28 public function newResultObject() {
29 return new HarbormasterBuildUnitMessage();
30 }
31
32 protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
33 $where = parent::buildWhereClauseParts($conn);
34
35 if ($this->ids !== null) {
36 $where[] = qsprintf(
37 $conn,
38 'id IN (%Ld)',
39 $this->ids);
40 }
41
42 if ($this->phids !== null) {
43 $where[] = qsprintf(
44 $conn,
45 'phid in (%Ls)',
46 $this->phids);
47 }
48
49 if ($this->targetPHIDs !== null) {
50 $where[] = qsprintf(
51 $conn,
52 'buildTargetPHID in (%Ls)',
53 $this->targetPHIDs);
54 }
55
56 return $where;
57 }
58
59 protected function didFilterPage(array $messages) {
60 $indexes = array();
61 foreach ($messages as $message) {
62 $index = $message->getNameIndex();
63 if (strlen($index)) {
64 $indexes[$index] = $index;
65 }
66 }
67
68 if ($indexes) {
69 $map = HarbormasterString::newIndexMap($indexes);
70
71 foreach ($messages as $message) {
72 $index = $message->getNameIndex();
73
74 if (!strlen($index)) {
75 continue;
76 }
77
78 $name = idx($map, $index);
79 if ($name === null) {
80 $name = pht('Unknown Unit Message ("%s")', $index);
81 }
82
83 $message->setName($name);
84 }
85 }
86
87 return $messages;
88 }
89
90 public function getQueryApplicationClass() {
91 return PhabricatorHarbormasterApplication::class;
92 }
93
94}