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

Add cart transactions to Phortune

Summary: Ref T2787. I mostly just want these in place so I can glue emails to them, but they're also useful on their own.

Test Plan: {F216515}

Reviewers: btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T2787

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

+240 -7
+19
resources/sql/autopatches/20141012.phortunecartxaction.sql
··· 1 + CREATE TABLE {$NAMESPACE}_phortune.phortune_carttransaction ( 2 + id INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY, 3 + phid VARCHAR(64) COLLATE utf8_bin NOT NULL, 4 + authorPHID VARCHAR(64) COLLATE utf8_bin NOT NULL, 5 + objectPHID VARCHAR(64) COLLATE utf8_bin NOT NULL, 6 + viewPolicy VARCHAR(64) COLLATE utf8_bin NOT NULL, 7 + editPolicy VARCHAR(64) COLLATE utf8_bin NOT NULL, 8 + commentPHID VARCHAR(64) COLLATE utf8_bin DEFAULT NULL, 9 + commentVersion INT UNSIGNED NOT NULL, 10 + transactionType VARCHAR(32) COLLATE utf8_bin NOT NULL, 11 + oldValue LONGTEXT COLLATE utf8_bin NOT NULL, 12 + newValue LONGTEXT COLLATE utf8_bin NOT NULL, 13 + contentSource LONGTEXT COLLATE utf8_bin NOT NULL, 14 + metadata LONGTEXT COLLATE utf8_bin NOT NULL, 15 + dateCreated INT UNSIGNED NOT NULL, 16 + dateModified INT UNSIGNED NOT NULL, 17 + UNIQUE KEY `key_phid` (`phid`), 18 + KEY `key_object` (`objectPHID`) 19 + ) ENGINE=InnoDB, COLLATE utf8_general_ci;
+6
src/__phutil_library_map__.php
··· 2563 2563 'PhortuneCartCancelController' => 'applications/phortune/controller/PhortuneCartCancelController.php', 2564 2564 'PhortuneCartCheckoutController' => 'applications/phortune/controller/PhortuneCartCheckoutController.php', 2565 2565 'PhortuneCartController' => 'applications/phortune/controller/PhortuneCartController.php', 2566 + 'PhortuneCartEditor' => 'applications/phortune/editor/PhortuneCartEditor.php', 2566 2567 'PhortuneCartImplementation' => 'applications/phortune/cart/PhortuneCartImplementation.php', 2567 2568 'PhortuneCartListController' => 'applications/phortune/controller/PhortuneCartListController.php', 2568 2569 'PhortuneCartPHIDType' => 'applications/phortune/phid/PhortuneCartPHIDType.php', 2569 2570 'PhortuneCartQuery' => 'applications/phortune/query/PhortuneCartQuery.php', 2570 2571 'PhortuneCartSearchEngine' => 'applications/phortune/query/PhortuneCartSearchEngine.php', 2572 + 'PhortuneCartTransaction' => 'applications/phortune/storage/PhortuneCartTransaction.php', 2573 + 'PhortuneCartTransactionQuery' => 'applications/phortune/query/PhortuneCartTransactionQuery.php', 2571 2574 'PhortuneCartUpdateController' => 'applications/phortune/controller/PhortuneCartUpdateController.php', 2572 2575 'PhortuneCartViewController' => 'applications/phortune/controller/PhortuneCartViewController.php', 2573 2576 'PhortuneCharge' => 'applications/phortune/storage/PhortuneCharge.php', ··· 5631 5634 'PhortuneCartCancelController' => 'PhortuneCartController', 5632 5635 'PhortuneCartCheckoutController' => 'PhortuneCartController', 5633 5636 'PhortuneCartController' => 'PhortuneController', 5637 + 'PhortuneCartEditor' => 'PhabricatorApplicationTransactionEditor', 5634 5638 'PhortuneCartListController' => 'PhortuneController', 5635 5639 'PhortuneCartPHIDType' => 'PhabricatorPHIDType', 5636 5640 'PhortuneCartQuery' => 'PhabricatorCursorPagedPolicyAwareQuery', 5637 5641 'PhortuneCartSearchEngine' => 'PhabricatorApplicationSearchEngine', 5642 + 'PhortuneCartTransaction' => 'PhabricatorApplicationTransaction', 5643 + 'PhortuneCartTransactionQuery' => 'PhabricatorApplicationTransactionQuery', 5638 5644 'PhortuneCartUpdateController' => 'PhortuneCartController', 5639 5645 'PhortuneCartViewController' => 'PhortuneCartController', 5640 5646 'PhortuneCharge' => array(
+1 -5
src/applications/phortune/controller/PhortuneAccountViewController.php
··· 267 267 ->withObjectPHIDs(array($account->getPHID())) 268 268 ->execute(); 269 269 270 - $engine = id(new PhabricatorMarkupEngine()) 271 - ->setViewer($user); 272 - 273 270 $xaction_view = id(new PhabricatorApplicationTransactionView()) 274 271 ->setUser($user) 275 272 ->setObjectPHID($account->getPHID()) 276 - ->setTransactions($xactions) 277 - ->setMarkupEngine($engine); 273 + ->setTransactions($xactions); 278 274 279 275 return $xaction_view; 280 276 }
+12
src/applications/phortune/controller/PhortuneCartViewController.php
··· 160 160 $this->addAccountCrumb($crumbs, $cart->getAccount()); 161 161 $crumbs->addTextCrumb(pht('Cart %d', $cart->getID())); 162 162 163 + $xactions = id(new PhortuneCartTransactionQuery()) 164 + ->setViewer($viewer) 165 + ->withObjectPHIDs(array($cart->getPHID())) 166 + ->execute(); 167 + 168 + $xaction_view = id(new PhabricatorApplicationTransactionView()) 169 + ->setUser($viewer) 170 + ->setObjectPHID($cart->getPHID()) 171 + ->setTransactions($xactions) 172 + ->setShouldTerminate(true); 173 + 163 174 return $this->buildApplicationPage( 164 175 array( 165 176 $crumbs, 166 177 $cart_box, 167 178 $charges, 179 + $xaction_view, 168 180 ), 169 181 array( 170 182 'title' => pht('Cart'),
+95
src/applications/phortune/editor/PhortuneCartEditor.php
··· 1 + <?php 2 + 3 + final class PhortuneCartEditor 4 + extends PhabricatorApplicationTransactionEditor { 5 + 6 + public function getEditorApplicationClass() { 7 + return 'PhabricatorPhortuneApplication'; 8 + } 9 + 10 + public function getEditorObjectsDescription() { 11 + return pht('Phortune Carts'); 12 + } 13 + 14 + public function getTransactionTypes() { 15 + $types = parent::getTransactionTypes(); 16 + 17 + $types[] = PhortuneCartTransaction::TYPE_CREATED; 18 + $types[] = PhortuneCartTransaction::TYPE_PURCHASED; 19 + $types[] = PhortuneCartTransaction::TYPE_HOLD; 20 + $types[] = PhortuneCartTransaction::TYPE_REVIEW; 21 + $types[] = PhortuneCartTransaction::TYPE_CANCEL; 22 + $types[] = PhortuneCartTransaction::TYPE_REFUND; 23 + 24 + return $types; 25 + } 26 + 27 + protected function getCustomTransactionOldValue( 28 + PhabricatorLiskDAO $object, 29 + PhabricatorApplicationTransaction $xaction) { 30 + 31 + switch ($xaction->getTransactionType()) { 32 + case PhortuneCartTransaction::TYPE_CREATED: 33 + case PhortuneCartTransaction::TYPE_PURCHASED: 34 + case PhortuneCartTransaction::TYPE_HOLD: 35 + case PhortuneCartTransaction::TYPE_REVIEW: 36 + case PhortuneCartTransaction::TYPE_CANCEL: 37 + case PhortuneCartTransaction::TYPE_REFUND: 38 + return null; 39 + } 40 + 41 + return parent::getCustomTransactionOldValue($object, $xaction); 42 + } 43 + 44 + protected function getCustomTransactionNewValue( 45 + PhabricatorLiskDAO $object, 46 + PhabricatorApplicationTransaction $xaction) { 47 + 48 + switch ($xaction->getTransactionType()) { 49 + case PhortuneCartTransaction::TYPE_CREATED: 50 + case PhortuneCartTransaction::TYPE_PURCHASED: 51 + case PhortuneCartTransaction::TYPE_HOLD: 52 + case PhortuneCartTransaction::TYPE_REVIEW: 53 + case PhortuneCartTransaction::TYPE_CANCEL: 54 + case PhortuneCartTransaction::TYPE_REFUND: 55 + return $xaction->getNewValue(); 56 + } 57 + 58 + return parent::getCustomTransactionNewValue($object, $xaction); 59 + } 60 + 61 + protected function applyCustomInternalTransaction( 62 + PhabricatorLiskDAO $object, 63 + PhabricatorApplicationTransaction $xaction) { 64 + 65 + switch ($xaction->getTransactionType()) { 66 + case PhortuneCartTransaction::TYPE_CREATED: 67 + case PhortuneCartTransaction::TYPE_PURCHASED: 68 + case PhortuneCartTransaction::TYPE_HOLD: 69 + case PhortuneCartTransaction::TYPE_REVIEW: 70 + case PhortuneCartTransaction::TYPE_CANCEL: 71 + case PhortuneCartTransaction::TYPE_REFUND: 72 + return; 73 + } 74 + 75 + return parent::applyCustomInternalTransaction($object, $xaction); 76 + } 77 + 78 + protected function applyCustomExternalTransaction( 79 + PhabricatorLiskDAO $object, 80 + PhabricatorApplicationTransaction $xaction) { 81 + 82 + switch ($xaction->getTransactionType()) { 83 + case PhortuneCartTransaction::TYPE_CREATED: 84 + case PhortuneCartTransaction::TYPE_PURCHASED: 85 + case PhortuneCartTransaction::TYPE_HOLD: 86 + case PhortuneCartTransaction::TYPE_REVIEW: 87 + case PhortuneCartTransaction::TYPE_CANCEL: 88 + case PhortuneCartTransaction::TYPE_REFUND: 89 + return; 90 + } 91 + 92 + return parent::applyCustomExternalTransaction($object, $xaction); 93 + } 94 + 95 + }
+10
src/applications/phortune/query/PhortuneCartTransactionQuery.php
··· 1 + <?php 2 + 3 + final class PhortuneCartTransactionQuery 4 + extends PhabricatorApplicationTransactionQuery { 5 + 6 + public function getTemplateApplicationTransaction() { 7 + return new PhortuneCartTransaction(); 8 + } 9 + 10 + }
+49 -2
src/applications/phortune/storage/PhortuneCart.php
··· 70 70 } 71 71 72 72 public function activateCart() { 73 - $this->setStatus(self::STATUS_READY)->save(); 73 + $this->openTransaction(); 74 + $this->beginReadLocking(); 75 + 76 + $copy = clone $this; 77 + $copy->reload(); 78 + 79 + if ($copy->getStatus() !== self::STATUS_BUILDING) { 80 + throw new Exception( 81 + pht( 82 + 'Cart has wrong status ("%s") to call willApplyCharge().', 83 + $copy->getStatus())); 84 + } 85 + 86 + $this->setStatus(self::STATUS_READY)->save(); 87 + 88 + $this->endReadLocking(); 89 + $this->saveTransaction(); 90 + 91 + $this->recordCartTransaction(PhortuneCartTransaction::TYPE_CREATED); 92 + 74 93 return $this; 75 94 } 76 95 ··· 140 159 141 160 $this->endReadLocking(); 142 161 $this->saveTransaction(); 162 + 163 + $this->recordCartTransaction(PhortuneCartTransaction::TYPE_HOLD); 143 164 } 144 165 145 166 public function didApplyCharge(PhortuneCharge $charge) { ··· 199 220 $this->endReadLocking(); 200 221 $this->saveTransaction(); 201 222 202 - // TODO: Notify merchant to review order. 223 + $this->recordCartTransaction(PhortuneCartTransaction::TYPE_REVIEW); 203 224 204 225 return $this; 205 226 } ··· 228 249 $this->endReadLocking(); 229 250 $this->saveTransaction(); 230 251 252 + $this->recordCartTransaction(PhortuneCartTransaction::TYPE_PURCHASED); 253 + 231 254 return $this; 232 255 } 233 256 ··· 382 405 383 406 $this->endReadLocking(); 384 407 $this->saveTransaction(); 408 + } 409 + 410 + private function recordCartTransaction($type) { 411 + $omnipotent_user = PhabricatorUser::getOmnipotentUser(); 412 + $phortune_phid = id(new PhabricatorPhortuneApplication())->getPHID(); 413 + 414 + $xactions = array(); 415 + 416 + $xactions[] = id(new PhortuneCartTransaction()) 417 + ->setTransactionType($type) 418 + ->setNewValue(true); 419 + 420 + $content_source = PhabricatorContentSource::newForSource( 421 + PhabricatorContentSource::SOURCE_PHORTUNE, 422 + array()); 423 + 424 + $editor = id(new PhortuneCartEditor()) 425 + ->setActor($omnipotent_user) 426 + ->setActingAsPHID($phortune_phid) 427 + ->setContentSource($content_source) 428 + ->setContinueOnMissingFields(true) 429 + ->setContinueOnNoEffect(true); 430 + 431 + $editor->applyTransactions($this, $xactions); 385 432 } 386 433 387 434 public function getName() {
+48
src/applications/phortune/storage/PhortuneCartTransaction.php
··· 1 + <?php 2 + 3 + final class PhortuneCartTransaction 4 + extends PhabricatorApplicationTransaction { 5 + 6 + const TYPE_CREATED = 'cart:created'; 7 + const TYPE_HOLD = 'cart:hold'; 8 + const TYPE_REVIEW = 'cart:review'; 9 + const TYPE_CANCEL = 'cart:cancel'; 10 + const TYPE_REFUND = 'cart:refund'; 11 + const TYPE_PURCHASED = 'cart:purchased'; 12 + 13 + public function getApplicationName() { 14 + return 'phortune'; 15 + } 16 + 17 + public function getApplicationTransactionType() { 18 + return PhortuneCartPHIDType::TYPECONST; 19 + } 20 + 21 + public function getApplicationTransactionCommentObject() { 22 + return null; 23 + } 24 + 25 + public function getTitle() { 26 + $old = $this->getOldValue(); 27 + $new = $this->getNewValue(); 28 + 29 + switch ($this->getTransactionType()) { 30 + case self::TYPE_CREATED: 31 + return pht('This order was created.'); 32 + case self::TYPE_HOLD: 33 + return pht('This order was put on hold until payment clears.'); 34 + case self::TYPE_REVIEW: 35 + return pht( 36 + 'This order was flagged for manual processing by the merchant.'); 37 + case self::TYPE_CANCEL: 38 + return pht('This order was cancelled.'); 39 + case self::TYPE_REFUND: 40 + return pht('This order was refunded.'); 41 + case self::TYPE_PURCHASED: 42 + return pht('Payment for this order was completed.'); 43 + } 44 + 45 + return parent::getTitle(); 46 + } 47 + 48 + }