3 abstract class PhabricatorApplicationTransactionComment
4 extends PhabricatorLiskDAO
6 PhabricatorMarkupInterface
,
7 PhabricatorPolicyInterface
,
8 PhabricatorDestructibleInterface
{
10 const MARKUP_FIELD_COMMENT
= 'markup:comment';
12 protected $transactionPHID;
13 protected $commentVersion;
14 protected $authorPHID;
15 protected $viewPolicy;
16 protected $editPolicy;
18 protected $contentSource;
19 protected $isDeleted = 0;
21 private $oldComment = self
::ATTACHABLE
;
23 abstract public function getApplicationTransactionObject();
25 public function generatePHID() {
26 return PhabricatorPHID
::generateNewPHID(
27 PhabricatorPHIDConstants
::PHID_TYPE_XCMT
);
30 protected function getConfiguration() {
32 self
::CONFIG_AUX_PHID
=> true,
33 self
::CONFIG_COLUMN_SCHEMA
=> array(
34 'transactionPHID' => 'phid?',
35 'commentVersion' => 'uint32',
37 'contentSource' => 'text',
38 'isDeleted' => 'bool',
40 self
::CONFIG_KEY_SCHEMA
=> array(
41 'key_version' => array(
42 'columns' => array('transactionPHID', 'commentVersion'),
46 ) + parent
::getConfiguration();
49 public function getApplicationName() {
50 return $this->getApplicationTransactionObject()->getApplicationName();
53 public function getTableName() {
54 $xaction = $this->getApplicationTransactionObject();
55 return self
::getTableNameFromTransaction($xaction);
58 public static function getTableNameFromTransaction(
59 PhabricatorApplicationTransaction
$xaction) {
60 return $xaction->getTableName().'_comment';
63 public function setContentSource(PhabricatorContentSource
$content_source) {
64 $this->contentSource
= $content_source->serialize();
68 public function setContentSourceFromRequest(AphrontRequest
$request) {
69 return $this->setContentSource(
70 PhabricatorContentSource
::newFromRequest($request));
73 public function getContentSource() {
74 return PhabricatorContentSource
::newFromSerialized($this->contentSource
);
77 public function getIsRemoved() {
78 return ($this->getIsDeleted() == 2);
81 public function setIsRemoved($removed) {
83 $this->setIsDeleted(2);
85 $this->setIsDeleted(0);
90 public function attachOldComment(
91 PhabricatorApplicationTransactionComment
$old_comment) {
92 $this->oldComment
= $old_comment;
96 public function getOldComment() {
97 return $this->assertAttached($this->oldComment
);
100 public function hasOldComment() {
101 return ($this->oldComment
!== self
::ATTACHABLE
);
104 public function getRawRemarkupURI() {
106 '/transactions/raw/%s/',
107 $this->getTransactionPHID());
110 public function isEmptyComment() {
111 $content = $this->getContent();
113 // The comment is empty if there's no content, or if the content only has
115 if (!strlen(trim($content))) {
122 /* -( PhabricatorMarkupInterface )----------------------------------------- */
125 public function getMarkupFieldKey($field) {
126 return PhabricatorPHIDConstants
::PHID_TYPE_XCMT
.':'.$this->getPHID();
130 public function newMarkupEngine($field) {
131 return PhabricatorMarkupEngine
::getEngine();
135 public function getMarkupText($field) {
136 return $this->getContent();
140 public function didMarkupText($field, $output, PhutilMarkupEngine
$engine) {
141 require_celerity_resource('phabricator-remarkup-css');
145 'class' => 'phabricator-remarkup',
151 public function shouldUseMarkupCache($field) {
152 return (bool)$this->getPHID();
155 /* -( PhabricatorPolicyInterface Implementation )-------------------------- */
158 public function getCapabilities() {
160 PhabricatorPolicyCapability
::CAN_VIEW
,
161 PhabricatorPolicyCapability
::CAN_EDIT
,
165 public function getPolicy($capability) {
166 switch ($capability) {
167 case PhabricatorPolicyCapability
::CAN_VIEW
:
168 return $this->getViewPolicy();
169 case PhabricatorPolicyCapability
::CAN_EDIT
:
170 return $this->getEditPolicy();
174 public function hasAutomaticCapability($capability, PhabricatorUser
$viewer) {
175 return ($viewer->getPHID() == $this->getAuthorPHID());
178 public function describeAutomaticCapability($capability) {
180 'Comments are visible to users who can see the object which was '.
181 'commented on. Comments can be edited by their authors.');
185 /* -( PhabricatorDestructibleInterface )----------------------------------- */
187 public function destroyObjectPermanently(
188 PhabricatorDestructionEngine
$engine) {
189 $this->openTransaction();
191 $this->saveTransaction();