mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-01 11:12:42 +01:00
Modularize "HarbormasterBuildableTransaction"
Summary: Ref T13072. Trivially convert this into a modular transaction type. Test Plan: Issued commands to a buildable. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13072 Differential Revision: https://secure.phabricator.com/D21694
This commit is contained in:
parent
706b91adf6
commit
346ffc51e1
6 changed files with 80 additions and 133 deletions
|
@ -1475,6 +1475,7 @@ phutil_register_library_map(array(
|
||||||
'HarbormasterBuildableEngine' => 'applications/harbormaster/engine/HarbormasterBuildableEngine.php',
|
'HarbormasterBuildableEngine' => 'applications/harbormaster/engine/HarbormasterBuildableEngine.php',
|
||||||
'HarbormasterBuildableInterface' => 'applications/harbormaster/interface/HarbormasterBuildableInterface.php',
|
'HarbormasterBuildableInterface' => 'applications/harbormaster/interface/HarbormasterBuildableInterface.php',
|
||||||
'HarbormasterBuildableListController' => 'applications/harbormaster/controller/HarbormasterBuildableListController.php',
|
'HarbormasterBuildableListController' => 'applications/harbormaster/controller/HarbormasterBuildableListController.php',
|
||||||
|
'HarbormasterBuildableMessageTransaction' => 'applications/harbormaster/xaction/buildable/HarbormasterBuildableMessageTransaction.php',
|
||||||
'HarbormasterBuildablePHIDType' => 'applications/harbormaster/phid/HarbormasterBuildablePHIDType.php',
|
'HarbormasterBuildablePHIDType' => 'applications/harbormaster/phid/HarbormasterBuildablePHIDType.php',
|
||||||
'HarbormasterBuildableQuery' => 'applications/harbormaster/query/HarbormasterBuildableQuery.php',
|
'HarbormasterBuildableQuery' => 'applications/harbormaster/query/HarbormasterBuildableQuery.php',
|
||||||
'HarbormasterBuildableSearchAPIMethod' => 'applications/harbormaster/conduit/HarbormasterBuildableSearchAPIMethod.php',
|
'HarbormasterBuildableSearchAPIMethod' => 'applications/harbormaster/conduit/HarbormasterBuildableSearchAPIMethod.php',
|
||||||
|
@ -1483,6 +1484,7 @@ phutil_register_library_map(array(
|
||||||
'HarbormasterBuildableTransaction' => 'applications/harbormaster/storage/HarbormasterBuildableTransaction.php',
|
'HarbormasterBuildableTransaction' => 'applications/harbormaster/storage/HarbormasterBuildableTransaction.php',
|
||||||
'HarbormasterBuildableTransactionEditor' => 'applications/harbormaster/editor/HarbormasterBuildableTransactionEditor.php',
|
'HarbormasterBuildableTransactionEditor' => 'applications/harbormaster/editor/HarbormasterBuildableTransactionEditor.php',
|
||||||
'HarbormasterBuildableTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildableTransactionQuery.php',
|
'HarbormasterBuildableTransactionQuery' => 'applications/harbormaster/query/HarbormasterBuildableTransactionQuery.php',
|
||||||
|
'HarbormasterBuildableTransactionType' => 'applications/harbormaster/xaction/buildable/HarbormasterBuildableTransactionType.php',
|
||||||
'HarbormasterBuildableViewController' => 'applications/harbormaster/controller/HarbormasterBuildableViewController.php',
|
'HarbormasterBuildableViewController' => 'applications/harbormaster/controller/HarbormasterBuildableViewController.php',
|
||||||
'HarbormasterBuildkiteBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterBuildkiteBuildStepImplementation.php',
|
'HarbormasterBuildkiteBuildStepImplementation' => 'applications/harbormaster/step/HarbormasterBuildkiteBuildStepImplementation.php',
|
||||||
'HarbormasterBuildkiteBuildableInterface' => 'applications/harbormaster/interface/HarbormasterBuildkiteBuildableInterface.php',
|
'HarbormasterBuildkiteBuildableInterface' => 'applications/harbormaster/interface/HarbormasterBuildkiteBuildableInterface.php',
|
||||||
|
@ -7730,14 +7732,16 @@ phutil_register_library_map(array(
|
||||||
'HarbormasterBuildableActionController' => 'HarbormasterController',
|
'HarbormasterBuildableActionController' => 'HarbormasterController',
|
||||||
'HarbormasterBuildableEngine' => 'Phobject',
|
'HarbormasterBuildableEngine' => 'Phobject',
|
||||||
'HarbormasterBuildableListController' => 'HarbormasterController',
|
'HarbormasterBuildableListController' => 'HarbormasterController',
|
||||||
|
'HarbormasterBuildableMessageTransaction' => 'HarbormasterBuildableTransactionType',
|
||||||
'HarbormasterBuildablePHIDType' => 'PhabricatorPHIDType',
|
'HarbormasterBuildablePHIDType' => 'PhabricatorPHIDType',
|
||||||
'HarbormasterBuildableQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
'HarbormasterBuildableQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||||
'HarbormasterBuildableSearchAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
'HarbormasterBuildableSearchAPIMethod' => 'PhabricatorSearchEngineAPIMethod',
|
||||||
'HarbormasterBuildableSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
'HarbormasterBuildableSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||||
'HarbormasterBuildableStatus' => 'Phobject',
|
'HarbormasterBuildableStatus' => 'Phobject',
|
||||||
'HarbormasterBuildableTransaction' => 'PhabricatorApplicationTransaction',
|
'HarbormasterBuildableTransaction' => 'PhabricatorModularTransaction',
|
||||||
'HarbormasterBuildableTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
|
'HarbormasterBuildableTransactionEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||||
'HarbormasterBuildableTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
'HarbormasterBuildableTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||||
|
'HarbormasterBuildableTransactionType' => 'PhabricatorModularTransactionType',
|
||||||
'HarbormasterBuildableViewController' => 'HarbormasterController',
|
'HarbormasterBuildableViewController' => 'HarbormasterController',
|
||||||
'HarbormasterBuildkiteBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
|
'HarbormasterBuildkiteBuildStepImplementation' => 'HarbormasterBuildStepImplementation',
|
||||||
'HarbormasterBuildkiteHookController' => 'HarbormasterController',
|
'HarbormasterBuildkiteHookController' => 'HarbormasterController',
|
||||||
|
|
|
@ -111,18 +111,14 @@ final class HarbormasterBuildableActionController
|
||||||
->setContinueOnNoEffect(true)
|
->setContinueOnNoEffect(true)
|
||||||
->setContinueOnMissingFields(true);
|
->setContinueOnMissingFields(true);
|
||||||
|
|
||||||
|
$xaction_type = HarbormasterBuildableMessageTransaction::TRANSACTIONTYPE;
|
||||||
|
|
||||||
$xaction = id(new HarbormasterBuildableTransaction())
|
$xaction = id(new HarbormasterBuildableTransaction())
|
||||||
->setTransactionType(HarbormasterBuildableTransaction::TYPE_COMMAND)
|
->setTransactionType($xaction_type)
|
||||||
->setNewValue($action);
|
->setNewValue($action);
|
||||||
|
|
||||||
$editor->applyTransactions($buildable, array($xaction));
|
$editor->applyTransactions($buildable, array($xaction));
|
||||||
|
|
||||||
$build_editor = id(new HarbormasterBuildTransactionEditor())
|
|
||||||
->setActor($viewer)
|
|
||||||
->setContentSourceFromRequest($request)
|
|
||||||
->setContinueOnNoEffect(true)
|
|
||||||
->setContinueOnMissingFields(true);
|
|
||||||
|
|
||||||
foreach ($can_send as $build) {
|
foreach ($can_send as $build) {
|
||||||
$build->sendMessage(
|
$build->sendMessage(
|
||||||
$viewer,
|
$viewer,
|
||||||
|
|
|
@ -11,60 +11,4 @@ final class HarbormasterBuildableTransactionEditor
|
||||||
return pht('Harbormaster Buildables');
|
return pht('Harbormaster Buildables');
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTransactionTypes() {
|
|
||||||
$types = parent::getTransactionTypes();
|
|
||||||
|
|
||||||
$types[] = HarbormasterBuildableTransaction::TYPE_COMMAND;
|
|
||||||
|
|
||||||
return $types;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getCustomTransactionOldValue(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case HarbormasterBuildableTransaction::TYPE_COMMAND:
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getCustomTransactionOldValue($object, $xaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function getCustomTransactionNewValue(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case HarbormasterBuildableTransaction::TYPE_COMMAND:
|
|
||||||
return $xaction->getNewValue();
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getCustomTransactionNewValue($object, $xaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function applyCustomInternalTransaction(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case HarbormasterBuildableTransaction::TYPE_COMMAND:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::applyCustomInternalTransaction($object, $xaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected function applyCustomExternalTransaction(
|
|
||||||
PhabricatorLiskDAO $object,
|
|
||||||
PhabricatorApplicationTransaction $xaction) {
|
|
||||||
|
|
||||||
switch ($xaction->getTransactionType()) {
|
|
||||||
case HarbormasterBuildableTransaction::TYPE_COMMAND:
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::applyCustomExternalTransaction($object, $xaction);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,9 +1,7 @@
|
||||||
<?php
|
<?php
|
||||||
|
|
||||||
final class HarbormasterBuildableTransaction
|
final class HarbormasterBuildableTransaction
|
||||||
extends PhabricatorApplicationTransaction {
|
extends PhabricatorModularTransaction {
|
||||||
|
|
||||||
const TYPE_COMMAND = 'harbormaster:buildable:command';
|
|
||||||
|
|
||||||
public function getApplicationName() {
|
public function getApplicationName() {
|
||||||
return 'harbormaster';
|
return 'harbormaster';
|
||||||
|
@ -13,72 +11,8 @@ final class HarbormasterBuildableTransaction
|
||||||
return HarbormasterBuildablePHIDType::TYPECONST;
|
return HarbormasterBuildablePHIDType::TYPECONST;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getTitle() {
|
public function getBaseTransactionClass() {
|
||||||
$author_phid = $this->getAuthorPHID();
|
return 'HarbormasterBuildableTransactionType';
|
||||||
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
|
|
||||||
switch ($this->getTransactionType()) {
|
|
||||||
case self::TYPE_COMMAND:
|
|
||||||
switch ($new) {
|
|
||||||
case HarbormasterBuildMessageRestartTransaction::MESSAGETYPE:
|
|
||||||
return pht(
|
|
||||||
'%s restarted this buildable.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
case HarbormasterBuildMessageResumeTransaction::MESSAGETYPE:
|
|
||||||
return pht(
|
|
||||||
'%s resumed this buildable.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
|
|
||||||
return pht(
|
|
||||||
'%s paused this buildable.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
case HarbormasterBuildMessageAbortTransaction::MESSAGETYPE:
|
|
||||||
return pht(
|
|
||||||
'%s aborted this buildable.',
|
|
||||||
$this->renderHandleLink($author_phid));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return parent::getTitle();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getIcon() {
|
|
||||||
$author_phid = $this->getAuthorPHID();
|
|
||||||
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
|
|
||||||
switch ($this->getTransactionType()) {
|
|
||||||
case self::TYPE_COMMAND:
|
|
||||||
switch ($new) {
|
|
||||||
case HarbormasterBuildMessageRestartTransaction::MESSAGETYPE:
|
|
||||||
return 'fa-backward';
|
|
||||||
case HarbormasterBuildMessageResumeTransaction::MESSAGETYPE:
|
|
||||||
return 'fa-play';
|
|
||||||
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
|
|
||||||
return 'fa-pause';
|
|
||||||
case HarbormasterBuildMessageAbortTransaction::MESSAGETYPE:
|
|
||||||
return 'fa-exclamation-triangle';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return parent::getIcon();
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getColor() {
|
|
||||||
$author_phid = $this->getAuthorPHID();
|
|
||||||
|
|
||||||
$old = $this->getOldValue();
|
|
||||||
$new = $this->getNewValue();
|
|
||||||
|
|
||||||
switch ($this->getTransactionType()) {
|
|
||||||
case self::TYPE_COMMAND:
|
|
||||||
switch ($new) {
|
|
||||||
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
|
|
||||||
return 'red';
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return parent::getColor();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,65 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
final class HarbormasterBuildableMessageTransaction
|
||||||
|
extends HarbormasterBuildableTransactionType {
|
||||||
|
|
||||||
|
const TRANSACTIONTYPE = 'harbormaster:buildable:command';
|
||||||
|
|
||||||
|
public function generateOldValue($object) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
$new = $this->getNewValue();
|
||||||
|
|
||||||
|
switch ($new) {
|
||||||
|
case HarbormasterBuildMessageRestartTransaction::MESSAGETYPE:
|
||||||
|
return pht(
|
||||||
|
'%s restarted this buildable.',
|
||||||
|
$this->renderAuthor());
|
||||||
|
case HarbormasterBuildMessageResumeTransaction::MESSAGETYPE:
|
||||||
|
return pht(
|
||||||
|
'%s resumed this buildable.',
|
||||||
|
$this->renderAuthor());
|
||||||
|
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
|
||||||
|
return pht(
|
||||||
|
'%s paused this buildable.',
|
||||||
|
$this->renderAuthor());
|
||||||
|
case HarbormasterBuildMessageAbortTransaction::MESSAGETYPE:
|
||||||
|
return pht(
|
||||||
|
'%s aborted this buildable.',
|
||||||
|
$this->renderAuthor());
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::getTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getIcon() {
|
||||||
|
$new = $this->getNewValue();
|
||||||
|
|
||||||
|
switch ($new) {
|
||||||
|
case HarbormasterBuildMessageRestartTransaction::MESSAGETYPE:
|
||||||
|
return 'fa-backward';
|
||||||
|
case HarbormasterBuildMessageResumeTransaction::MESSAGETYPE:
|
||||||
|
return 'fa-play';
|
||||||
|
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
|
||||||
|
return 'fa-pause';
|
||||||
|
case HarbormasterBuildMessageAbortTransaction::MESSAGETYPE:
|
||||||
|
return 'fa-exclamation-triangle';
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::getIcon();
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getColor() {
|
||||||
|
$new = $this->getNewValue();
|
||||||
|
|
||||||
|
switch ($new) {
|
||||||
|
case HarbormasterBuildMessagePauseTransaction::MESSAGETYPE:
|
||||||
|
return 'red';
|
||||||
|
}
|
||||||
|
|
||||||
|
return parent::getColor();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -0,0 +1,4 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
abstract class HarbormasterBuildableTransactionType
|
||||||
|
extends PhabricatorModularTransactionType {}
|
Loading…
Reference in a new issue