Page Menu
Home
Phabricator
Search
Configure Global Search
Log In
Files
F14112639
D21690.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
12 KB
Referenced Files
None
Subscribers
None
D21690.diff
View Options
diff --git a/resources/sql/autopatches/20210715.harborcommand.01.xactions.php b/resources/sql/autopatches/20210715.harborcommand.01.xactions.php
new file mode 100644
--- /dev/null
+++ b/resources/sql/autopatches/20210715.harborcommand.01.xactions.php
@@ -0,0 +1,34 @@
+<?php
+
+// See T13072. Turn the old "process a command" transaction into modular
+// transactions that each handle one particular type of command.
+
+$xactions_table = new HarbormasterBuildTransaction();
+$xactions_conn = $xactions_table->establishConnection('w');
+$row_iterator = new LiskRawMigrationIterator(
+ $xactions_conn,
+ $xactions_table->getTableName());
+
+$map = array(
+ '"pause"' => 'message/pause',
+ '"abort"' => 'message/abort',
+ '"resume"' => 'message/resume',
+ '"restart"' => 'message/restart',
+);
+
+foreach ($row_iterator as $row) {
+ if ($row['transactionType'] !== 'harbormaster:build:command') {
+ continue;
+ }
+
+ $raw_value = $row['newValue'];
+
+ if (isset($map[$raw_value])) {
+ queryfx(
+ $xactions_conn,
+ 'UPDATE %R SET transactionType = %s WHERE id = %d',
+ $xactions_table,
+ $map[$raw_value],
+ $row['id']);
+ }
+}
diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1408,7 +1408,11 @@
'HarbormasterBuildLogView' => 'applications/harbormaster/view/HarbormasterBuildLogView.php',
'HarbormasterBuildLogViewController' => 'applications/harbormaster/controller/HarbormasterBuildLogViewController.php',
'HarbormasterBuildMessage' => 'applications/harbormaster/storage/HarbormasterBuildMessage.php',
+ 'HarbormasterBuildMessageAbortTransaction' => 'applications/harbormaster/xaction/build/HarbormasterBuildMessageAbortTransaction.php',
+ 'HarbormasterBuildMessagePauseTransaction' => 'applications/harbormaster/xaction/build/HarbormasterBuildMessagePauseTransaction.php',
'HarbormasterBuildMessageQuery' => 'applications/harbormaster/query/HarbormasterBuildMessageQuery.php',
+ 'HarbormasterBuildMessageRestartTransaction' => 'applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php',
+ 'HarbormasterBuildMessageResumeTransaction' => 'applications/harbormaster/xaction/build/HarbormasterBuildMessageResumeTransaction.php',
'HarbormasterBuildMessageTransaction' => 'applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php',
'HarbormasterBuildPHIDType' => 'applications/harbormaster/phid/HarbormasterBuildPHIDType.php',
'HarbormasterBuildPlan' => 'applications/harbormaster/storage/configuration/HarbormasterBuildPlan.php',
@@ -7629,7 +7633,11 @@
'PhabricatorPolicyInterface',
'PhabricatorDestructibleInterface',
),
+ 'HarbormasterBuildMessageAbortTransaction' => 'HarbormasterBuildMessageTransaction',
+ 'HarbormasterBuildMessagePauseTransaction' => 'HarbormasterBuildMessageTransaction',
'HarbormasterBuildMessageQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+ 'HarbormasterBuildMessageRestartTransaction' => 'HarbormasterBuildMessageTransaction',
+ 'HarbormasterBuildMessageResumeTransaction' => 'HarbormasterBuildMessageTransaction',
'HarbormasterBuildMessageTransaction' => 'HarbormasterBuildTransactionType',
'HarbormasterBuildPHIDType' => 'PhabricatorPHIDType',
'HarbormasterBuildPlan' => array(
diff --git a/src/applications/harbormaster/engine/HarbormasterBuildEngine.php b/src/applications/harbormaster/engine/HarbormasterBuildEngine.php
--- a/src/applications/harbormaster/engine/HarbormasterBuildEngine.php
+++ b/src/applications/harbormaster/engine/HarbormasterBuildEngine.php
@@ -124,12 +124,18 @@
$xactions = array();
- $message_xaction = HarbormasterBuildMessageTransaction::TRANSACTIONTYPE;
-
$messages = $build->getUnprocessedMessagesForApply();
foreach ($messages as $message) {
$message_type = $message->getType();
+ $message_xaction =
+ HarbormasterBuildMessageTransaction::getTransactionTypeForMessageType(
+ $message_type);
+
+ if (!$message_xaction) {
+ continue;
+ }
+
$xactions[] = $build->getApplicationTransactionTemplate()
->setAuthorPHID($message->getAuthorPHID())
->setTransactionType($message_xaction)
diff --git a/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageAbortTransaction.php b/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageAbortTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageAbortTransaction.php
@@ -0,0 +1,41 @@
+<?php
+
+final class HarbormasterBuildMessageAbortTransaction
+ extends HarbormasterBuildMessageTransaction {
+
+ const TRANSACTIONTYPE = 'message/abort';
+
+ public function getMessageType() {
+ return 'abort';
+ }
+
+ public function getTitle() {
+ return pht(
+ '%s aborted this build.',
+ $this->renderAuthor());
+ }
+
+ public function getIcon() {
+ return 'fa-exclamation-triangle';
+ }
+
+ public function getColor() {
+ return 'red';
+ }
+
+ public function applyInternalEffects($object, $value) {
+ $actor = $this->getActor();
+ $build = $object;
+
+ $build->setBuildStatus(HarbormasterBuildStatus::STATUS_ABORTED);
+ }
+
+ public function applyExternalEffects($object, $value) {
+ $actor = $this->getActor();
+ $build = $object;
+
+ $build->releaseAllArtifacts($actor);
+ }
+
+
+}
diff --git a/src/applications/harbormaster/xaction/build/HarbormasterBuildMessagePauseTransaction.php b/src/applications/harbormaster/xaction/build/HarbormasterBuildMessagePauseTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/harbormaster/xaction/build/HarbormasterBuildMessagePauseTransaction.php
@@ -0,0 +1,33 @@
+<?php
+
+final class HarbormasterBuildMessagePauseTransaction
+ extends HarbormasterBuildMessageTransaction {
+
+ const TRANSACTIONTYPE = 'message/pause';
+
+ public function getMessageType() {
+ return 'pause';
+ }
+
+ public function getTitle() {
+ return pht(
+ '%s paused this build.',
+ $this->renderAuthor());
+ }
+
+ public function getIcon() {
+ return 'fa-pause';
+ }
+
+ public function getColor() {
+ return 'red';
+ }
+
+ public function applyInternalEffects($object, $value) {
+ $actor = $this->getActor();
+ $build = $object;
+
+ $build->setBuildStatus(HarbormasterBuildStatus::STATUS_PAUSED);
+ }
+
+}
diff --git a/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php b/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageRestartTransaction.php
@@ -0,0 +1,30 @@
+<?php
+
+final class HarbormasterBuildMessageRestartTransaction
+ extends HarbormasterBuildMessageTransaction {
+
+ const TRANSACTIONTYPE = 'message/restart';
+
+ public function getMessageType() {
+ return 'restart';
+ }
+
+ public function getTitle() {
+ return pht(
+ '%s restarted this build.',
+ $this->renderAuthor());
+ }
+
+ public function getIcon() {
+ return 'fa-backward';
+ }
+
+ public function applyInternalEffects($object, $value) {
+ $actor = $this->getActor();
+ $build = $object;
+
+ $build->restartBuild($actor);
+ $build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING);
+ }
+
+}
diff --git a/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageResumeTransaction.php b/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageResumeTransaction.php
new file mode 100644
--- /dev/null
+++ b/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageResumeTransaction.php
@@ -0,0 +1,29 @@
+<?php
+
+final class HarbormasterBuildMessageResumeTransaction
+ extends HarbormasterBuildMessageTransaction {
+
+ const TRANSACTIONTYPE = 'message/resume';
+
+ public function getMessageType() {
+ return 'resume';
+ }
+
+ public function getTitle() {
+ return pht(
+ '%s resumed this build.',
+ $this->renderAuthor());
+ }
+
+ public function getIcon() {
+ return 'fa-play';
+ }
+
+ public function applyInternalEffects($object, $value) {
+ $actor = $this->getActor();
+ $build = $object;
+
+ $build->setBuildStatus(HarbormasterBuildStatus::STATUS_BUILDING);
+ }
+
+}
diff --git a/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php b/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php
--- a/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php
+++ b/src/applications/harbormaster/xaction/build/HarbormasterBuildMessageTransaction.php
@@ -1,80 +1,37 @@
<?php
-final class HarbormasterBuildMessageTransaction
+abstract class HarbormasterBuildMessageTransaction
extends HarbormasterBuildTransactionType {
- const TRANSACTIONTYPE = 'harbormaster:build:command';
-
- public function generateOldValue($object) {
+ final public function generateOldValue($object) {
return null;
}
- public function getTitle() {
- $new = $this->getNewValue();
-
- 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));
+ final public function getTransactionTypeForConduit($xaction) {
+ return 'message';
}
- 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';
- }
+ final public function getFieldValuesForConduit($xaction, $data) {
+ return array(
+ 'type' => $xaction->getNewValue(),
+ );
}
- public function getColor() {
- $new = $this->getNewValue();
+ final public static function getTransactionTypeForMessageType($message_type) {
+ $message_xactions = id(new PhutilClassMapQuery())
+ ->setAncestorClass(__CLASS__)
+ ->execute();
- switch ($new) {
- case HarbormasterBuildCommand::COMMAND_PAUSE:
- case HarbormasterBuildCommand::COMMAND_ABORT:
- return 'red';
+ foreach ($message_xactions as $message_xaction) {
+ if ($message_xaction->getMessageType() === $message_type) {
+ return $message_xaction->getTransactionTypeConstant();
+ }
}
- return parent::getColor();
+ return null;
}
- public function getTransactionTypeForConduit($xaction) {
- return 'message';
- }
-
- public function getFieldValuesForConduit($xaction, $data) {
- return array(
- 'type' => $xaction->getNewValue(),
- );
- }
+ abstract public function getMessageType();
public function validateTransactions($object, array $xactions) {
$errors = array();
@@ -88,41 +45,4 @@
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;
- }
- }
-
-
}
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Fri, Nov 29, 2:08 AM (10 h, 9 m)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
6803289
Default Alt Text
D21690.diff (12 KB)
Attached To
Mode
D21690: Modularize individual Harbormaster build messages
Attached
Detach File
Event Timeline
Log In to Comment