[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 final class PhabricatorAuditInlineComment 4 implements PhabricatorInlineCommentInterface { 5 6 private $proxy; 7 private $syntheticAuthor; 8 9 public function __construct() { 10 $this->proxy = new PhabricatorAuditTransactionComment(); 11 } 12 13 public function __clone() { 14 $this->proxy = clone $this->proxy; 15 } 16 17 public function getTransactionPHID() { 18 return $this->proxy->getTransactionPHID(); 19 } 20 21 public function getTransactionComment() { 22 return $this->proxy; 23 } 24 25 public function getTransactionCommentForSave() { 26 $content_source = PhabricatorContentSource::newForSource( 27 PhabricatorContentSource::SOURCE_LEGACY, 28 array()); 29 30 $this->proxy 31 ->setViewPolicy('public') 32 ->setEditPolicy($this->getAuthorPHID()) 33 ->setContentSource($content_source) 34 ->setCommentVersion(1); 35 36 return $this->proxy; 37 } 38 39 public static function loadID($id) { 40 $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 41 'id = %d', 42 $id); 43 if (!$inlines) { 44 return null; 45 } 46 47 return head(self::buildProxies($inlines)); 48 } 49 50 public static function loadDraftComments( 51 PhabricatorUser $viewer, 52 $commit_phid) { 53 54 $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 55 'authorPHID = %s AND commitPHID = %s AND transactionPHID IS NULL 56 AND pathID IS NOT NULL', 57 $viewer->getPHID(), 58 $commit_phid); 59 60 return self::buildProxies($inlines); 61 } 62 63 public static function loadPublishedComments( 64 PhabricatorUser $viewer, 65 $commit_phid) { 66 67 $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 68 'commitPHID = %s AND transactionPHID IS NOT NULL 69 AND pathID IS NOT NULL', 70 $commit_phid); 71 72 return self::buildProxies($inlines); 73 } 74 75 public static function loadDraftAndPublishedComments( 76 PhabricatorUser $viewer, 77 $commit_phid, 78 $path_id = null) { 79 80 if ($path_id === null) { 81 $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 82 'commitPHID = %s AND (transactionPHID IS NOT NULL OR authorPHID = %s) 83 AND pathID IS NOT NULL', 84 $commit_phid, 85 $viewer->getPHID()); 86 } else { 87 $inlines = id(new PhabricatorAuditTransactionComment())->loadAllWhere( 88 'commitPHID = %s AND pathID = %d AND 89 (authorPHID = %s OR transactionPHID IS NOT NULL)', 90 $commit_phid, 91 $path_id, 92 $viewer->getPHID()); 93 } 94 95 return self::buildProxies($inlines); 96 } 97 98 private static function buildProxies(array $inlines) { 99 $results = array(); 100 foreach ($inlines as $key => $inline) { 101 $results[$key] = PhabricatorAuditInlineComment::newFromModernComment( 102 $inline); 103 } 104 return $results; 105 } 106 107 public function setSyntheticAuthor($synthetic_author) { 108 $this->syntheticAuthor = $synthetic_author; 109 return $this; 110 } 111 112 public function getSyntheticAuthor() { 113 return $this->syntheticAuthor; 114 } 115 116 public function openTransaction() { 117 $this->proxy->openTransaction(); 118 } 119 120 public function saveTransaction() { 121 $this->proxy->saveTransaction(); 122 } 123 124 public function save() { 125 $this->getTransactionCommentForSave()->save(); 126 127 return $this; 128 } 129 130 public function delete() { 131 $this->proxy->delete(); 132 133 return $this; 134 } 135 136 public function getID() { 137 return $this->proxy->getID(); 138 } 139 140 public function getPHID() { 141 return $this->proxy->getPHID(); 142 } 143 144 public static function newFromModernComment( 145 PhabricatorAuditTransactionComment $comment) { 146 147 $obj = new PhabricatorAuditInlineComment(); 148 $obj->proxy = $comment; 149 150 return $obj; 151 } 152 153 public function isCompatible(PhabricatorInlineCommentInterface $comment) { 154 return 155 ($this->getAuthorPHID() === $comment->getAuthorPHID()) && 156 ($this->getSyntheticAuthor() === $comment->getSyntheticAuthor()) && 157 ($this->getContent() === $comment->getContent()); 158 } 159 160 public function setContent($content) { 161 $this->proxy->setContent($content); 162 return $this; 163 } 164 165 public function getContent() { 166 return $this->proxy->getContent(); 167 } 168 169 public function isDraft() { 170 return !$this->proxy->getTransactionPHID(); 171 } 172 173 public function setPathID($id) { 174 $this->proxy->setPathID($id); 175 return $this; 176 } 177 178 public function getPathID() { 179 return $this->proxy->getPathID(); 180 } 181 182 public function setIsNewFile($is_new) { 183 $this->proxy->setIsNewFile($is_new); 184 return $this; 185 } 186 187 public function getIsNewFile() { 188 return $this->proxy->getIsNewFile(); 189 } 190 191 public function setLineNumber($number) { 192 $this->proxy->setLineNumber($number); 193 return $this; 194 } 195 196 public function getLineNumber() { 197 return $this->proxy->getLineNumber(); 198 } 199 200 public function setLineLength($length) { 201 $this->proxy->setLineLength($length); 202 return $this; 203 } 204 205 public function getLineLength() { 206 return $this->proxy->getLineLength(); 207 } 208 209 public function setCache($cache) { 210 return $this; 211 } 212 213 public function getCache() { 214 return null; 215 } 216 217 public function setAuthorPHID($phid) { 218 $this->proxy->setAuthorPHID($phid); 219 return $this; 220 } 221 222 public function getAuthorPHID() { 223 return $this->proxy->getAuthorPHID(); 224 } 225 226 public function setCommitPHID($commit_phid) { 227 $this->proxy->setCommitPHID($commit_phid); 228 return $this; 229 } 230 231 public function getCommitPHID() { 232 return $this->proxy->getCommitPHID(); 233 } 234 235 // When setting a comment ID, we also generate a phantom transaction PHID for 236 // the future transaction. 237 238 public function setAuditCommentID($id) { 239 $this->proxy->setLegacyCommentID($id); 240 $this->proxy->setTransactionPHID( 241 PhabricatorPHID::generateNewPHID( 242 PhabricatorApplicationTransactionTransactionPHIDType::TYPECONST, 243 PhabricatorRepositoryCommitPHIDType::TYPECONST)); 244 return $this; 245 } 246 247 public function getAuditCommentID() { 248 return $this->proxy->getLegacyCommentID(); 249 } 250 251 public function setChangesetID($id) { 252 return $this->setPathID($id); 253 } 254 255 public function getChangesetID() { 256 return $this->getPathID(); 257 } 258 259 260 /* -( PhabricatorMarkupInterface Implementation )-------------------------- */ 261 262 263 public function getMarkupFieldKey($field) { 264 return 'AI:'.$this->getID(); 265 } 266 267 public function newMarkupEngine($field) { 268 return PhabricatorMarkupEngine::newDifferentialMarkupEngine(); 269 } 270 271 public function getMarkupText($field) { 272 return $this->getContent(); 273 } 274 275 public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { 276 return $output; 277 } 278 279 public function shouldUseMarkupCache($field) { 280 // Only cache submitted comments. 281 return ($this->getID() && $this->getAuditCommentID()); 282 } 283 284 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |