Changeset View
Changeset View
Standalone View
Standalone View
src/applications/metamta/query/PhabricatorMetaMTAMailQuery.php
| Show First 20 Lines • Show All 58 Lines • ▼ Show 20 Lines | protected function buildWhereClauseParts(AphrontDatabaseConnection $conn) { | ||||
| if ($this->actorPHIDs !== null) { | if ($this->actorPHIDs !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'mail.actorPHID IN (%Ls)', | 'mail.actorPHID IN (%Ls)', | ||||
| $this->actorPHIDs); | $this->actorPHIDs); | ||||
| } | } | ||||
| if ($this->recipientPHIDs !== null) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'recipient.dst IN (%Ls)', | |||||
| $this->recipientPHIDs); | |||||
| } | |||||
| if ($this->actorPHIDs === null && $this->recipientPHIDs === null) { | |||||
| $viewer = $this->getViewer(); | |||||
| if (!$viewer->isOmnipotent()) { | |||||
| $where[] = qsprintf( | |||||
| $conn, | |||||
| 'edge.dst = %s OR actorPHID = %s', | |||||
| $viewer->getPHID(), | |||||
| $viewer->getPHID()); | |||||
| } | |||||
| } | |||||
| if ($this->createdMin !== null) { | if ($this->createdMin !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'mail.dateCreated >= %d', | 'mail.dateCreated >= %d', | ||||
| $this->createdMin); | $this->createdMin); | ||||
| } | } | ||||
| if ($this->createdMax !== null) { | if ($this->createdMax !== null) { | ||||
| $where[] = qsprintf( | $where[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'mail.dateCreated <= %d', | 'mail.dateCreated <= %d', | ||||
| $this->createdMax); | $this->createdMax); | ||||
| } | } | ||||
| return $where; | return $where; | ||||
| } | } | ||||
| protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | protected function buildJoinClauseParts(AphrontDatabaseConnection $conn) { | ||||
| $joins = parent::buildJoinClauseParts($conn); | $joins = parent::buildJoinClauseParts($conn); | ||||
| if ($this->actorPHIDs === null && $this->recipientPHIDs === null) { | if ($this->shouldJoinRecipients()) { | ||||
| $joins[] = qsprintf( | $joins[] = qsprintf( | ||||
| $conn, | $conn, | ||||
| 'LEFT JOIN %T edge ON mail.phid = edge.src AND edge.type = %d', | 'JOIN %T recipient | ||||
| ON mail.phid = recipient.src | |||||
| AND recipient.type = %d | |||||
| AND recipient.dst IN (%Ls)', | |||||
| PhabricatorEdgeConfig::TABLE_NAME_EDGE, | PhabricatorEdgeConfig::TABLE_NAME_EDGE, | ||||
| PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST); | PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST, | ||||
| $this->recipientPHIDs); | |||||
| } | } | ||||
| if ($this->recipientPHIDs !== null) { | return $joins; | ||||
| $joins[] = qsprintf( | |||||
| $conn, | |||||
| 'LEFT JOIN %T recipient '. | |||||
| 'ON mail.phid = recipient.src AND recipient.type = %d', | |||||
| PhabricatorEdgeConfig::TABLE_NAME_EDGE, | |||||
| PhabricatorMetaMTAMailHasRecipientEdgeType::EDGECONST); | |||||
| } | } | ||||
| return $joins; | private function shouldJoinRecipients() { | ||||
| if ($this->recipientPHIDs === null) { | |||||
| return false; | |||||
| } | |||||
| return true; | |||||
| } | } | ||||
| protected function getPrimaryTableAlias() { | protected function getPrimaryTableAlias() { | ||||
| return 'mail'; | return 'mail'; | ||||
| } | } | ||||
| public function newResultObject() { | public function newResultObject() { | ||||
| return new PhabricatorMetaMTAMail(); | return new PhabricatorMetaMTAMail(); | ||||
| } | } | ||||
| public function getQueryApplicationClass() { | public function getQueryApplicationClass() { | ||||
| return 'PhabricatorMetaMTAApplication'; | return 'PhabricatorMetaMTAApplication'; | ||||
| } | } | ||||
| protected function shouldGroupQueryResultRows() { | |||||
| if ($this->shouldJoinRecipients()) { | |||||
| if (count($this->recipientPHIDs) > 1) { | |||||
| return true; | |||||
| } | |||||
| } | |||||
| return parent::shouldGroupQueryResultRows(); | |||||
| } | |||||
| } | } | ||||