From 0f93d1ffe4501f16559a372e8674aeec5ef6794b Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 13 Jul 2021 14:19:07 -0700 Subject: [PATCH] Rename "HarbormasterBuild" methods to prepare for use of the "BuildMessages" table Summary: Ref T13072. Rename various "command" properties to "message" properties, to prepare for merging "HarbormasterCommand" into "HarbormasterMessage". This change only renames variables and methods and should not affect program behavior. Test Plan: Grepped for affected symbols, found no unmodified hits. Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam Maniphest Tasks: T13072 Differential Revision: https://secure.phabricator.com/D21683 --- .../engine/HarbormasterBuildEngine.php | 2 +- .../query/HarbormasterBuildQuery.php | 8 +-- .../storage/build/HarbormasterBuild.php | 56 ++++++++++--------- 3 files changed, 36 insertions(+), 30 deletions(-) diff --git a/src/applications/harbormaster/engine/HarbormasterBuildEngine.php b/src/applications/harbormaster/engine/HarbormasterBuildEngine.php index 447bd53704..60d3040e33 100644 --- a/src/applications/harbormaster/engine/HarbormasterBuildEngine.php +++ b/src/applications/harbormaster/engine/HarbormasterBuildEngine.php @@ -127,7 +127,7 @@ final class HarbormasterBuildEngine extends Phobject { $build->save(); } - $build->deleteUnprocessedCommands(); + $build->markUnprocessedMessagesAsProcessed(); if ($build->getBuildStatus() == HarbormasterBuildStatus::STATUS_BUILDING) { $this->updateBuildSteps($build); diff --git a/src/applications/harbormaster/query/HarbormasterBuildQuery.php b/src/applications/harbormaster/query/HarbormasterBuildQuery.php index 770ca4413b..3e474bd81d 100644 --- a/src/applications/harbormaster/query/HarbormasterBuildQuery.php +++ b/src/applications/harbormaster/query/HarbormasterBuildQuery.php @@ -104,13 +104,13 @@ final class HarbormasterBuildQuery } $build_phids = mpull($page, 'getPHID'); - $commands = id(new HarbormasterBuildCommand())->loadAllWhere( + $messages = id(new HarbormasterBuildCommand())->loadAllWhere( 'targetPHID IN (%Ls) ORDER BY id ASC', $build_phids); - $commands = mgroup($commands, 'getTargetPHID'); + $messages = mgroup($messages, 'getTargetPHID'); foreach ($page as $build) { - $unprocessed_commands = idx($commands, $build->getPHID(), array()); - $build->attachUnprocessedCommands($unprocessed_commands); + $unprocessed_messages = idx($messages, $build->getPHID(), array()); + $build->attachUnprocessedMessages($unprocessed_messages); } if ($this->needBuildTargets) { diff --git a/src/applications/harbormaster/storage/build/HarbormasterBuild.php b/src/applications/harbormaster/storage/build/HarbormasterBuild.php index 7af5af092f..292ccd99cf 100644 --- a/src/applications/harbormaster/storage/build/HarbormasterBuild.php +++ b/src/applications/harbormaster/storage/build/HarbormasterBuild.php @@ -18,7 +18,7 @@ final class HarbormasterBuild extends HarbormasterDAO private $buildable = self::ATTACHABLE; private $buildPlan = self::ATTACHABLE; private $buildTargets = self::ATTACHABLE; - private $unprocessedCommands = self::ATTACHABLE; + private $unprocessedMessages = self::ATTACHABLE; public static function initializeNewBuild(PhabricatorUser $actor) { return id(new HarbormasterBuild()) @@ -28,7 +28,7 @@ final class HarbormasterBuild extends HarbormasterDAO public function delete() { $this->openTransaction(); - $this->deleteUnprocessedCommands(); + $this->deleteUnprocessedMessages(); $result = parent::delete(); $this->saveTransaction(); @@ -222,15 +222,15 @@ final class HarbormasterBuild extends HarbormasterDAO } -/* -( Build Commands )----------------------------------------------------- */ +/* -( Build Messages )----------------------------------------------------- */ - private function getUnprocessedCommands() { - return $this->assertAttached($this->unprocessedCommands); + private function getUnprocessedMessages() { + return $this->assertAttached($this->unprocessedMessages); } - public function attachUnprocessedCommands(array $commands) { - $this->unprocessedCommands = $commands; + public function attachUnprocessedMessages(array $messages) { + $this->unprocessedMessages = $messages; return $this; } @@ -330,9 +330,9 @@ final class HarbormasterBuild extends HarbormasterDAO public function isPausing() { $is_pausing = false; - foreach ($this->getUnprocessedCommands() as $command_object) { - $command = $command_object->getCommand(); - switch ($command) { + foreach ($this->getUnprocessedMessages() as $message_object) { + $message_type = $message_object->getCommand(); + switch ($message_type) { case HarbormasterBuildCommand::COMMAND_PAUSE: $is_pausing = true; break; @@ -351,9 +351,9 @@ final class HarbormasterBuild extends HarbormasterDAO public function isResuming() { $is_resuming = false; - foreach ($this->getUnprocessedCommands() as $command_object) { - $command = $command_object->getCommand(); - switch ($command) { + foreach ($this->getUnprocessedMessages() as $message_object) { + $message_type = $message_object->getCommand(); + switch ($message_type) { case HarbormasterBuildCommand::COMMAND_RESTART: case HarbormasterBuildCommand::COMMAND_RESUME: $is_resuming = true; @@ -372,9 +372,9 @@ final class HarbormasterBuild extends HarbormasterDAO public function isRestarting() { $is_restarting = false; - foreach ($this->getUnprocessedCommands() as $command_object) { - $command = $command_object->getCommand(); - switch ($command) { + foreach ($this->getUnprocessedMessages() as $message_object) { + $message_type = $message_object->getCommand(); + switch ($message_type) { case HarbormasterBuildCommand::COMMAND_RESTART: $is_restarting = true; break; @@ -386,9 +386,9 @@ final class HarbormasterBuild extends HarbormasterDAO public function isAborting() { $is_aborting = false; - foreach ($this->getUnprocessedCommands() as $command_object) { - $command = $command_object->getCommand(); - switch ($command) { + foreach ($this->getUnprocessedMessages() as $message_object) { + $message_type = $message_object->getCommand(); + switch ($message_type) { case HarbormasterBuildCommand::COMMAND_ABORT: $is_aborting = true; break; @@ -398,10 +398,16 @@ final class HarbormasterBuild extends HarbormasterDAO return $is_aborting; } - public function deleteUnprocessedCommands() { - foreach ($this->getUnprocessedCommands() as $key => $command_object) { - $command_object->delete(); - unset($this->unprocessedCommands[$key]); + public function markUnprocessedMessagesAsProcessed() { + // TODO: See T13072. This is a placeholder until BuildCommand and + // BuildMessage merge. + return $this->deleteUnprocessedMessages(); + } + + public function deleteUnprocessedMessages() { + foreach ($this->getUnprocessedMessages() as $key => $message_object) { + $message_object->delete(); + unset($this->unprocessedMessages[$key]); } return $this; @@ -452,7 +458,7 @@ final class HarbormasterBuild extends HarbormasterDAO } } - public function sendMessage(PhabricatorUser $viewer, $command) { + public function sendMessage(PhabricatorUser $viewer, $message_type) { // TODO: This should not be an editor transaction, but there are plans to // merge BuildCommand into BuildMessage which should moot this. As this // exists today, it can race against BuildEngine. @@ -476,7 +482,7 @@ final class HarbormasterBuild extends HarbormasterDAO $xaction = id(new HarbormasterBuildTransaction()) ->setTransactionType(HarbormasterBuildTransaction::TYPE_COMMAND) - ->setNewValue($command); + ->setNewValue($message_type); $editor->applyTransactions($this, array($xaction)); }