@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<?php
2
3final class PhabricatorConfigTransaction
4 extends PhabricatorApplicationTransaction {
5
6 const TYPE_EDIT = 'config:edit';
7
8 public function getApplicationName() {
9 return 'config';
10 }
11
12 public function getApplicationTransactionType() {
13 return PhabricatorConfigConfigPHIDType::TYPECONST;
14 }
15
16 public function getTitle() {
17 $author_phid = $this->getAuthorPHID();
18
19 $old = $this->getOldValue();
20 $new = $this->getNewValue();
21
22 switch ($this->getTransactionType()) {
23 case self::TYPE_EDIT:
24
25 // TODO: After T2213 show the actual values too; for now, we don't
26 // have the tools to do it without making a bit of a mess of it.
27
28 $old_del = idx($old, 'deleted');
29 $new_del = idx($new, 'deleted');
30 if ($old_del && !$new_del) {
31 return pht(
32 '%s created this configuration entry.',
33 $this->renderHandleLink($author_phid));
34 } else if (!$old_del && $new_del) {
35 return pht(
36 '%s deleted this configuration entry.',
37 $this->renderHandleLink($author_phid));
38 } else if ($old_del && $new_del) {
39 // This is a bug.
40 return pht(
41 '%s deleted this configuration entry (again?).',
42 $this->renderHandleLink($author_phid));
43 } else {
44 return pht(
45 '%s edited this configuration entry.',
46 $this->renderHandleLink($author_phid));
47 }
48 }
49
50 return parent::getTitle();
51 }
52
53 public function getTitleForFeed() {
54 $author_phid = $this->getAuthorPHID();
55
56 $old = $this->getOldValue();
57 $new = $this->getNewValue();
58
59 switch ($this->getTransactionType()) {
60 case self::TYPE_EDIT:
61 $old_del = idx($old, 'deleted');
62 $new_del = idx($new, 'deleted');
63 if ($old_del && !$new_del) {
64 return pht(
65 '%s created %s.',
66 $this->renderHandleLink($author_phid),
67 $this->getObject()->getConfigKey());
68 } else if (!$old_del && $new_del) {
69 return pht(
70 '%s deleted %s.',
71 $this->renderHandleLink($author_phid),
72 $this->getObject()->getConfigKey());
73 } else if ($old_del && $new_del) {
74 // This is a bug.
75 return pht(
76 '%s deleted %s (again?).',
77 $this->renderHandleLink($author_phid),
78 $this->getObject()->getConfigKey());
79 } else {
80 return pht(
81 '%s edited %s.',
82 $this->renderHandleLink($author_phid),
83 $this->getObject()->getConfigKey());
84 }
85 }
86
87 return parent::getTitle();
88 }
89
90
91 public function getIcon() {
92 switch ($this->getTransactionType()) {
93 case self::TYPE_EDIT:
94 return 'fa-pencil';
95 }
96
97 return parent::getIcon();
98 }
99
100 public function hasChangeDetails() {
101 switch ($this->getTransactionType()) {
102 case self::TYPE_EDIT:
103 return true;
104 }
105 return parent::hasChangeDetails();
106 }
107
108 public function renderChangeDetails(PhabricatorUser $viewer) {
109 $old = $this->getOldValue();
110 $new = $this->getNewValue();
111
112 if ($old['deleted']) {
113 $old_text = '';
114 } else {
115 $old_text = PhabricatorConfigJSON::prettyPrintJSON($old['value']);
116 }
117
118 if ($new['deleted']) {
119 $new_text = '';
120 } else {
121 $new_text = PhabricatorConfigJSON::prettyPrintJSON($new['value']);
122 }
123
124 return $this->renderTextCorpusChangeDetails(
125 $viewer,
126 $old_text,
127 $new_text);
128 }
129
130 public function getColor() {
131 $old = $this->getOldValue();
132 $new = $this->getNewValue();
133
134 switch ($this->getTransactionType()) {
135 case self::TYPE_EDIT:
136 $old_del = idx($old, 'deleted');
137 $new_del = idx($new, 'deleted');
138
139 if ($old_del && !$new_del) {
140 return PhabricatorTransactions::COLOR_GREEN;
141 } else if (!$old_del && $new_del) {
142 return PhabricatorTransactions::COLOR_RED;
143 } else {
144 return PhabricatorTransactions::COLOR_BLUE;
145 }
146 }
147 }
148
149}