@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Allow modular transactions to override transaction title and body text in mail

Summary:
Ref T12921. I'm moving Instances to modular transactions, and we have an "Alert" transaction type used to send notifications ("Your instance is going to be suspended for nonpayment.").

Currently, there's no way to specifically customize mail rendering under modular transactions. Add crude support for it.

Note that (per comment) this is fairly aspirational right now, since we actually always render everything as text (see T12921). But this API should (?) mostly survive intact when I fix this properly, and allows Instances to move to modular transactions so I can fix some more pressing issues in the meantime.

Test Plan: See next diff for Instances.

Reviewers: amckinley

Reviewed By: amckinley

Maniphest Tasks: T12921

Differential Revision: https://secure.phabricator.com/D20057

+121 -5
+57 -5
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
··· 3294 3294 // move the other transactions down so they provide context above the 3295 3295 // actual comment. 3296 3296 3297 - $comment = $xaction->getBodyForMail(); 3297 + $comment = $this->getBodyForTextMail($xaction); 3298 3298 if ($comment !== null) { 3299 3299 $is_comment = true; 3300 3300 $comments[] = array( ··· 3307 3307 } 3308 3308 3309 3309 if (!$is_comment || !$seen_comment) { 3310 - $header = $xaction->getTitleForTextMail(); 3310 + $header = $this->getTitleForTextMail($xaction); 3311 3311 if ($header !== null) { 3312 3312 $headers[] = $header; 3313 3313 } 3314 3314 3315 - $header_html = $xaction->getTitleForHTMLMail(); 3315 + $header_html = $this->getTitleForHTMLMail($xaction); 3316 3316 if ($header_html !== null) { 3317 3317 $headers_html[] = $header_html; 3318 3318 } ··· 3392 3392 // If this is not the first comment in the mail, add the header showing 3393 3393 // who wrote the comment immediately above the comment. 3394 3394 if (!$is_initial) { 3395 - $header = $xaction->getTitleForTextMail(); 3395 + $header = $this->getTitleForTextMail($xaction); 3396 3396 if ($header !== null) { 3397 3397 $body->addRawPlaintextSection($header); 3398 3398 } 3399 3399 3400 - $header_html = $xaction->getTitleForHTMLMail(); 3400 + $header_html = $this->getTitleForHTMLMail($xaction); 3401 3401 if ($header_html !== null) { 3402 3402 $body->addRawHTMLSection($header_html); 3403 3403 } ··· 4981 4981 array_unshift($xactions, $mfa_xaction); 4982 4982 4983 4983 return $xactions; 4984 + } 4985 + 4986 + private function getTitleForTextMail( 4987 + PhabricatorApplicationTransaction $xaction) { 4988 + $type = $xaction->getTransactionType(); 4989 + 4990 + $xtype = $this->getModularTransactionType($type); 4991 + if ($xtype) { 4992 + $xtype = clone $xtype; 4993 + $xtype->setStorage($xaction); 4994 + $comment = $xtype->getTitleForTextMail(); 4995 + if ($comment !== false) { 4996 + return $comment; 4997 + } 4998 + } 4999 + 5000 + return $xaction->getTitleForTextMail(); 5001 + } 5002 + 5003 + private function getBodyForHTMLMail( 5004 + PhabricatorApplicationTransaction $xaction) { 5005 + $type = $xaction->getTransactionType(); 5006 + 5007 + $xtype = $this->getModularTransactionType($type); 5008 + if ($xtype) { 5009 + $xtype = clone $xtype; 5010 + $xtype->setStorage($xaction); 5011 + $comment = $xtype->getTitleForHTMLMail(); 5012 + if ($comment !== false) { 5013 + return $comment; 5014 + } 5015 + } 5016 + 5017 + return $xaction->getTitleForHTMLMail(); 5018 + } 5019 + 5020 + 5021 + private function getBodyForTextMail( 5022 + PhabricatorApplicationTransaction $xaction) { 5023 + $type = $xaction->getTransactionType(); 5024 + 5025 + $xtype = $this->getModularTransactionType($type); 5026 + if ($xtype) { 5027 + $xtype = clone $xtype; 5028 + $xtype->setStorage($xaction); 5029 + $comment = $xtype->getBodyForTextMail(); 5030 + if ($comment !== false) { 5031 + return $comment; 5032 + } 5033 + } 5034 + 5035 + return $xaction->getBodyForMail(); 4984 5036 } 4985 5037 4986 5038
+64
src/applications/transactions/storage/PhabricatorModularTransactionType.php
··· 431 431 return false; 432 432 } 433 433 434 + // NOTE: See T12921. These APIs are somewhat aspirational. For now, all of 435 + // these use "TARGET_TEXT" (even the HTML methods!) and the body methods 436 + // actually return Remarkup, not text or HTML. 437 + 438 + final public function getTitleForTextMail() { 439 + return $this->getTitleForMailWithRenderingTarget( 440 + PhabricatorApplicationTransaction::TARGET_TEXT); 441 + } 442 + 443 + final public function getTitleForHTMLMail() { 444 + return $this->getTitleForMailWithRenderingTarget( 445 + PhabricatorApplicationTransaction::TARGET_TEXT); 446 + } 447 + 448 + final public function getBodyForTextMail() { 449 + return $this->getBodyForMailWithRenderingTarget( 450 + PhabricatorApplicationTransaction::TARGET_TEXT); 451 + } 452 + 453 + final public function getBodyForHTMLMail() { 454 + return $this->getBodyForMailWithRenderingTarget( 455 + PhabricatorApplicationTransaction::TARGET_TEXT); 456 + } 457 + 458 + private function getTitleForMailWithRenderingTarget($target) { 459 + $storage = $this->getStorage(); 460 + 461 + $old_target = $storage->getRenderingTarget(); 462 + try { 463 + $storage->setRenderingTarget($target); 464 + $result = $this->getTitleForMail(); 465 + } catch (Exception $ex) { 466 + $storage->setRenderingTarget($old_target); 467 + throw $ex; 468 + } 469 + $storage->setRenderingTarget($old_target); 470 + 471 + return $result; 472 + } 473 + 474 + private function getBodyForMailWithRenderingTarget($target) { 475 + $storage = $this->getStorage(); 476 + 477 + $old_target = $storage->getRenderingTarget(); 478 + try { 479 + $storage->setRenderingTarget($target); 480 + $result = $this->getBodyForMail(); 481 + } catch (Exception $ex) { 482 + $storage->setRenderingTarget($old_target); 483 + throw $ex; 484 + } 485 + $storage->setRenderingTarget($old_target); 486 + 487 + return $result; 488 + } 489 + 490 + protected function getTitleForMail() { 491 + return false; 492 + } 493 + 494 + protected function getBodyForMail() { 495 + return false; 496 + } 497 + 434 498 }