3 final class DifferentialTransactionComment
4 extends PhabricatorApplicationTransactionComment
6 PhabricatorInlineCommentInterface
{
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();
18 private $replyToComment = self
::ATTACHABLE
;
19 private $isHidden = self
::ATTACHABLE
;
20 private $changeset = self
::ATTACHABLE
;
21 private $inlineContext = self
::ATTACHABLE
;
23 public function getApplicationTransactionObject() {
24 return new DifferentialTransaction();
27 public function attachReplyToComment(
28 DifferentialTransactionComment
$comment = null) {
29 $this->replyToComment
= $comment;
33 public function getReplyToComment() {
34 return $this->assertAttached($this->replyToComment
);
37 protected function getConfiguration() {
38 $config = parent
::getConfiguration();
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
];
51 $config[self
::CONFIG_KEY_SCHEMA
] = array(
53 'columns' => array('authorPHID', 'transactionPHID'),
55 'key_changeset' => array(
56 'columns' => array('changesetID'),
58 'key_revision' => array(
59 'columns' => array('revisionPHID'),
61 ) +
$config[self
::CONFIG_KEY_SCHEMA
];
63 $config[self
::CONFIG_SERIALIZATION
] = array(
64 'attributes' => self
::SERIALIZATION_JSON
,
65 ) +
idx($config, self
::CONFIG_SERIALIZATION
, array());
70 public function shouldUseMarkupCache($field) {
71 // Only cache submitted comments.
72 return ($this->getTransactionPHID() != null);
75 public static function sortAndGroupInlines(
78 assert_instances_of($inlines, 'DifferentialTransaction');
79 assert_instances_of($changesets, 'DifferentialChangeset');
81 $changesets = mpull($changesets, null, 'getID');
82 $changesets = msort($changesets, 'getFilename');
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;
90 $inline_groups = array_select_keys($inline_groups, array_keys($changesets));
92 foreach ($inline_groups as $changeset_id => $group) {
93 // Sort the group of inlines by line number.
95 foreach ($group as $inline) {
96 $comment = $inline->getComment();
97 $num = $comment->getLineNumber();
98 $len = $comment->getLineLength();
99 $id = $comment->getID();
103 'sort' => sprintf('~%010d%010d%010d', $num, $len, $id),
107 $items = isort($items, 'sort');
108 $items = ipull($items, 'inline');
109 $inline_groups[$changeset_id] = $items;
112 return $inline_groups;
115 public function getIsHidden() {
116 return $this->assertAttached($this->isHidden
);
119 public function attachIsHidden($hidden) {
120 $this->isHidden
= $hidden;
124 public function getAttribute($key, $default = null) {
125 return idx($this->attributes
, $key, $default);
128 public function setAttribute($key, $value) {
129 $this->attributes
[$key] = $value;
133 public function newInlineCommentObject() {
134 return DifferentialInlineComment
::newFromModernComment($this);
137 public function getInlineContext() {
138 return $this->assertAttached($this->inlineContext
);
141 public function attachInlineContext(
142 PhabricatorInlineCommentContext
$context = null) {
143 $this->inlineContext
= $context;
148 public function isEmptyComment() {
149 if (!parent
::isEmptyComment()) {
153 return $this->newInlineCommentObject()
155 ->isEmptyContentState();