Remove all "FileHasObject" edge reads and writes
[phabricator.git] / src / applications / transactions / storage / PhabricatorApplicationTransactionComment.php
blob00cad18d2ddb2c3dc08388cf98ebe445d10723fa
1 <?php
3 abstract class PhabricatorApplicationTransactionComment
4 extends PhabricatorLiskDAO
5 implements
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;
17 protected $content;
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() {
31 return array(
32 self::CONFIG_AUX_PHID => true,
33 self::CONFIG_COLUMN_SCHEMA => array(
34 'transactionPHID' => 'phid?',
35 'commentVersion' => 'uint32',
36 'content' => 'text',
37 'contentSource' => 'text',
38 'isDeleted' => 'bool',
40 self::CONFIG_KEY_SCHEMA => array(
41 'key_version' => array(
42 'columns' => array('transactionPHID', 'commentVersion'),
43 'unique' => true,
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();
65 return $this;
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) {
82 if ($removed) {
83 $this->setIsDeleted(2);
84 } else {
85 $this->setIsDeleted(0);
87 return $this;
90 public function attachOldComment(
91 PhabricatorApplicationTransactionComment $old_comment) {
92 $this->oldComment = $old_comment;
93 return $this;
96 public function getOldComment() {
97 return $this->assertAttached($this->oldComment);
100 public function hasOldComment() {
101 return ($this->oldComment !== self::ATTACHABLE);
104 public function getRawRemarkupURI() {
105 return urisprintf(
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
114 // whitespace.
115 if (!strlen(trim($content))) {
116 return true;
119 return false;
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');
142 return phutil_tag(
143 'div',
144 array(
145 'class' => 'phabricator-remarkup',
147 $output);
151 public function shouldUseMarkupCache($field) {
152 return (bool)$this->getPHID();
155 /* -( PhabricatorPolicyInterface Implementation )-------------------------- */
158 public function getCapabilities() {
159 return array(
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) {
179 return pht(
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();
190 $this->delete();
191 $this->saveTransaction();