@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

Apply normal Audit actions directly with Transaction editor

Summary: Ref T4896. This converts the last "CommentEditor" to a transaction editor and removes a large part of the old code.

Test Plan:
- Added comments.
- Accepted / added auditors.
- Added inline comments.

Reviewers: joshuaspence, btrahan

Reviewed By: btrahan

Subscribers: epriestley

Maniphest Tasks: T4896

Differential Revision: https://secure.phabricator.com/D10128

+32 -276
-2
src/__phutil_library_map__.php
··· 1136 1136 'PhabricatorAuditActionConstants' => 'applications/audit/constants/PhabricatorAuditActionConstants.php', 1137 1137 'PhabricatorAuditAddCommentController' => 'applications/audit/controller/PhabricatorAuditAddCommentController.php', 1138 1138 'PhabricatorAuditApplication' => 'applications/audit/application/PhabricatorAuditApplication.php', 1139 - 'PhabricatorAuditComment' => 'applications/audit/storage/PhabricatorAuditComment.php', 1140 1139 'PhabricatorAuditCommentEditor' => 'applications/audit/editor/PhabricatorAuditCommentEditor.php', 1141 1140 'PhabricatorAuditCommitStatusConstants' => 'applications/audit/constants/PhabricatorAuditCommitStatusConstants.php', 1142 1141 'PhabricatorAuditController' => 'applications/audit/controller/PhabricatorAuditController.php', ··· 3931 3930 'PhabricatorAsanaConfigOptions' => 'PhabricatorApplicationConfigOptions', 3932 3931 'PhabricatorAuditAddCommentController' => 'PhabricatorAuditController', 3933 3932 'PhabricatorAuditApplication' => 'PhabricatorApplication', 3934 - 'PhabricatorAuditComment' => 'PhabricatorMarkupInterface', 3935 3933 'PhabricatorAuditCommentEditor' => 'PhabricatorEditor', 3936 3934 'PhabricatorAuditController' => 'PhabricatorController', 3937 3935 'PhabricatorAuditDAO' => 'PhabricatorLiskDAO',
+31 -18
src/applications/audit/controller/PhabricatorAuditAddCommentController.php
··· 21 21 return new Aphront404Response(); 22 22 } 23 23 24 - $phids = array($commit_phid); 25 - 26 - $comments = array(); 24 + $xactions = array(); 27 25 28 26 // make sure we only add auditors or ccs if the action matches 29 27 $action = $request->getStr('action'); 30 28 switch ($action) { 31 29 case PhabricatorAuditActionConstants::ADD_AUDITORS: 32 30 $auditors = $request->getArr('auditors'); 33 - $comments[] = id(new PhabricatorAuditComment()) 34 - ->setAction(PhabricatorAuditActionConstants::ADD_AUDITORS) 31 + $xactions[] = id(new PhabricatorAuditTransaction()) 32 + ->setTransactionType(PhabricatorAuditActionConstants::ADD_AUDITORS) 35 33 ->setNewValue(array_fuse($auditors)); 36 34 break; 37 35 case PhabricatorAuditActionConstants::ADD_CCS: 38 - $comments[] = id(new PhabricatorAuditComment()) 39 - ->setAction(PhabricatorTransactions::TYPE_SUBSCRIBERS) 36 + $xactions[] = id(new PhabricatorAuditTransaction()) 37 + ->setTransactionType(PhabricatorTransactions::TYPE_SUBSCRIBERS) 40 38 ->setNewValue( 41 39 array( 42 40 '+' => $request->getArr('ccs'), ··· 46 44 // We'll deal with this below. 47 45 break; 48 46 default: 49 - $comments[] = id(new PhabricatorAuditComment()) 50 - ->setAction($action); 47 + $xactions[] = id(new PhabricatorAuditTransaction()) 48 + ->setTransactionType(PhabricatorAuditActionConstants::ACTION) 49 + ->setNewValue($action); 51 50 break; 52 51 } 53 52 54 53 $content = $request->getStr('content'); 55 54 if (strlen($content)) { 56 - $comments[] = id(new PhabricatorAuditComment()) 57 - ->setAction(PhabricatorAuditActionConstants::COMMENT) 58 - ->setContent($content); 55 + $xactions[] = id(new PhabricatorAuditTransaction()) 56 + ->setTransactionType(PhabricatorTransactions::TYPE_COMMENT) 57 + ->attachComment( 58 + id(new PhabricatorAuditTransactionComment()) 59 + ->setCommitPHID($commit->getPHID()) 60 + ->setContent($content)); 61 + } 62 + 63 + $inlines = PhabricatorAuditInlineComment::loadDraftComments( 64 + $user, 65 + $commit->getPHID()); 66 + foreach ($inlines as $inline) { 67 + $xactions[] = id(new PhabricatorAuditTransaction()) 68 + ->setTransactionType(PhabricatorAuditActionConstants::INLINE) 69 + ->attachComment($inline->getTransactionComment()); 59 70 } 60 71 61 - id(new PhabricatorAuditCommentEditor($commit)) 72 + id(new PhabricatorAuditEditor()) 62 73 ->setActor($user) 63 - ->setAttachInlineComments(true) 64 - ->addComments($comments); 65 - 66 - $handles = $this->loadViewerHandles($phids); 67 - $uri = $handles[$commit_phid]->getURI(); 74 + ->setContentSourceFromRequest($request) 75 + ->setContinueOnMissingFields(true) 76 + ->applyTransactions($commit, $xactions); 68 77 69 78 $draft = id(new PhabricatorDraft())->loadOneWhere( 70 79 'authorPHID = %s AND draftKey = %s', ··· 73 82 if ($draft) { 74 83 $draft->delete(); 75 84 } 85 + 86 + $monogram = $commit->getRepository()->getMonogram(); 87 + $identifier = $commit->getCommitIdentifier(); 88 + $uri = '/'.$monogram.$identifier; 76 89 77 90 return id(new AphrontRedirectResponse())->setURI($uri); 78 91 }
-58
src/applications/audit/editor/PhabricatorAuditCommentEditor.php
··· 2 2 3 3 final class PhabricatorAuditCommentEditor extends PhabricatorEditor { 4 4 5 - private $commit; 6 - private $attachInlineComments; 7 - 8 - public function __construct(PhabricatorRepositoryCommit $commit) { 9 - $this->commit = $commit; 10 - return $this; 11 - } 12 - 13 - public function setAttachInlineComments($attach_inline_comments) { 14 - $this->attachInlineComments = $attach_inline_comments; 15 - return $this; 16 - } 17 - 18 - public function addComments(array $comments) { 19 - assert_instances_of($comments, 'PhabricatorAuditComment'); 20 - 21 - $commit = $this->commit; 22 - $actor = $this->getActor(); 23 - 24 - $other_comments = PhabricatorAuditComment::loadComments( 25 - $actor, 26 - $commit->getPHID()); 27 - 28 - $inline_comments = array(); 29 - if ($this->attachInlineComments) { 30 - $inline_comments = PhabricatorAuditInlineComment::loadDraftComments( 31 - $actor, 32 - $commit->getPHID()); 33 - } 34 - 35 - // Convert old comments into real transactions and apply them with a 36 - // normal editor. 37 - 38 - $xactions = array(); 39 - foreach ($comments as $comment) { 40 - $xactions[] = $comment->getTransactionForSave(); 41 - } 42 - 43 - foreach ($inline_comments as $inline) { 44 - $xactions[] = id(new PhabricatorAuditTransaction()) 45 - ->setTransactionType(PhabricatorAuditActionConstants::INLINE) 46 - ->attachComment($inline->getTransactionComment()); 47 - } 48 - 49 - $content_source = PhabricatorContentSource::newForSource( 50 - PhabricatorContentSource::SOURCE_LEGACY, 51 - array()); 52 - 53 - $editor = id(new PhabricatorAuditEditor()) 54 - ->setActor($actor) 55 - ->setContinueOnNoEffect(true) 56 - ->setContinueOnMissingFields(true) 57 - ->setContentSource($content_source) 58 - ->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs()) 59 - ->applyTransactions($commit, $xactions); 60 - } 61 - 62 - 63 5 /** 64 6 * Load the PHIDs for all objects the user has the authority to act as an 65 7 * audit for. This includes themselves, and any packages they are an owner
+1 -1
src/applications/audit/mail/PhabricatorAuditReplyHandler.php
··· 52 52 ->setCommitPHID($commit->getPHID()) 53 53 ->setContent($message)); 54 54 55 - $editor = id(new PhabricatorAuditEditor($commit)) 55 + $editor = id(new PhabricatorAuditEditor()) 56 56 ->setActor($actor) 57 57 ->setContentSource($content_source) 58 58 ->setExcludeMailRecipientPHIDs($this->getExcludeMailRecipientPHIDs())
-197
src/applications/audit/storage/PhabricatorAuditComment.php
··· 1 - <?php 2 - 3 - final class PhabricatorAuditComment 4 - implements PhabricatorMarkupInterface { 5 - 6 - const MARKUP_FIELD_BODY = 'markup:body'; 7 - 8 - private $proxyComment; 9 - private $proxy; 10 - 11 - public function __construct() { 12 - $this->proxy = new PhabricatorAuditTransaction(); 13 - } 14 - 15 - public function __clone() { 16 - $this->proxy = clone $this->proxy; 17 - if ($this->proxyComment) { 18 - $this->proxyComment = clone $this->proxyComment; 19 - } 20 - } 21 - 22 - public static function newFromModernTransaction( 23 - PhabricatorAuditTransaction $xaction) { 24 - 25 - $obj = new PhabricatorAuditComment(); 26 - $obj->proxy = $xaction; 27 - 28 - if ($xaction->hasComment()) { 29 - $obj->proxyComment = $xaction->getComment(); 30 - } 31 - 32 - return $obj; 33 - } 34 - 35 - public static function loadComments( 36 - PhabricatorUser $viewer, 37 - $commit_phid) { 38 - 39 - $xactions = id(new PhabricatorAuditTransactionQuery()) 40 - ->setViewer($viewer) 41 - ->withObjectPHIDs(array($commit_phid)) 42 - ->needComments(true) 43 - ->execute(); 44 - 45 - $comments = array(); 46 - foreach ($xactions as $xaction) { 47 - $comments[] = self::newFromModernTransaction($xaction); 48 - } 49 - 50 - return $comments; 51 - } 52 - 53 - public function getPHID() { 54 - return $this->proxy->getPHID(); 55 - } 56 - 57 - public function getActorPHID() { 58 - return $this->proxy->getAuthorPHID(); 59 - } 60 - 61 - public function setActorPHID($actor_phid) { 62 - $this->proxy->setAuthorPHID($actor_phid); 63 - return $this; 64 - } 65 - 66 - public function setTargetPHID($target_phid) { 67 - $this->getProxyComment()->setCommitPHID($target_phid); 68 - $this->proxy->setObjectPHID($target_phid); 69 - return $this; 70 - } 71 - 72 - public function getTargetPHID() { 73 - return $this->proxy->getObjectPHID(); 74 - } 75 - 76 - public function getContent() { 77 - return $this->getProxyComment()->getContent(); 78 - } 79 - 80 - public function setContent($content) { 81 - $this->getProxyComment()->setContent($content); 82 - return $this; 83 - } 84 - 85 - public function setContentSource($content_source) { 86 - $this->proxy->setContentSource($content_source); 87 - $this->proxyComment->setContentSource($content_source); 88 - return $this; 89 - } 90 - 91 - public function getContentSource() { 92 - return $this->proxy->getContentSource(); 93 - } 94 - 95 - private function getProxyComment() { 96 - if (!$this->proxyComment) { 97 - $this->proxyComment = new PhabricatorAuditTransactionComment(); 98 - } 99 - return $this->proxyComment; 100 - } 101 - 102 - public function setProxyComment(PhabricatorAuditTransactionComment $proxy) { 103 - if ($this->proxyComment) { 104 - throw new Exception(pht('You can not overwrite a proxy comment.')); 105 - } 106 - $this->proxyComment = $proxy; 107 - return $this; 108 - } 109 - 110 - public function setAction($action) { 111 - switch ($action) { 112 - case PhabricatorAuditActionConstants::INLINE: 113 - case PhabricatorAuditActionConstants::ADD_CCS: 114 - case PhabricatorTransactions::TYPE_SUBSCRIBERS: 115 - case PhabricatorAuditActionConstants::ADD_AUDITORS: 116 - $this->proxy->setTransactionType($action); 117 - break; 118 - case PhabricatorAuditActionConstants::COMMENT: 119 - $this->proxy->setTransactionType(PhabricatorTransactions::TYPE_COMMENT); 120 - break; 121 - default: 122 - $this->proxy 123 - ->setTransactionType(PhabricatorAuditActionConstants::ACTION) 124 - ->setNewValue($action); 125 - break; 126 - } 127 - 128 - return $this; 129 - } 130 - 131 - public function getAction() { 132 - $type = $this->proxy->getTransactionType(); 133 - switch ($type) { 134 - case PhabricatorTransactions::TYPE_COMMENT: 135 - return PhabricatorAuditActionConstants::COMMENT; 136 - case PhabricatorAuditActionConstants::INLINE: 137 - case PhabricatorAuditActionConstants::ADD_CCS: 138 - case PhabricatorTransactions::TYPE_SUBSCRIBERS: 139 - case PhabricatorAuditActionConstants::ADD_AUDITORS: 140 - return $type; 141 - default: 142 - return $this->proxy->getNewValue(); 143 - } 144 - } 145 - 146 - public function save() { 147 - throw new Exception( 148 - pht('This object can no longer be written to directly!')); 149 - } 150 - 151 - public function getTransactionForSave() { 152 - $xaction = $this->proxy; 153 - if (strlen($this->getContent())) { 154 - $xaction->attachComment($this->getProxyComment()); 155 - } 156 - 157 - return $xaction; 158 - } 159 - 160 - public function setNewValue($value) { 161 - $this->proxy->setNewValue($value); 162 - return $this; 163 - } 164 - 165 - public function getDateCreated() { 166 - return $this->proxy->getDateCreated(); 167 - } 168 - 169 - public function getDateModified() { 170 - return $this->proxy->getDateModified(); 171 - } 172 - 173 - 174 - /* -( PhabricatorMarkupInterface Implementation )-------------------------- */ 175 - 176 - 177 - public function getMarkupFieldKey($field) { 178 - return 'AC:'.$this->getPHID(); 179 - } 180 - 181 - public function newMarkupEngine($field) { 182 - return PhabricatorMarkupEngine::newDiffusionMarkupEngine(); 183 - } 184 - 185 - public function getMarkupText($field) { 186 - return $this->getContent(); 187 - } 188 - 189 - public function didMarkupText($field, $output, PhutilMarkupEngine $engine) { 190 - return $output; 191 - } 192 - 193 - public function shouldUseMarkupCache($field) { 194 - return (bool)$this->getPHID(); 195 - } 196 - 197 - }