Differential D18627 Diff 44739 src/applications/differential/editor/DifferentialTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/differential/editor/DifferentialTransactionEditor.php
| Show All 20 Lines | final class DifferentialTransactionEditor | ||||
| public function getCreateObjectTitle($author, $object) { | public function getCreateObjectTitle($author, $object) { | ||||
| return pht('%s created this revision.', $author); | return pht('%s created this revision.', $author); | ||||
| } | } | ||||
| public function getCreateObjectTitleForFeed($author, $object) { | public function getCreateObjectTitleForFeed($author, $object) { | ||||
| return pht('%s created %s.', $author, $object); | return pht('%s created %s.', $author, $object); | ||||
| } | } | ||||
| public function isFirstBroadcast() { | |||||
| return $this->getIsNewObject(); | |||||
| } | |||||
| public function getDiffUpdateTransaction(array $xactions) { | public function getDiffUpdateTransaction(array $xactions) { | ||||
| $type_update = DifferentialTransaction::TYPE_UPDATE; | $type_update = DifferentialTransaction::TYPE_UPDATE; | ||||
| foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
| if ($xaction->getTransactionType() == $type_update) { | if ($xaction->getTransactionType() == $type_update) { | ||||
| return $xaction; | return $xaction; | ||||
| } | } | ||||
| } | } | ||||
| ▲ Show 20 Lines • Show All 558 Lines • ▼ Show 20 Lines | foreach ($xactions as $xaction) { | ||||
| } else { | } else { | ||||
| $head[] = $xaction; | $head[] = $xaction; | ||||
| } | } | ||||
| } | } | ||||
| return array_values(array_merge($head, $tail)); | return array_values(array_merge($head, $tail)); | ||||
| } | } | ||||
| protected function requireCapabilities( | protected function shouldPublishFeedStory( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| PhabricatorApplicationTransaction $xaction) { | array $xactions) { | ||||
| switch ($xaction->getTransactionType()) {} | |||||
| return parent::requireCapabilities($object, $xaction); | if (!$object->shouldBroadcast()) { | ||||
| return false; | |||||
| } | } | ||||
| protected function shouldPublishFeedStory( | |||||
| PhabricatorLiskDAO $object, | |||||
| array $xactions) { | |||||
| return true; | return true; | ||||
| } | } | ||||
| protected function shouldSendMail( | protected function shouldSendMail( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| array $xactions) { | array $xactions) { | ||||
| if (!$object->shouldBroadcast()) { | |||||
| return false; | |||||
| } | |||||
| return true; | return true; | ||||
| } | } | ||||
| protected function getMailTo(PhabricatorLiskDAO $object) { | protected function getMailTo(PhabricatorLiskDAO $object) { | ||||
| $phids = array(); | $phids = array(); | ||||
| $phids[] = $object->getAuthorPHID(); | $phids[] = $object->getAuthorPHID(); | ||||
| foreach ($object->getReviewers() as $reviewer) { | foreach ($object->getReviewers() as $reviewer) { | ||||
| $phids[] = $reviewer->getReviewerPHID(); | $phids[] = $reviewer->getReviewerPHID(); | ||||
| } | } | ||||
| return $phids; | return $phids; | ||||
| } | } | ||||
| protected function getMailAction( | protected function getMailAction( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| array $xactions) { | array $xactions) { | ||||
| $show_lines = false; | |||||
| if ($this->isFirstBroadcast()) { | |||||
| $action = pht('Request'); | |||||
| $show_lines = true; | |||||
| } else { | |||||
| $action = parent::getMailAction($object, $xactions); | $action = parent::getMailAction($object, $xactions); | ||||
| $strongest = $this->getStrongestAction($object, $xactions); | $strongest = $this->getStrongestAction($object, $xactions); | ||||
| switch ($strongest->getTransactionType()) { | $type_update = DifferentialTransaction::TYPE_UPDATE; | ||||
| case DifferentialTransaction::TYPE_UPDATE: | if ($strongest->getTransactionType() == $type_update) { | ||||
| $show_lines = true; | |||||
| } | |||||
| } | |||||
| if ($show_lines) { | |||||
| $count = new PhutilNumber($object->getLineCount()); | $count = new PhutilNumber($object->getLineCount()); | ||||
| $action = pht('%s, %s line(s)', $action, $count); | $action = pht('%s, %s line(s)', $action, $count); | ||||
| break; | |||||
| } | } | ||||
| return $action; | return $action; | ||||
| } | } | ||||
| protected function getMailSubjectPrefix() { | protected function getMailSubjectPrefix() { | ||||
| return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix'); | return PhabricatorEnv::getEnvConfig('metamta.differential.subject-prefix'); | ||||
| } | } | ||||
| Show All 22 Lines | return id(new PhabricatorMetaMTAMail()) | ||||
| ->setSubject($subject) | ->setSubject($subject) | ||||
| ->addHeader('Thread-Topic', $thread_topic); | ->addHeader('Thread-Topic', $thread_topic); | ||||
| } | } | ||||
| protected function buildMailBody( | protected function buildMailBody( | ||||
| PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
| array $xactions) { | array $xactions) { | ||||
| $viewer = $this->requireActor(); | |||||
| // If this is the first time we're sending mail about this revision, we | |||||
| // generate mail for all prior transactions, not just whatever is being | |||||
| // applied now. This gets the "added reviewers" lines and other relevant | |||||
| // information into the mail. | |||||
| if ($this->isFirstBroadcast()) { | |||||
| $xactions = $this->loadUnbroadcastTransactions($object); | |||||
| } | |||||
| $body = new PhabricatorMetaMTAMailBody(); | $body = new PhabricatorMetaMTAMailBody(); | ||||
| $body->setViewer($this->requireActor()); | $body->setViewer($this->requireActor()); | ||||
| $revision_uri = PhabricatorEnv::getProductionURI('/D'.$object->getID()); | $revision_uri = PhabricatorEnv::getProductionURI('/D'.$object->getID()); | ||||
| $this->addHeadersAndCommentsToMailBody( | $this->addHeadersAndCommentsToMailBody( | ||||
| $body, | $body, | ||||
| $xactions, | $xactions, | ||||
| ▲ Show 20 Lines • Show All 796 Lines • ▼ Show 20 Lines | queryfx( | ||||
| WHERE revisionPHID = %s | WHERE revisionPHID = %s | ||||
| AND reviewerPHID = %s', | AND reviewerPHID = %s', | ||||
| $reviewer_table->getTableName(), | $reviewer_table->getTableName(), | ||||
| $diff->getPHID(), | $diff->getPHID(), | ||||
| $object->getPHID(), | $object->getPHID(), | ||||
| $acting_phid); | $acting_phid); | ||||
| } | } | ||||
| private function loadUnbroadcastTransactions($object) { | |||||
| $viewer = $this->requireActor(); | |||||
| $xactions = id(new DifferentialTransactionQuery()) | |||||
| ->setViewer($viewer) | |||||
| ->withObjectPHIDs(array($object->getPHID())) | |||||
| ->execute(); | |||||
| return array_reverse($xactions); | |||||
| } | |||||
| } | } | ||||