Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/artifact/HarbormasterDrydockLeaseArtifact.php
12256 views
1
<?php
2
3
abstract class HarbormasterDrydockLeaseArtifact
4
extends HarbormasterArtifact {
5
6
public function getArtifactParameterSpecification() {
7
return array(
8
'drydockLeasePHID' => 'string',
9
);
10
}
11
12
public function getArtifactParameterDescriptions() {
13
return array(
14
'drydockLeasePHID' => pht(
15
'Drydock working copy lease to create an artifact from.'),
16
);
17
}
18
19
public function getArtifactDataExample() {
20
return array(
21
'drydockLeasePHID' => 'PHID-DRYL-abcdefghijklmnopqrst',
22
);
23
}
24
25
public function renderArtifactSummary(PhabricatorUser $viewer) {
26
$artifact = $this->getBuildArtifact();
27
$lease_phid = $artifact->getProperty('drydockLeasePHID');
28
return $viewer->renderHandle($lease_phid);
29
}
30
31
public function willCreateArtifact(PhabricatorUser $actor) {
32
// We don't load the lease here because it's expected that artifacts are
33
// created before leases actually exist. This guarantees that the leases
34
// will be cleaned up.
35
}
36
37
public function loadArtifactLease(PhabricatorUser $viewer) {
38
$artifact = $this->getBuildArtifact();
39
$lease_phid = $artifact->getProperty('drydockLeasePHID');
40
41
$lease = id(new DrydockLeaseQuery())
42
->setViewer($viewer)
43
->withPHIDs(array($lease_phid))
44
->executeOne();
45
if (!$lease) {
46
throw new Exception(
47
pht(
48
'Drydock lease PHID "%s" does not correspond to a valid lease.',
49
$lease_phid));
50
}
51
52
return $lease;
53
}
54
55
public function releaseArtifact(PhabricatorUser $actor) {
56
try {
57
$lease = $this->loadArtifactLease($actor);
58
} catch (Exception $ex) {
59
// If we can't load the lease, treat it as already released. Artifacts
60
// are generated before leases are queued, so it's possible to arrive
61
// here under normal conditions.
62
return;
63
}
64
65
if (!$lease->canRelease()) {
66
return;
67
}
68
69
$author_phid = $actor->getPHID();
70
if (!$author_phid) {
71
$author_phid = id(new PhabricatorHarbormasterApplication())->getPHID();
72
}
73
74
$command = DrydockCommand::initializeNewCommand($actor)
75
->setTargetPHID($lease->getPHID())
76
->setAuthorPHID($author_phid)
77
->setCommand(DrydockCommand::COMMAND_RELEASE)
78
->save();
79
80
$lease->scheduleUpdate();
81
}
82
83
}
84
85