Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/differential/storage/DifferentialTransactionComment.php
12256 views
1
<?php
2
3
final class DifferentialTransactionComment
4
extends PhabricatorApplicationTransactionComment
5
implements
6
PhabricatorInlineCommentInterface {
7
8
protected $revisionPHID;
9
protected $changesetID;
10
protected $isNewFile = 0;
11
protected $lineNumber = 0;
12
protected $lineLength = 0;
13
protected $fixedState;
14
protected $hasReplies = 0;
15
protected $replyToCommentPHID;
16
protected $attributes = array();
17
18
private $replyToComment = self::ATTACHABLE;
19
private $isHidden = self::ATTACHABLE;
20
private $changeset = self::ATTACHABLE;
21
private $inlineContext = self::ATTACHABLE;
22
23
public function getApplicationTransactionObject() {
24
return new DifferentialTransaction();
25
}
26
27
public function attachReplyToComment(
28
DifferentialTransactionComment $comment = null) {
29
$this->replyToComment = $comment;
30
return $this;
31
}
32
33
public function getReplyToComment() {
34
return $this->assertAttached($this->replyToComment);
35
}
36
37
protected function getConfiguration() {
38
$config = parent::getConfiguration();
39
40
$config[self::CONFIG_COLUMN_SCHEMA] = array(
41
'revisionPHID' => 'phid?',
42
'changesetID' => 'id?',
43
'isNewFile' => 'bool',
44
'lineNumber' => 'uint32',
45
'lineLength' => 'uint32',
46
'fixedState' => 'text12?',
47
'hasReplies' => 'bool',
48
'replyToCommentPHID' => 'phid?',
49
) + $config[self::CONFIG_COLUMN_SCHEMA];
50
51
$config[self::CONFIG_KEY_SCHEMA] = array(
52
'key_draft' => array(
53
'columns' => array('authorPHID', 'transactionPHID'),
54
),
55
'key_changeset' => array(
56
'columns' => array('changesetID'),
57
),
58
'key_revision' => array(
59
'columns' => array('revisionPHID'),
60
),
61
) + $config[self::CONFIG_KEY_SCHEMA];
62
63
$config[self::CONFIG_SERIALIZATION] = array(
64
'attributes' => self::SERIALIZATION_JSON,
65
) + idx($config, self::CONFIG_SERIALIZATION, array());
66
67
return $config;
68
}
69
70
public function shouldUseMarkupCache($field) {
71
// Only cache submitted comments.
72
return ($this->getTransactionPHID() != null);
73
}
74
75
public static function sortAndGroupInlines(
76
array $inlines,
77
array $changesets) {
78
assert_instances_of($inlines, 'DifferentialTransaction');
79
assert_instances_of($changesets, 'DifferentialChangeset');
80
81
$changesets = mpull($changesets, null, 'getID');
82
$changesets = msort($changesets, 'getFilename');
83
84
// Group the changesets by file and reorder them by display order.
85
$inline_groups = array();
86
foreach ($inlines as $inline) {
87
$changeset_id = $inline->getComment()->getChangesetID();
88
$inline_groups[$changeset_id][] = $inline;
89
}
90
$inline_groups = array_select_keys($inline_groups, array_keys($changesets));
91
92
foreach ($inline_groups as $changeset_id => $group) {
93
// Sort the group of inlines by line number.
94
$items = array();
95
foreach ($group as $inline) {
96
$comment = $inline->getComment();
97
$num = $comment->getLineNumber();
98
$len = $comment->getLineLength();
99
$id = $comment->getID();
100
101
$items[] = array(
102
'inline' => $inline,
103
'sort' => sprintf('~%010d%010d%010d', $num, $len, $id),
104
);
105
}
106
107
$items = isort($items, 'sort');
108
$items = ipull($items, 'inline');
109
$inline_groups[$changeset_id] = $items;
110
}
111
112
return $inline_groups;
113
}
114
115
public function getIsHidden() {
116
return $this->assertAttached($this->isHidden);
117
}
118
119
public function attachIsHidden($hidden) {
120
$this->isHidden = $hidden;
121
return $this;
122
}
123
124
public function getAttribute($key, $default = null) {
125
return idx($this->attributes, $key, $default);
126
}
127
128
public function setAttribute($key, $value) {
129
$this->attributes[$key] = $value;
130
return $this;
131
}
132
133
public function newInlineCommentObject() {
134
return DifferentialInlineComment::newFromModernComment($this);
135
}
136
137
public function getInlineContext() {
138
return $this->assertAttached($this->inlineContext);
139
}
140
141
public function attachInlineContext(
142
PhabricatorInlineCommentContext $context = null) {
143
$this->inlineContext = $context;
144
return $this;
145
}
146
147
148
public function isEmptyComment() {
149
if (!parent::isEmptyComment()) {
150
return false;
151
}
152
153
return $this->newInlineCommentObject()
154
->getContentState()
155
->isEmptyContentState();
156
}
157
158
159
}
160
161