Remove product literal strings in "pht()", part 6
[phabricator.git] / src / applications / harbormaster / artifact / HarbormasterDrydockLeaseArtifact.php
blobe7a2ac41e67b3c71b7504e3e614de336e7fa9bcd
1 <?php
3 abstract class HarbormasterDrydockLeaseArtifact
4 extends HarbormasterArtifact {
6 public function getArtifactParameterSpecification() {
7 return array(
8 'drydockLeasePHID' => 'string',
9 );
12 public function getArtifactParameterDescriptions() {
13 return array(
14 'drydockLeasePHID' => pht(
15 'Drydock working copy lease to create an artifact from.'),
19 public function getArtifactDataExample() {
20 return array(
21 'drydockLeasePHID' => 'PHID-DRYL-abcdefghijklmnopqrst',
25 public function renderArtifactSummary(PhabricatorUser $viewer) {
26 $artifact = $this->getBuildArtifact();
27 $lease_phid = $artifact->getProperty('drydockLeasePHID');
28 return $viewer->renderHandle($lease_phid);
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.
37 public function loadArtifactLease(PhabricatorUser $viewer) {
38 $artifact = $this->getBuildArtifact();
39 $lease_phid = $artifact->getProperty('drydockLeasePHID');
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));
52 return $lease;
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;
65 if (!$lease->canRelease()) {
66 return;
69 $author_phid = $actor->getPHID();
70 if (!$author_phid) {
71 $author_phid = id(new PhabricatorHarbormasterApplication())->getPHID();
74 $command = DrydockCommand::initializeNewCommand($actor)
75 ->setTargetPHID($lease->getPHID())
76 ->setAuthorPHID($author_phid)
77 ->setCommand(DrydockCommand::COMMAND_RELEASE)
78 ->save();
80 $lease->scheduleUpdate();