Differential D21690 Diff 51703 src/applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php
<?php | <?php | ||||
final class HarbormasterBuildMessageTransaction | abstract class HarbormasterBuildMessageTransaction | ||||
extends HarbormasterBuildTransactionType { | extends HarbormasterBuildTransactionType { | ||||
const TRANSACTIONTYPE = 'harbormaster:build:command'; | final public function generateOldValue($object) { | ||||
public function generateOldValue($object) { | |||||
return null; | return null; | ||||
} | } | ||||
public function getTitle() { | final public function getTransactionTypeForConduit($xaction) { | ||||
$new = $this->getNewValue(); | return 'message'; | ||||
switch ($new) { | |||||
case HarbormasterBuildCommand::COMMAND_RESTART: | |||||
return pht( | |||||
'%s restarted this build.', | |||||
$this->renderAuthor()); | |||||
case HarbormasterBuildCommand::COMMAND_ABORT: | |||||
return pht( | |||||
'%s aborted this build.', | |||||
$this->renderAuthor()); | |||||
case HarbormasterBuildCommand::COMMAND_RESUME: | |||||
return pht( | |||||
'%s resumed this build.', | |||||
$this->renderAuthor()); | |||||
case HarbormasterBuildCommand::COMMAND_PAUSE: | |||||
return pht( | |||||
'%s paused this build.', | |||||
$this->renderAuthor()); | |||||
} | |||||
return pht( | |||||
'%s issued an unknown command ("%s") to this build.', | |||||
$this->renderAuthor(), | |||||
$this->renderValue($new)); | |||||
} | |||||
public function getIcon() { | |||||
$new = $this->getNewValue(); | |||||
switch ($new) { | |||||
case HarbormasterBuildCommand::COMMAND_RESTART: | |||||
return 'fa-backward'; | |||||
case HarbormasterBuildCommand::COMMAND_RESUME: | |||||
return 'fa-play'; | |||||
case HarbormasterBuildCommand::COMMAND_PAUSE: | |||||
return 'fa-pause'; | |||||
case HarbormasterBuildCommand::COMMAND_ABORT: | |||||
return 'fa-exclamation-triangle'; | |||||
default: | |||||
return 'fa-question'; | |||||
} | |||||
} | } | ||||
public function getColor() { | final public function getFieldValuesForConduit($xaction, $data) { | ||||
$new = $this->getNewValue(); | return array( | ||||
'type' => $xaction->getNewValue(), | |||||
switch ($new) { | ); | ||||
case HarbormasterBuildCommand::COMMAND_PAUSE: | |||||
case HarbormasterBuildCommand::COMMAND_ABORT: | |||||
return 'red'; | |||||
} | } | ||||
return parent::getColor(); | final public static function getTransactionTypeForMessageType($message_type) { | ||||
$message_xactions = id(new PhutilClassMapQuery()) | |||||
->setAncestorClass(__CLASS__) | |||||
->execute(); | |||||
foreach ($message_xactions as $message_xaction) { | |||||
if ($message_xaction->getMessageType() === $message_type) { | |||||
return $message_xaction->getTransactionTypeConstant(); | |||||
} | } | ||||
public function getTransactionTypeForConduit($xaction) { | |||||
return 'message'; | |||||
} | } | ||||
public function getFieldValuesForConduit($xaction, $data) { | return null; | ||||
return array( | |||||
'type' => $xaction->getNewValue(), | |||||
); | |||||
} | } | ||||
abstract public function getMessageType(); | |||||
public function validateTransactions($object, array $xactions) { | public function validateTransactions($object, array $xactions) { | ||||
$errors = array(); | $errors = array(); | ||||
// TODO: Restore logic that tests if the command can issue without causing | // TODO: Restore logic that tests if the command can issue without causing | ||||
// anything to lapse into an invalid state. This should not be the same | // anything to lapse into an invalid state. This should not be the same | ||||
// as the logic which powers the web UI: for example, if an "abort" is | // 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 | // queued we want to disable "Abort" in the web UI, but should obviously | ||||
// process it here. | // process it here. | ||||
return $errors; | return $errors; | ||||
} | } | ||||
public function applyInternalEffects($object, $value) { | |||||
$actor = $this->getActor(); | |||||
$build = $object; | |||||
$new = $this->getNewValue(); | |||||
switch ($new) { | |||||
case HarbormasterBuildCommand::COMMAND_ABORT: | |||||
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_ABORTED); | |||||
break; | |||||
case HarbormasterBuildCommand::COMMAND_RESTART: | |||||
$build->restartBuild($actor); | |||||
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING); | |||||
break; | |||||
case HarbormasterBuildCommand::COMMAND_RESUME: | |||||
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING); | |||||
break; | |||||
case HarbormasterBuildCommand::COMMAND_PAUSE: | |||||
$build->setBuildStatus(HarbormasterBuildStatus::STATUS_PAUSED); | |||||
break; | |||||
} | |||||
} | |||||
public function applyExternalEffects($object, $value) { | |||||
$actor = $this->getActor(); | |||||
$build = $object; | |||||
$new = $this->getNewValue(); | |||||
switch ($new) { | |||||
case HarbormasterBuildCommand::COMMAND_ABORT: | |||||
$build->releaseAllArtifacts($actor); | |||||
break; | |||||
} | |||||
} | |||||
} | } |