Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / fund / xaction / FundInitiativeRefundTransaction.php
blob0741e29d104a7df377f89f5148090834ae61f481
1 <?php
3 final class FundInitiativeRefundTransaction
4 extends FundInitiativeTransactionType {
6 const TRANSACTIONTYPE = 'fund:refund';
8 public function generateOldValue($object) {
9 return null;
12 public function applyInternalEffects($object, $value) {
13 $amount = $this->getMetadataValue(
14 FundInitiativeTransaction::PROPERTY_AMOUNT);
15 $amount = PhortuneCurrency::newFromString($amount);
16 $total = $object->getTotalAsCurrency()->subtract($amount);
17 $object->setTotalAsCurrency($total);
20 public function applyExternalEffects($object, $value) {
21 $backer = id(new FundBackerQuery())
22 ->setViewer($this->getActor())
23 ->withPHIDs(array($value))
24 ->executeOne();
25 if (!$backer) {
26 throw new Exception(pht('Unable to load %s!', 'FundBacker'));
29 $subx = array();
30 $amount = $this->getMetadataValue(
31 FundInitiativeTransaction::PROPERTY_AMOUNT);
32 $subx[] = id(new FundBackerTransaction())
33 ->setTransactionType(FundBackerStatusTransaction::TRANSACTIONTYPE)
34 ->setNewValue($amount);
36 $content_source = $this->getEditor()->getContentSource();
38 $editor = id(new FundBackerEditor())
39 ->setActor($this->getActor())
40 ->setContentSource($content_source)
41 ->setContinueOnMissingFields(true)
42 ->setContinueOnNoEffect(true);
44 $editor->applyTransactions($backer, $subx);
47 public function getTitle() {
48 $amount = $this->getMetadataValue(
49 FundInitiativeTransaction::PROPERTY_AMOUNT);
50 $amount = PhortuneCurrency::newFromString($amount);
51 $backer_phid = $this->getMetadataValue(
52 FundInitiativeTransaction::PROPERTY_BACKER);
54 return pht(
55 '%s refunded %s to %s.',
56 $this->renderAuthor(),
57 $amount->formatForDisplay(),
58 $this->renderHandle($backer_phid));
61 public function getTitleForFeed() {
62 $amount = $this->getMetadataValue(
63 FundInitiativeTransaction::PROPERTY_AMOUNT);
64 $amount = PhortuneCurrency::newFromString($amount);
65 $backer_phid = $this->getMetadataValue(
66 FundInitiativeTransaction::PROPERTY_BACKER);
68 return pht(
69 '%s refunded %s to %s for %s.',
70 $this->renderAuthor(),
71 $amount->formatForDisplay(),
72 $this->renderHandle($backer_phid),
73 $this->renderObject());