1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-28 01:32:42 +01:00
phorge-phorge/src/applications/harbormaster/query/HarbormasterBuildMessageQuery.php
epriestley c42bbd6f5c Rename HarbormasterBuildMessage "buildTargetPHID" to "receiverPHID"
Summary: Ref T13054. Companion storage change for D19062.

Test Plan: Applied migration and adjustments. Viewed messages in Harbormaster; created them with `harbormaster.sendmessage`; processed them with `bin/phd debug task`.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13054

Differential Revision: https://secure.phabricator.com/D19063
2018-02-12 12:17:44 -08:00

92 lines
2 KiB
PHP

<?php
final class HarbormasterBuildMessageQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $ids;
private $receiverPHIDs;
private $consumed;
public function withIDs(array $ids) {
$this->ids = $ids;
return $this;
}
public function withReceiverPHIDs(array $phids) {
$this->receiverPHIDs = $phids;
return $this;
}
public function withConsumed($consumed) {
$this->consumed = $consumed;
return $this;
}
public function newResultObject() {
return new HarbormasterBuildMessage();
}
protected function loadPage() {
return $this->loadStandardPage($this->newResultObject());
}
protected function willFilterPage(array $page) {
$receiver_phids = array_filter(mpull($page, 'getReceiverPHID'));
if ($receiver_phids) {
$receivers = id(new PhabricatorObjectQuery())
->setViewer($this->getViewer())
->withPHIDs($receiver_phids)
->setParentQuery($this)
->execute();
$receivers = mpull($receivers, null, 'getPHID');
} else {
$receivers = array();
}
foreach ($page as $key => $message) {
$receiver_phid = $message->getReceiverPHID();
if (empty($receivers[$receiver_phid])) {
unset($page[$key]);
$this->didRejectResult($message);
continue;
}
$message->attachReceiver($receivers[$receiver_phid]);
}
return $page;
}
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
$where = parent::buildWhereClauseParts($conn);
if ($this->ids !== null) {
$where[] = qsprintf(
$conn,
'id IN (%Ld)',
$this->ids);
}
if ($this->receiverPHIDs !== null) {
$where[] = qsprintf(
$conn,
'receiverPHID IN (%Ls)',
$this->receiverPHIDs);
}
if ($this->consumed !== null) {
$where[] = qsprintf(
$conn,
'isConsumed = %d',
(int)$this->consumed);
}
return $where;
}
public function getQueryApplicationClass() {
return 'PhabricatorHarbormasterApplication';
}
}