Differential D21687 Diff 51713 src/applications/harbormaster/editor/HarbormasterBuildTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/editor/HarbormasterBuildTransactionEditor.php
Show First 20 Lines • Show All 59 Lines • ▼ Show 20 Lines | protected function applyCustomInternalTransaction( | ||||
return parent::applyCustomInternalTransaction($object, $xaction); | return parent::applyCustomInternalTransaction($object, $xaction); | ||||
} | } | ||||
private function executeBuildCommand( | private function executeBuildCommand( | ||||
HarbormasterBuild $build, | HarbormasterBuild $build, | ||||
HarbormasterBuildTransaction $xaction) { | HarbormasterBuildTransaction $xaction) { | ||||
$command = $xaction->getNewValue(); | $actor = $this->getActor(); | ||||
$message_type = $xaction->getNewValue(); | |||||
switch ($command) { | // TODO: Restore logic that tests if the command can issue without causing | ||||
case HarbormasterBuildCommand::COMMAND_RESTART: | // anything to lapse into an invalid state. This should not be the same | ||||
$issuable = $build->canRestartBuild(); | // as the logic which powers the web UI: for example, if an "abort" is | ||||
// queued we want to disable "Abort" in the web UI, but should obviously | |||||
// process it here. | |||||
switch ($message_type) { | |||||
case HarbormasterBuildCommand::COMMAND_ABORT: | |||||
// TODO: This should move to external effects, perhaps. | |||||
$build->releaseAllArtifacts($actor); | |||||
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_ABORTED); | |||||
break; | break; | ||||
case HarbormasterBuildCommand::COMMAND_PAUSE: | case HarbormasterBuildCommand::COMMAND_RESTART: | ||||
$issuable = $build->canPauseBuild(); | $build->restartBuild($actor); | ||||
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING); | |||||
break; | break; | ||||
case HarbormasterBuildCommand::COMMAND_RESUME: | case HarbormasterBuildCommand::COMMAND_RESUME: | ||||
$issuable = $build->canResumeBuild(); | $build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING); | ||||
break; | break; | ||||
case HarbormasterBuildCommand::COMMAND_ABORT: | case HarbormasterBuildCommand::COMMAND_PAUSE: | ||||
$issuable = $build->canAbortBuild(); | $build->setBuildStatus(HarbormasterBuildStatus::STATUS_PAUSED); | ||||
break; | break; | ||||
default: | |||||
throw new Exception(pht('Unknown command %s', $command)); | |||||
} | } | ||||
if (!$issuable) { | |||||
return; | |||||
} | |||||
$actor = $this->getActor(); | |||||
if (!$build->canIssueCommand($actor, $command)) { | |||||
return; | |||||
} | |||||
HarbormasterBuildMessage::initializeNewMessage($actor) | |||||
->setAuthorPHID($xaction->getAuthorPHID()) | |||||
->setReceiverPHID($build->getPHID()) | |||||
->setType($command) | |||||
->save(); | |||||
PhabricatorWorker::scheduleTask( | |||||
'HarbormasterBuildWorker', | |||||
array( | |||||
'buildID' => $build->getID(), | |||||
), | |||||
array( | |||||
'objectPHID' => $build->getPHID(), | |||||
)); | |||||
} | } | ||||
protected function applyCustomExternalTransaction( | protected function applyCustomExternalTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
switch ($xaction->getTransactionType()) { | switch ($xaction->getTransactionType()) { | ||||
case HarbormasterBuildTransaction::TYPE_CREATE: | case HarbormasterBuildTransaction::TYPE_CREATE: | ||||
case HarbormasterBuildTransaction::TYPE_COMMAND: | case HarbormasterBuildTransaction::TYPE_COMMAND: | ||||
return; | return; | ||||
} | } | ||||
return parent::applyCustomExternalTransaction($object, $xaction); | return parent::applyCustomExternalTransaction($object, $xaction); | ||||
} | } | ||||
} | } |