@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 HarbormasterFileArtifact extends HarbormasterArtifact {
4
5 const ARTIFACTCONST = 'file';
6
7 public function getArtifactTypeName() {
8 return pht('File');
9 }
10
11 public function getArtifactTypeDescription() {
12 return pht(
13 'Stores a reference to file data.');
14 }
15
16 public function getArtifactParameterSpecification() {
17 return array(
18 'filePHID' => 'string',
19 );
20 }
21
22 public function getArtifactParameterDescriptions() {
23 return array(
24 'filePHID' => pht('File to create an artifact from.'),
25 );
26 }
27
28 public function getArtifactDataExample() {
29 return array(
30 'filePHID' => 'PHID-FILE-abcdefghijklmnopqrst',
31 );
32 }
33
34 public function renderArtifactSummary(PhabricatorUser $viewer) {
35 $artifact = $this->getBuildArtifact();
36 $file_phid = $artifact->getProperty('filePHID');
37 return $viewer->renderHandle($file_phid);
38 }
39
40 public function willCreateArtifact(PhabricatorUser $actor) {
41 // NOTE: This is primarily making sure the actor has permission to view the
42 // file. We don't want to let you run builds using files you don't have
43 // permission to see, since this could let you violate permissions.
44 $this->loadArtifactFile($actor);
45 }
46
47 public function loadArtifactFile(PhabricatorUser $viewer) {
48 $artifact = $this->getBuildArtifact();
49 $file_phid = $artifact->getProperty('filePHID');
50
51 $file = id(new PhabricatorFileQuery())
52 ->setViewer($viewer)
53 ->withPHIDs(array($file_phid))
54 ->executeOne();
55 if (!$file) {
56 throw new Exception(
57 pht(
58 'File PHID "%s" does not correspond to a valid file.',
59 $file_phid));
60 }
61
62 return $file;
63 }
64
65}