Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/config/storage/PhabricatorConfigTransaction.php
12256 views
1
<?php
2
3
final 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
break;
49
}
50
51
return parent::getTitle();
52
}
53
54
public function getTitleForFeed() {
55
$author_phid = $this->getAuthorPHID();
56
57
$old = $this->getOldValue();
58
$new = $this->getNewValue();
59
60
switch ($this->getTransactionType()) {
61
case self::TYPE_EDIT:
62
$old_del = idx($old, 'deleted');
63
$new_del = idx($new, 'deleted');
64
if ($old_del && !$new_del) {
65
return pht(
66
'%s created %s.',
67
$this->renderHandleLink($author_phid),
68
$this->getObject()->getConfigKey());
69
} else if (!$old_del && $new_del) {
70
return pht(
71
'%s deleted %s.',
72
$this->renderHandleLink($author_phid),
73
$this->getObject()->getConfigKey());
74
} else if ($old_del && $new_del) {
75
// This is a bug.
76
return pht(
77
'%s deleted %s (again?).',
78
$this->renderHandleLink($author_phid),
79
$this->getObject()->getConfigKey());
80
} else {
81
return pht(
82
'%s edited %s.',
83
$this->renderHandleLink($author_phid),
84
$this->getObject()->getConfigKey());
85
}
86
break;
87
}
88
89
return parent::getTitle();
90
}
91
92
93
public function getIcon() {
94
switch ($this->getTransactionType()) {
95
case self::TYPE_EDIT:
96
return 'fa-pencil';
97
}
98
99
return parent::getIcon();
100
}
101
102
public function hasChangeDetails() {
103
switch ($this->getTransactionType()) {
104
case self::TYPE_EDIT:
105
return true;
106
}
107
return parent::hasChangeDetails();
108
}
109
110
public function renderChangeDetails(PhabricatorUser $viewer) {
111
$old = $this->getOldValue();
112
$new = $this->getNewValue();
113
114
if ($old['deleted']) {
115
$old_text = '';
116
} else {
117
$old_text = PhabricatorConfigJSON::prettyPrintJSON($old['value']);
118
}
119
120
if ($new['deleted']) {
121
$new_text = '';
122
} else {
123
$new_text = PhabricatorConfigJSON::prettyPrintJSON($new['value']);
124
}
125
126
return $this->renderTextCorpusChangeDetails(
127
$viewer,
128
$old_text,
129
$new_text);
130
}
131
132
public function getColor() {
133
$old = $this->getOldValue();
134
$new = $this->getNewValue();
135
136
switch ($this->getTransactionType()) {
137
case self::TYPE_EDIT:
138
$old_del = idx($old, 'deleted');
139
$new_del = idx($new, 'deleted');
140
141
if ($old_del && !$new_del) {
142
return PhabricatorTransactions::COLOR_GREEN;
143
} else if (!$old_del && $new_del) {
144
return PhabricatorTransactions::COLOR_RED;
145
} else {
146
return PhabricatorTransactions::COLOR_BLUE;
147
}
148
break;
149
}
150
}
151
152
}
153
154