Files
phabricator/src/applications/differential/mail/DifferentialReviewRequestMail.php

130 lines
3.3 KiB
PHP
Raw Normal View History

2011-01-25 17:17:19 -08:00
<?php
abstract class DifferentialReviewRequestMail extends DifferentialMail {
const MAX_AFFECTED_FILES = 1000;
2011-01-25 17:17:19 -08:00
protected $comments;
private $patch;
2011-01-25 17:17:19 -08:00
public function setComments($comments) {
$this->comments = $comments;
return $this;
}
public function getComments() {
return $this->comments;
}
public function __construct(
DifferentialRevision $revision,
PhabricatorObjectHandle $actor,
2011-01-25 17:17:19 -08:00
array $changesets) {
assert_instances_of($changesets, 'DifferentialChangeset');
2011-01-25 17:17:19 -08:00
$this->setRevision($revision);
$this->setActorHandle($actor);
2011-01-25 17:17:19 -08:00
$this->setChangesets($changesets);
}
protected function prepareBody() {
parent::prepareBody();
$inline_max_length = PhabricatorEnv::getEnvConfig(
'metamta.differential.inline-patches');
if ($inline_max_length) {
$patch = $this->buildPatch();
if (count(explode("\n", $patch)) <= $inline_max_length) {
$this->patch = $patch;
}
}
}
2011-01-25 17:17:19 -08:00
protected function renderReviewRequestBody() {
$revision = $this->getRevision();
$body = array();
if (!$this->isFirstMailToRecipients()) {
2011-01-25 17:17:19 -08:00
if (strlen($this->getComments())) {
$body[] = $this->formatText($this->getComments());
$body[] = null;
}
}
$phase = ($this->isFirstMailToRecipients() ?
DifferentialMailPhase::WELCOME :
DifferentialMailPhase::UPDATE);
$body[] = $this->renderAuxFields($phase);
2011-01-25 17:17:19 -08:00
$changesets = $this->getChangesets();
if ($changesets) {
$body[] = 'AFFECTED FILES';
$max = self::MAX_AFFECTED_FILES;
foreach (array_values($changesets) as $i => $changeset) {
if ($i == $max) {
$body[] = ' ('.(count($changesets) - $max).' more files)';
break;
}
2011-01-25 17:17:19 -08:00
$body[] = ' '.$changeset->getFilename();
}
$body[] = null;
}
if ($this->patch) {
$body[] = 'CHANGE DETAILS';
$body[] = $this->patch;
}
2011-01-25 17:17:19 -08:00
return implode("\n", $body);
}
protected function buildAttachments() {
$attachments = array();
if (PhabricatorEnv::getEnvConfig('metamta.differential.attach-patches')) {
$revision = $this->getRevision();
$revision_id = $revision->getID();
$diffs = id(new DifferentialDiffQuery())
->setViewer($this->getActor())
->withRevisionIDs(array($revision_id))
->execute();
$diff_number = count($diffs);
$attachments[] = new PhabricatorMetaMTAAttachment(
$this->buildPatch(),
"D{$revision_id}.{$diff_number}.patch",
'text/x-patch; charset=utf-8'
);
}
return $attachments;
}
private function buildPatch() {
$renderer = new DifferentialRawDiffRenderer();
$renderer->setChangesets($this->getChangesets());
$renderer->setFormat(
PhabricatorEnv::getEnvConfig('metamta.differential.patch-format'));
// TODO: It would be nice to have a real viewer here eventually, but
// in the meantime anyone we're sending mail to can certainly see the
// patch.
$renderer->setViewer(PhabricatorUser::getOmnipotentUser());
return $renderer->buildPatch();
}
Fix "request" and "update" mail preferences for Differential Summary: Fixes T3030. T1977 attempted to fix this but either didn't work (I think this is the case) or was broken later. We don't send `DifferentialCommentMail` on a create or update; we send `DifferentialReviewRequestMail`. Also update the details to be more clear. Test Plan: Verified review request mail is marked undeliverable: ``` $ ./bin/mail show-outbound --id 6644 ... PARAMETERS ... mailtags: ["differential-review-request"] ... subject: D922: asdf subject-prefix: [Differential] vary-subject-prefix: [Request, 100 lines] ... RECIPIENTS ! duck (duck) - This mail has tags which control which users receive it, and this recipient has not elected to receive mail with any of the tags on this message (Settings > Email Preferences). BODY epriestley requested code review of "asdf". ... ``` Verified update mail is marked undeliverable: ``` $ ./bin/mail show-outbound --id 6646 ... Message: Message has no valid recipients: all To/Cc are disabled, invalid, or configured not to receive this mail. PARAMETERS ... mailtags: ["differential-updated"] ... subject: D922: asdf subject-prefix: [Differential] vary-subject-prefix: [Updated, 100 lines] ... RECIPIENTS ! duck (duck) - This mail has tags which control which users receive it, and this recipient has not elected to receive mail with any of the tags on this message (Settings > Email Preferences). BODY epriestley updated the revision "asdf". ... ``` Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T3030 Differential Revision: https://secure.phabricator.com/D6518
2013-07-22 12:20:48 -07:00
protected function getMailTags() {
$tags = array();
if ($this->isFirstMailToRecipients()) {
$tags[] = MetaMTANotificationType::TYPE_DIFFERENTIAL_REVIEW_REQUEST;
} else {
$tags[] = MetaMTANotificationType::TYPE_DIFFERENTIAL_UPDATED;
}
return $tags;
}
2011-01-25 17:17:19 -08:00
}