@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Merge the "HarbormasterBuildCommand" table into "HarbormasterBuildMessage"

Summary:
Ref T13072. These two similar tables don't make sense to keep separate. Instead, make Build a valid receiver for BuildMessage objects.

These tables are practically the same, so this is straightforward: just copy the rows in and then drop the old table.

(This table was trivial and ephemeral anyway, so I'm not bothering to do the usual "keep it around for a couple years just in case".)

Test Plan:
- Populated BuildCommand table, ran migration, saw Builds end up in the proper transitional state (e.g., pausing, aborting, restarting) with appropriate queued messages.
- Queued new messages by clicking UI buttons.
- Ran BuildWorkers, saw them process messages and mark them as consumed.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13072

Differential Revision: https://secure.phabricator.com/D21684

+26 -32
+4
resources/sql/autopatches/20210713.harborcommand.01.migrate.sql
··· 1 + INSERT IGNORE INTO {$NAMESPACE}_harbormaster.harbormaster_buildmessage 2 + (authorPHID, receiverPHID, type, isConsumed, dateCreated, dateModified) 3 + SELECT authorPHID, targetPHID, command, 0, dateCreated, dateModified 4 + FROM {$NAMESPACE}_harbormaster.harbormaster_buildcommand;
+1
resources/sql/autopatches/20210713.harborcommand.02.drop.sql
··· 1 + DROP TABLE IF EXISTS {$NAMESPACE}_harbormaster.harbormaster_buildcommand;
+1 -1
src/__phutil_library_map__.php
··· 7597 7597 'HarbormasterBuildArtifactPHIDType' => 'PhabricatorPHIDType', 7598 7598 'HarbormasterBuildArtifactQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 7599 7599 'HarbormasterBuildAutoplan' => 'Phobject', 7600 - 'HarbormasterBuildCommand' => 'HarbormasterDAO', 7600 + 'HarbormasterBuildCommand' => 'Phobject', 7601 7601 'HarbormasterBuildDependencyDatasource' => 'PhabricatorTypeaheadDatasource', 7602 7602 'HarbormasterBuildEngine' => 'Phobject', 7603 7603 'HarbormasterBuildFailureException' => 'Exception',
+3 -3
src/applications/harbormaster/editor/HarbormasterBuildTransactionEditor.php
··· 93 93 return; 94 94 } 95 95 96 - id(new HarbormasterBuildCommand()) 96 + HarbormasterBuildMessage::initializeNewMessage($actor) 97 97 ->setAuthorPHID($xaction->getAuthorPHID()) 98 - ->setTargetPHID($build->getPHID()) 99 - ->setCommand($command) 98 + ->setReceiverPHID($build->getPHID()) 99 + ->setType($command) 100 100 ->save(); 101 101 102 102 PhabricatorWorker::scheduleTask(
+3 -3
src/applications/harbormaster/query/HarbormasterBuildQuery.php
··· 104 104 } 105 105 106 106 $build_phids = mpull($page, 'getPHID'); 107 - $messages = id(new HarbormasterBuildCommand())->loadAllWhere( 108 - 'targetPHID IN (%Ls) ORDER BY id ASC', 107 + $messages = id(new HarbormasterBuildMessage())->loadAllWhere( 108 + 'receiverPHID IN (%Ls) AND isConsumed = 0 ORDER BY id ASC', 109 109 $build_phids); 110 - $messages = mgroup($messages, 'getTargetPHID'); 110 + $messages = mgroup($messages, 'getReceiverPHID'); 111 111 foreach ($page as $build) { 112 112 $unprocessed_messages = idx($messages, $build->getPHID(), array()); 113 113 $build->attachUnprocessedMessages($unprocessed_messages);
+2 -18
src/applications/harbormaster/storage/HarbormasterBuildCommand.php
··· 1 1 <?php 2 2 3 - final class HarbormasterBuildCommand extends HarbormasterDAO { 3 + final class HarbormasterBuildCommand 4 + extends Phobject { 4 5 5 6 const COMMAND_PAUSE = 'pause'; 6 7 const COMMAND_RESUME = 'resume'; 7 8 const COMMAND_RESTART = 'restart'; 8 9 const COMMAND_ABORT = 'abort'; 9 - 10 - protected $authorPHID; 11 - protected $targetPHID; 12 - protected $command; 13 - 14 - protected function getConfiguration() { 15 - return array( 16 - self::CONFIG_COLUMN_SCHEMA => array( 17 - 'command' => 'text128', 18 - ), 19 - self::CONFIG_KEY_SCHEMA => array( 20 - 'key_target' => array( 21 - 'columns' => array('targetPHID'), 22 - ), 23 - ), 24 - ) + parent::getConfiguration(); 25 - } 26 10 27 11 }
+12 -7
src/applications/harbormaster/storage/build/HarbormasterBuild.php
··· 230 230 } 231 231 232 232 public function attachUnprocessedMessages(array $messages) { 233 + assert_instances_of($messages, 'HarbormasterBuildMessage'); 233 234 $this->unprocessedMessages = $messages; 234 235 return $this; 235 236 } ··· 331 332 public function isPausing() { 332 333 $is_pausing = false; 333 334 foreach ($this->getUnprocessedMessages() as $message_object) { 334 - $message_type = $message_object->getCommand(); 335 + $message_type = $message_object->getType(); 335 336 switch ($message_type) { 336 337 case HarbormasterBuildCommand::COMMAND_PAUSE: 337 338 $is_pausing = true; ··· 352 353 public function isResuming() { 353 354 $is_resuming = false; 354 355 foreach ($this->getUnprocessedMessages() as $message_object) { 355 - $message_type = $message_object->getCommand(); 356 + $message_type = $message_object->getType(); 356 357 switch ($message_type) { 357 358 case HarbormasterBuildCommand::COMMAND_RESTART: 358 359 case HarbormasterBuildCommand::COMMAND_RESUME: ··· 373 374 public function isRestarting() { 374 375 $is_restarting = false; 375 376 foreach ($this->getUnprocessedMessages() as $message_object) { 376 - $message_type = $message_object->getCommand(); 377 + $message_type = $message_object->getType(); 377 378 switch ($message_type) { 378 379 case HarbormasterBuildCommand::COMMAND_RESTART: 379 380 $is_restarting = true; ··· 387 388 public function isAborting() { 388 389 $is_aborting = false; 389 390 foreach ($this->getUnprocessedMessages() as $message_object) { 390 - $message_type = $message_object->getCommand(); 391 + $message_type = $message_object->getType(); 391 392 switch ($message_type) { 392 393 case HarbormasterBuildCommand::COMMAND_ABORT: 393 394 $is_aborting = true; ··· 399 400 } 400 401 401 402 public function markUnprocessedMessagesAsProcessed() { 402 - // TODO: See T13072. This is a placeholder until BuildCommand and 403 - // BuildMessage merge. 404 - return $this->deleteUnprocessedMessages(); 403 + foreach ($this->getUnprocessedMessages() as $key => $message_object) { 404 + $message_object 405 + ->setIsConsumed(1) 406 + ->save(); 407 + } 408 + 409 + return $this; 405 410 } 406 411 407 412 public function deleteUnprocessedMessages() {