Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/audit/view/PhabricatorAuditTransactionView.php
12256 views
1
<?php
2
3
final class PhabricatorAuditTransactionView
4
extends PhabricatorApplicationTransactionView {
5
6
private $pathMap = array();
7
8
public function setPathMap(array $path_map) {
9
$this->pathMap = $path_map;
10
return $this;
11
}
12
13
public function getPathMap() {
14
return $this->pathMap;
15
}
16
17
// TODO: This shares a lot of code with Differential and Pholio and should
18
// probably be merged up.
19
20
protected function shouldGroupTransactions(
21
PhabricatorApplicationTransaction $u,
22
PhabricatorApplicationTransaction $v) {
23
24
if ($u->getAuthorPHID() != $v->getAuthorPHID()) {
25
// Don't group transactions by different authors.
26
return false;
27
}
28
29
if (($v->getDateCreated() - $u->getDateCreated()) > 60) {
30
// Don't group if transactions that happened more than 60s apart.
31
return false;
32
}
33
34
switch ($u->getTransactionType()) {
35
case PhabricatorTransactions::TYPE_COMMENT:
36
case PhabricatorAuditActionConstants::INLINE:
37
break;
38
default:
39
return false;
40
}
41
42
switch ($v->getTransactionType()) {
43
case PhabricatorAuditActionConstants::INLINE:
44
return true;
45
}
46
47
return parent::shouldGroupTransactions($u, $v);
48
}
49
50
protected function renderTransactionContent(
51
PhabricatorApplicationTransaction $xaction) {
52
53
$out = array();
54
55
$type_inline = PhabricatorAuditActionConstants::INLINE;
56
57
$group = $xaction->getTransactionGroup();
58
59
if ($xaction->getTransactionType() == $type_inline) {
60
array_unshift($group, $xaction);
61
} else {
62
$out[] = parent::renderTransactionContent($xaction);
63
}
64
65
if ($this->getIsPreview()) {
66
return $out;
67
}
68
69
if (!$group) {
70
return $out;
71
}
72
73
$inlines = array();
74
foreach ($group as $xaction) {
75
switch ($xaction->getTransactionType()) {
76
case PhabricatorAuditActionConstants::INLINE:
77
$inlines[] = $xaction;
78
break;
79
default:
80
throw new Exception(pht('Unknown grouped transaction type!'));
81
}
82
}
83
84
$structs = array();
85
foreach ($inlines as $key => $inline) {
86
$comment = $inline->getComment();
87
if (!$comment) {
88
// TODO: Migrate these away? They probably do not exist on normal
89
// non-development installs.
90
unset($inlines[$key]);
91
continue;
92
}
93
94
$path_id = $comment->getPathID();
95
$path = idx($this->pathMap, $path_id);
96
if ($path === null) {
97
continue;
98
}
99
100
$structs[] = array(
101
'inline' => $inline,
102
'path' => $path,
103
'sort' => (string)id(new PhutilSortVector())
104
->addString($path)
105
->addInt($comment->getLineNumber())
106
->addInt($comment->getLineLength())
107
->addInt($inline->getID()),
108
);
109
}
110
111
if (!$structs) {
112
return $out;
113
}
114
115
$structs = isort($structs, 'sort');
116
$structs = igroup($structs, 'path');
117
118
$inline_view = new PhabricatorInlineSummaryView();
119
foreach ($structs as $path => $group) {
120
$inlines = ipull($group, 'inline');
121
$items = array();
122
foreach ($inlines as $inline) {
123
$comment = $inline->getComment();
124
$items[] = array(
125
'id' => $comment->getID(),
126
'line' => $comment->getLineNumber(),
127
'length' => $comment->getLineLength(),
128
'content' => parent::renderTransactionContent($inline),
129
);
130
}
131
$inline_view->addCommentGroup($path, $items);
132
}
133
134
$out[] = $inline_view;
135
136
return $out;
137
}
138
139
}
140
141