@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
3final class HarbormasterArtifactSearchEngine
4 extends PhabricatorApplicationSearchEngine {
5
6 public function getResultTypeDescription() {
7 return pht('Harbormaster Artifacts');
8 }
9
10 public function getApplicationClassName() {
11 return PhabricatorHarbormasterApplication::class;
12 }
13
14 public function newQuery() {
15 return new HarbormasterBuildArtifactQuery();
16 }
17
18 protected function buildCustomSearchFields() {
19 return array(
20 id(new PhabricatorPHIDsSearchField())
21 ->setLabel(pht('Targets'))
22 ->setKey('buildTargetPHIDs')
23 ->setAliases(
24 array(
25 'buildTargetPHID',
26 'buildTargets',
27 'buildTarget',
28 'targetPHIDs',
29 'targetPHID',
30 'targets',
31 'target',
32 ))
33 ->setDescription(
34 pht('Search for artifacts attached to particular build targets.')),
35 );
36 }
37
38 protected function buildQueryFromParameters(array $map) {
39 $query = $this->newQuery();
40
41 if ($map['buildTargetPHIDs']) {
42 $query->withBuildTargetPHIDs($map['buildTargetPHIDs']);
43 }
44
45 return $query;
46 }
47
48 protected function getURI($path) {
49 return '/harbormaster/artifact/'.$path;
50 }
51
52 protected function getBuiltinQueryNames() {
53 return array(
54 'all' => pht('All Artifacts'),
55 );
56 }
57
58 public function buildSavedQueryFromBuiltin($query_key) {
59 $query = $this->newSavedQuery();
60 $query->setQueryKey($query_key);
61
62 switch ($query_key) {
63 case 'all':
64 return $query;
65 }
66
67 return parent::buildSavedQueryFromBuiltin($query_key);
68 }
69
70 /**
71 * @param array<HarbormasterBuildArtifact> $artifacts
72 * @param PhabricatorSavedQuery $query
73 * @param array<PhabricatorObjectHandle> $handles
74 */
75 protected function renderResultList(
76 array $artifacts,
77 PhabricatorSavedQuery $query,
78 array $handles) {
79 assert_instances_of($artifacts, HarbormasterBuildArtifact::class);
80
81 $viewer = $this->requireViewer();
82
83 $list = new PHUIObjectItemListView();
84 foreach ($artifacts as $artifact) {
85 $id = $artifact->getID();
86
87 $item = id(new PHUIObjectItemView())
88 ->setObjectName(pht('Artifact %d', $id));
89
90 $list->addItem($item);
91 }
92
93 return id(new PhabricatorApplicationSearchResultView())
94 ->setObjectList($list)
95 ->setNoDataString(pht('No artifacts found.'));
96 }
97
98}