2015-06-22 13:46:26 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorMetaMTAMailQuery
|
|
|
|
extends PhabricatorCursorPagedPolicyAwareQuery {
|
|
|
|
|
|
|
|
private $ids;
|
|
|
|
private $phids;
|
2015-06-23 11:37:14 -07:00
|
|
|
private $actorPHIDs;
|
|
|
|
private $recipientPHIDs;
|
2015-08-06 11:32:17 -07:00
|
|
|
private $createdMin;
|
|
|
|
private $createdMax;
|
2015-06-22 13:46:26 -07:00
|
|
|
|
|
|
|
public function withIDs(array $ids) {
|
|
|
|
$this->ids = $ids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withPHIDs(array $phids) {
|
|
|
|
$this->phids = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-23 11:37:14 -07:00
|
|
|
public function withActorPHIDs(array $phids) {
|
|
|
|
$this->actorPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function withRecipientPHIDs(array $phids) {
|
|
|
|
$this->recipientPHIDs = $phids;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-08-06 11:32:17 -07:00
|
|
|
public function withDateCreatedBetween($min, $max) {
|
|
|
|
$this->createdMin = $min;
|
|
|
|
$this->createdMax = $max;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2015-06-22 13:46:26 -07:00
|
|
|
protected function loadPage() {
|
|
|
|
return $this->loadStandardPage($this->newResultObject());
|
|
|
|
}
|
|
|
|
|
2015-08-06 11:32:17 -07:00
|
|
|
protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) {
|
|
|
|
$where = parent::buildWhereClauseParts($conn);
|
2015-06-22 13:46:26 -07:00
|
|
|
|
|
|
|
if ($this->ids !== null) {
|
|
|
|
$where[] = qsprintf(
|
2015-08-06 11:32:17 -07:00
|
|
|
$conn,
|
2015-06-22 13:46:26 -07:00
|
|
|
'mail.id IN (%Ld)',
|
|
|
|
$this->ids);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->phids !== null) {
|
|
|
|
$where[] = qsprintf(
|
2015-08-06 11:32:17 -07:00
|
|
|
$conn,
|
2015-06-22 13:46:26 -07:00
|
|
|
'mail.phid IN (%Ls)',
|
|
|
|
$this->phids);
|
|
|
|
}
|
|
|
|
|
2015-06-23 11:37:14 -07:00
|
|
|
if ($this->actorPHIDs !== null) {
|
|
|
|
$where[] = qsprintf(
|
2015-08-06 11:32:17 -07:00
|
|
|
$conn,
|
2015-06-23 11:37:14 -07:00
|
|
|
'mail.actorPHID IN (%Ls)',
|
|
|
|
$this->actorPHIDs);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->recipientPHIDs !== null) {
|
|
|
|
$where[] = qsprintf(
|
2015-08-06 11:32:17 -07:00
|
|
|
$conn,
|
2015-06-23 11:37:14 -07:00
|
|
|
'recipient.dst IN (%Ls)',
|
|
|
|
$this->recipientPHIDs);
|
|
|
|
}
|
|
|
|
|
2015-06-23 12:55:44 -07:00
|
|
|
if ($this->actorPHIDs === null && $this->recipientPHIDs === null) {
|
|
|
|
$viewer = $this->getViewer();
|
2015-08-06 11:32:17 -07:00
|
|
|
if (!$viewer->isOmnipotent()) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'edge.dst = %s OR actorPHID = %s',
|
|
|
|
$viewer->getPHID(),
|
|
|
|
$viewer->getPHID());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($this->createdMin !== null) {
|
2015-06-23 12:55:44 -07:00
|
|
|
$where[] = qsprintf(
|
2015-08-06 11:32:17 -07:00
|
|
|
$conn,
|
|
|
|
'mail.dateCreated >= %d',
|
|
|
|
$this->createdMin);
|
2015-06-23 12:55:44 -07:00
|
|
|
}
|
2015-06-23 11:37:14 -07:00
|
|
|
|
2015-08-06 11:32:17 -07:00
|
|
|
if ($this->createdMax !== null) {
|
|
|
|
$where[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'mail.dateCreated <= %d',
|
|
|
|
$this->createdMax);
|
|
|
|
}
|
2015-06-22 13:46:26 -07:00
|
|
|
|
2015-08-06 11:32:17 -07:00
|
|
|
return $where;
|
2015-06-22 13:46:26 -07:00
|
|
|
}
|
|
|
|
|
2015-06-23 11:37:14 -07:00
|
|
|
protected function buildJoinClause(AphrontDatabaseConnection $conn) {
|
|
|
|
$joins = array();
|
|
|
|
|
2015-06-23 12:55:44 -07:00
|
|
|
if ($this->actorPHIDs === null && $this->recipientPHIDs === null) {
|
|
|
|
$joins[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'LEFT JOIN %T edge ON mail.phid = edge.src AND edge.type = %d',
|
|
|
|
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
|
|
|
|
PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST);
|
|
|
|
}
|
2015-06-23 11:37:14 -07:00
|
|
|
|
|
|
|
if ($this->recipientPHIDs !== null) {
|
|
|
|
$joins[] = qsprintf(
|
|
|
|
$conn,
|
|
|
|
'LEFT JOIN %T recipient '.
|
|
|
|
'ON mail.phid = recipient.src AND recipient.type = %d',
|
|
|
|
PhabricatorEdgeConfig::TABLE_NAME_EDGE,
|
|
|
|
PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST);
|
|
|
|
}
|
|
|
|
|
|
|
|
return implode(' ', $joins);
|
|
|
|
}
|
|
|
|
|
2015-06-22 13:46:26 -07:00
|
|
|
protected function getPrimaryTableAlias() {
|
|
|
|
return 'mail';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function newResultObject() {
|
|
|
|
return new PhabricatorMetaMTAMail();
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getQueryApplicationClass() {
|
|
|
|
return 'PhabricatorMetaMTAApplication';
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|