diff --git a/src/applications/harbormaster/conduit/HarbormasterSendMessageConduitAPIMethod.php b/src/applications/harbormaster/conduit/HarbormasterSendMessageConduitAPIMethod.php index dbf1f18cfa..fc83b7ab42 100644 --- a/src/applications/harbormaster/conduit/HarbormasterSendMessageConduitAPIMethod.php +++ b/src/applications/harbormaster/conduit/HarbormasterSendMessageConduitAPIMethod.php @@ -245,7 +245,7 @@ final class HarbormasterSendMessageConduitAPIMethod } $save[] = HarbormasterBuildMessage::initializeNewMessage($viewer) - ->setBuildTargetPHID($build_target->getPHID()) + ->setReceiverPHID($build_target->getPHID()) ->setType($message_type); $build_target->openTransaction(); diff --git a/src/applications/harbormaster/controller/HarbormasterBuildViewController.php b/src/applications/harbormaster/controller/HarbormasterBuildViewController.php index 5b7171a200..4507139d47 100644 --- a/src/applications/harbormaster/controller/HarbormasterBuildViewController.php +++ b/src/applications/harbormaster/controller/HarbormasterBuildViewController.php @@ -65,9 +65,9 @@ final class HarbormasterBuildViewController if ($build_targets) { $messages = id(new HarbormasterBuildMessageQuery()) ->setViewer($viewer) - ->withBuildTargetPHIDs(mpull($build_targets, 'getPHID')) + ->withReceiverPHIDs(mpull($build_targets, 'getPHID')) ->execute(); - $messages = mgroup($messages, 'getBuildTargetPHID'); + $messages = mgroup($messages, 'getReceiverPHID'); } else { $messages = array(); } diff --git a/src/applications/harbormaster/engine/HarbormasterBuildEngine.php b/src/applications/harbormaster/engine/HarbormasterBuildEngine.php index 9c4112e810..4079620f2a 100644 --- a/src/applications/harbormaster/engine/HarbormasterBuildEngine.php +++ b/src/applications/harbormaster/engine/HarbormasterBuildEngine.php @@ -382,12 +382,12 @@ final class HarbormasterBuildEngine extends Phobject { $messages = id(new HarbormasterBuildMessageQuery()) ->setViewer($this->getViewer()) - ->withBuildTargetPHIDs(array_keys($waiting_targets)) + ->withReceiverPHIDs(array_keys($waiting_targets)) ->withConsumed(false) ->execute(); foreach ($messages as $message) { - $target = $waiting_targets[$message->getBuildTargetPHID()]; + $target = $waiting_targets[$message->getReceiverPHID()]; switch ($message->getType()) { case HarbormasterMessageType::MESSAGE_PASS: diff --git a/src/applications/harbormaster/query/HarbormasterBuildMessageQuery.php b/src/applications/harbormaster/query/HarbormasterBuildMessageQuery.php index 749fdd76d4..1b55f2e781 100644 --- a/src/applications/harbormaster/query/HarbormasterBuildMessageQuery.php +++ b/src/applications/harbormaster/query/HarbormasterBuildMessageQuery.php @@ -4,7 +4,7 @@ final class HarbormasterBuildMessageQuery extends PhabricatorCursorPagedPolicyAwareQuery { private $ids; - private $buildTargetPHIDs; + private $receiverPHIDs; private $consumed; public function withIDs(array $ids) { @@ -12,8 +12,8 @@ final class HarbormasterBuildMessageQuery return $this; } - public function withBuildTargetPHIDs(array $phids) { - $this->buildTargetPHIDs = $phids; + public function withReceiverPHIDs(array $phids) { + $this->receiverPHIDs = $phids; return $this; } @@ -22,73 +22,67 @@ final class HarbormasterBuildMessageQuery return $this; } + public function newResultObject() { + return new HarbormasterBuildMessage(); + } + protected function loadPage() { - $table = new HarbormasterBuildMessage(); - $conn_r = $table->establishConnection('r'); - - $data = queryfx_all( - $conn_r, - 'SELECT * FROM %T %Q %Q %Q', - $table->getTableName(), - $this->buildWhereClause($conn_r), - $this->buildOrderClause($conn_r), - $this->buildLimitClause($conn_r)); - - return $table->loadAllFromArray($data); + return $this->loadStandardPage($this->newResultObject()); } protected function willFilterPage(array $page) { - $build_target_phids = array_filter(mpull($page, 'getBuildTargetPHID')); - if ($build_target_phids) { - $build_targets = id(new PhabricatorObjectQuery()) + $receiver_phids = array_filter(mpull($page, 'getReceiverPHID')); + if ($receiver_phids) { + $receivers = id(new PhabricatorObjectQuery()) ->setViewer($this->getViewer()) - ->withPHIDs($build_target_phids) + ->withPHIDs($receiver_phids) ->setParentQuery($this) ->execute(); - $build_targets = mpull($build_targets, null, 'getPHID'); + $receivers = mpull($receivers, null, 'getPHID'); } else { - $build_targets = array(); + $receivers = array(); } foreach ($page as $key => $message) { - $build_target_phid = $message->getBuildTargetPHID(); - if (empty($build_targets[$build_target_phid])) { + $receiver_phid = $message->getReceiverPHID(); + + if (empty($receivers[$receiver_phid])) { unset($page[$key]); + $this->didRejectResult($message); continue; } - $message->attachBuildTarget($build_targets[$build_target_phid]); + + $message->attachReceiver($receivers[$receiver_phid]); } return $page; } - protected function buildWhereClause(AphrontDatabaseConnection $conn_r) { - $where = array(); + protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { + $where = parent::buildWhereClauseParts($conn); - if ($this->ids) { + if ($this->ids !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'id IN (%Ld)', $this->ids); } - if ($this->buildTargetPHIDs) { + if ($this->receiverPHIDs !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'buildTargetPHID IN (%Ls)', - $this->buildTargetPHIDs); + $this->receiverPHIDs); } if ($this->consumed !== null) { $where[] = qsprintf( - $conn_r, + $conn, 'isConsumed = %d', (int)$this->consumed); } - $where[] = $this->buildPagingClause($conn_r); - - return $this->formatWhereClause($where); + return $where; } public function getQueryApplicationClass() { diff --git a/src/applications/harbormaster/storage/HarbormasterBuildMessage.php b/src/applications/harbormaster/storage/HarbormasterBuildMessage.php index 20d138ad02..5c9c92b2fc 100644 --- a/src/applications/harbormaster/storage/HarbormasterBuildMessage.php +++ b/src/applications/harbormaster/storage/HarbormasterBuildMessage.php @@ -14,7 +14,7 @@ final class HarbormasterBuildMessage extends HarbormasterDAO protected $type; protected $isConsumed; - private $buildTarget = self::ATTACHABLE; + private $receiver = self::ATTACHABLE; public static function initializeNewMessage(PhabricatorUser $actor) { $actor_phid = $actor->getPHID(); @@ -41,12 +41,24 @@ final class HarbormasterBuildMessage extends HarbormasterDAO ) + parent::getConfiguration(); } - public function getBuildTarget() { - return $this->assertAttached($this->buildTarget); + public function getReceiverPHID() { + return $this->getBuildTargetPHID(); } - public function attachBuildTarget(HarbormasterBuildTarget $target) { - $this->buildTarget = $target; + public function setReceiverPHID($phid) { + return $this->setBuildTargetPHID($phid); + } + + public function getReceiver() { + return $this->assertAttached($this->receiver); + } + + public function getBuildTarget() { + return $this->getReceiver(); + } + + public function attachReceiver($receiver) { + $this->receiver = $receiver; return $this; } @@ -61,17 +73,17 @@ final class HarbormasterBuildMessage extends HarbormasterDAO } public function getPolicy($capability) { - return $this->getBuildTarget()->getPolicy($capability); + return $this->getReceiver()->getPolicy($capability); } public function hasAutomaticCapability($capability, PhabricatorUser $viewer) { - return $this->getBuildTarget()->hasAutomaticCapability( + return $this->getReceiver()->hasAutomaticCapability( $capability, $viewer); } public function describeAutomaticCapability($capability) { - return pht('Build messages have the same policies as their targets.'); + return pht('Build messages have the same policies as their receivers.'); } }