@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.

Send mail about cart/order changes from Phortune

Summary: Ref T2787. When order statuses change, send merchants and users email about it.

Test Plan: Used `bin/mail` to review mail.

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2787

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

+144 -1
+2
resources/sql/autopatches/20141013.phortunecartkey.sql
··· 1 + ALTER TABLE {$NAMESPACE}_phortune.phortune_cart 2 + ADD mailKey BINARY(20) NOT NULL;
+2
src/__phutil_library_map__.php
··· 2568 2568 'PhortuneCartListController' => 'applications/phortune/controller/PhortuneCartListController.php', 2569 2569 'PhortuneCartPHIDType' => 'applications/phortune/phid/PhortuneCartPHIDType.php', 2570 2570 'PhortuneCartQuery' => 'applications/phortune/query/PhortuneCartQuery.php', 2571 + 'PhortuneCartReplyHandler' => 'applications/phortune/mail/PhortuneCartReplyHandler.php', 2571 2572 'PhortuneCartSearchEngine' => 'applications/phortune/query/PhortuneCartSearchEngine.php', 2572 2573 'PhortuneCartTransaction' => 'applications/phortune/storage/PhortuneCartTransaction.php', 2573 2574 'PhortuneCartTransactionQuery' => 'applications/phortune/query/PhortuneCartTransactionQuery.php', ··· 5638 5639 'PhortuneCartListController' => 'PhortuneController', 5639 5640 'PhortuneCartPHIDType' => 'PhabricatorPHIDType', 5640 5641 'PhortuneCartQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 5642 + 'PhortuneCartReplyHandler' => 'PhabricatorMailReplyHandler', 5641 5643 'PhortuneCartSearchEngine' => 'PhabricatorApplicationSearchEngine', 5642 5644 'PhortuneCartTransaction' => 'PhabricatorApplicationTransaction', 5643 5645 'PhortuneCartTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
+12
src/applications/fund/editor/FundInitiativeEditor.php
··· 261 261 ->addHeader('Thread-Topic', $monogram); 262 262 } 263 263 264 + protected function buildMailBody( 265 + PhabricatorLiskDAO $object, 266 + array $xactions) { 267 + 268 + $body = parent::buildMailBody($object, $xactions); 269 + 270 + $body->addTextSection( 271 + pht('INITIATIVE DETAIL'), 272 + PhabricatorEnv::getProductionURI('/'.$object->getMonogram())); 273 + 274 + return $body; 275 + } 264 276 265 277 protected function getMailTo(PhabricatorLiskDAO $object) { 266 278 return array($object->getOwnerPHID());
+72
src/applications/phortune/editor/PhortuneCartEditor.php
··· 92 92 return parent::applyCustomExternalTransaction($object, $xaction); 93 93 } 94 94 95 + protected function shouldSendMail( 96 + PhabricatorLiskDAO $object, 97 + array $xactions) { 98 + return true; 99 + } 100 + 101 + protected function buildMailTemplate(PhabricatorLiskDAO $object) { 102 + $id = $object->getID(); 103 + $name = $object->getName(); 104 + 105 + return id(new PhabricatorMetaMTAMail()) 106 + ->setSubject(pht('Order %d: %s', $id, $name)) 107 + ->addHeader('Thread-Topic', pht('Order %s', $id)); 108 + } 109 + 110 + protected function buildMailBody( 111 + PhabricatorLiskDAO $object, 112 + array $xactions) { 113 + 114 + $body = parent::buildMailBody($object, $xactions); 115 + 116 + $items = array(); 117 + foreach ($object->getPurchases() as $purchase) { 118 + $name = $purchase->getFullDisplayName(); 119 + $price = $purchase->getTotalPriceAsCurrency()->formatForDisplay(); 120 + 121 + $items[] = "{$name} {$price}"; 122 + } 123 + 124 + $body->addTextSection(pht('ORDER CONTENTS'), implode("\n", $items)); 125 + 126 + $body->addTextSection( 127 + pht('ORDER DETAIL'), 128 + PhabricatorEnv::getProductionURI('/phortune/cart/'.$object->getID().'/')); 129 + 130 + return $body; 131 + } 132 + 133 + protected function getMailTo(PhabricatorLiskDAO $object) { 134 + $phids = array(); 135 + 136 + // Relaod the cart to pull merchant and account information, in case we 137 + // just created the object. 138 + $cart = id(new PhortuneCartQuery()) 139 + ->setViewer($this->requireActor()) 140 + ->withPHIDs(array($object->getPHID())) 141 + ->executeOne(); 142 + 143 + foreach ($cart->getAccount()->getMemberPHIDs() as $account_member) { 144 + $phids[] = $account_member; 145 + } 146 + 147 + foreach ($cart->getMerchant()->getMemberPHIDs() as $merchant_member) { 148 + $phids[] = $merchant_member; 149 + } 150 + 151 + return $phids; 152 + } 153 + 154 + protected function getMailCC(PhabricatorLiskDAO $object) { 155 + return array(); 156 + } 157 + 158 + protected function getMailSubjectPrefix() { 159 + return 'Order'; 160 + } 161 + 162 + protected function buildReplyHandler(PhabricatorLiskDAO $object) { 163 + return id(new PhortuneCartReplyHandler()) 164 + ->setMailReceiver($object); 165 + } 166 + 95 167 }
-1
src/applications/phortune/editor/PhortuneMerchantEditor.php
··· 111 111 return $errors; 112 112 } 113 113 114 - 115 114 }
+38
src/applications/phortune/mail/PhortuneCartReplyHandler.php
··· 1 + <?php 2 + 3 + final class PhortuneCartReplyHandler extends PhabricatorMailReplyHandler { 4 + 5 + public function validateMailReceiver($mail_receiver) { 6 + if (!($mail_receiver instanceof PhortuneCart)) { 7 + throw new Exception('Mail receiver is not a PhortuneCart!'); 8 + } 9 + } 10 + 11 + public function getPrivateReplyHandlerEmailAddress( 12 + PhabricatorObjectHandle $handle) { 13 + return $this->getDefaultPrivateReplyHandlerEmailAddress($handle, 'CART'); 14 + } 15 + 16 + public function getPublicReplyHandlerEmailAddress() { 17 + return $this->getDefaultPublicReplyHandlerEmailAddress('CART'); 18 + } 19 + 20 + public function getReplyHandlerDomain() { 21 + return PhabricatorEnv::getEnvConfig('metamta.reply-handler-domain'); 22 + } 23 + 24 + public function getReplyHandlerInstructions() { 25 + if ($this->supportsReplies()) { 26 + // TODO: Implement. 27 + return null; 28 + } else { 29 + return null; 30 + } 31 + } 32 + 33 + protected function receiveEmail(PhabricatorMetaMTAReceivedMail $mail) { 34 + // TODO: Implement. 35 + return null; 36 + } 37 + 38 + }
+9
src/applications/phortune/storage/PhortuneCart.php
··· 17 17 protected $cartClass; 18 18 protected $status; 19 19 protected $metadata = array(); 20 + protected $mailKey; 20 21 21 22 private $account = self::ATTACHABLE; 22 23 private $purchases = self::ATTACHABLE; ··· 514 515 self::CONFIG_COLUMN_SCHEMA => array( 515 516 'status' => 'text32', 516 517 'cartClass' => 'text128', 518 + 'mailKey' => 'bytes20', 517 519 ), 518 520 self::CONFIG_KEY_SCHEMA => array( 519 521 'key_account' => array( ··· 529 531 public function generatePHID() { 530 532 return PhabricatorPHID::generateNewPHID( 531 533 PhortuneCartPHIDType::TYPECONST); 534 + } 535 + 536 + public function save() { 537 + if (!$this->getMailKey()) { 538 + $this->setMailKey(Filesystem::readRandomCharacters(20)); 539 + } 540 + return parent::save(); 532 541 } 533 542 534 543 public function attachPurchases(array $purchases) {
+9
src/applications/phortune/storage/PhortuneCartTransaction.php
··· 22 22 return null; 23 23 } 24 24 25 + public function shouldHideForMail(array $xactions) { 26 + switch ($this->getTransactionType()) { 27 + case self::TYPE_CREATED: 28 + return true; 29 + } 30 + 31 + return parent::shouldHideForMail($xactions); 32 + } 33 + 25 34 public function getTitle() { 26 35 $old = $this->getOldValue(); 27 36 $new = $this->getNewValue();