Path: blob/master/src/applications/harbormaster/artifact/HarbormasterDrydockLeaseArtifact.php
12256 views
<?php12abstract class HarbormasterDrydockLeaseArtifact3extends HarbormasterArtifact {45public function getArtifactParameterSpecification() {6return array(7'drydockLeasePHID' => 'string',8);9}1011public function getArtifactParameterDescriptions() {12return array(13'drydockLeasePHID' => pht(14'Drydock working copy lease to create an artifact from.'),15);16}1718public function getArtifactDataExample() {19return array(20'drydockLeasePHID' => 'PHID-DRYL-abcdefghijklmnopqrst',21);22}2324public function renderArtifactSummary(PhabricatorUser $viewer) {25$artifact = $this->getBuildArtifact();26$lease_phid = $artifact->getProperty('drydockLeasePHID');27return $viewer->renderHandle($lease_phid);28}2930public function willCreateArtifact(PhabricatorUser $actor) {31// We don't load the lease here because it's expected that artifacts are32// created before leases actually exist. This guarantees that the leases33// will be cleaned up.34}3536public function loadArtifactLease(PhabricatorUser $viewer) {37$artifact = $this->getBuildArtifact();38$lease_phid = $artifact->getProperty('drydockLeasePHID');3940$lease = id(new DrydockLeaseQuery())41->setViewer($viewer)42->withPHIDs(array($lease_phid))43->executeOne();44if (!$lease) {45throw new Exception(46pht(47'Drydock lease PHID "%s" does not correspond to a valid lease.',48$lease_phid));49}5051return $lease;52}5354public function releaseArtifact(PhabricatorUser $actor) {55try {56$lease = $this->loadArtifactLease($actor);57} catch (Exception $ex) {58// If we can't load the lease, treat it as already released. Artifacts59// are generated before leases are queued, so it's possible to arrive60// here under normal conditions.61return;62}6364if (!$lease->canRelease()) {65return;66}6768$author_phid = $actor->getPHID();69if (!$author_phid) {70$author_phid = id(new PhabricatorHarbormasterApplication())->getPHID();71}7273$command = DrydockCommand::initializeNewCommand($actor)74->setTargetPHID($lease->getPHID())75->setAuthorPHID($author_phid)76->setCommand(DrydockCommand::COMMAND_RELEASE)77->save();7879$lease->scheduleUpdate();80}8182}838485