@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.

Remove willWriteRevision/didWriteRevision hooks

Summary:
Ref T2222. DifferentialRevisionEditor has no remaining callsites, but it has a bit of functionality which still needs to be ported forward. I'm going to rip it apart piece by piece.

This removes the willWriteRevision/didWriteRevision hooks. They are completely encapsulated by transactions now, except for a unique piece of branch/task logic, which I migrated forward.

Test Plan:
- Lots of `grep`.
- Created a new revision on branch `T25`, saw it associate with the task.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2222

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

+35 -212
-40
src/applications/differential/editor/DifferentialRevisionEditor.php
··· 161 161 162 162 $revision->loadRelationships(); 163 163 164 - $this->willWriteRevision(); 165 - 166 164 if ($this->reviewers === null) { 167 165 $this->reviewers = $revision->getReviewers(); 168 166 } ··· 437 435 break; 438 436 } 439 437 440 - $this->didWriteRevision(); 441 - 442 438 $event_data = array( 443 439 'revision_id' => $revision->getID(), 444 440 'revision_phid' => $revision->getPHID(), ··· 688 684 } 689 685 } 690 686 } 691 - } 692 - 693 - private function willWriteRevision() { 694 - foreach ($this->auxiliaryFields as $aux_field) { 695 - $aux_field->willWriteRevision($this); 696 - } 697 - 698 - $this->dispatchEvent( 699 - PhabricatorEventType::TYPE_DIFFERENTIAL_WILLEDITREVISION); 700 - } 701 - 702 - private function didWriteRevision() { 703 - foreach ($this->auxiliaryFields as $aux_field) { 704 - $aux_field->didWriteRevision($this); 705 - } 706 - 707 - $this->dispatchEvent( 708 - PhabricatorEventType::TYPE_DIFFERENTIAL_DIDEDITREVISION); 709 - } 710 - 711 - private function dispatchEvent($type) { 712 - $event = new PhabricatorEvent( 713 - $type, 714 - array( 715 - 'revision' => $this->revision, 716 - 'new' => $this->isCreate, 717 - )); 718 - 719 - $event->setUser($this->getActor()); 720 - 721 - $request = $this->getAphrontRequestForEventDispatch(); 722 - if ($request) { 723 - $event->setAphrontRequest($request); 724 - } 725 - 726 - PhutilEventEngine::dispatchEvent($event); 727 687 } 728 688 729 689 /**
+35 -1
src/applications/differential/editor/DifferentialTransactionEditor.php
··· 226 226 $actor = $this->getActor(); 227 227 $actor_phid = $actor->getPHID(); 228 228 $type_edge = PhabricatorTransactions::TYPE_EDGE; 229 + 229 230 $edge_reviewer = PhabricatorEdgeConfig::TYPE_DREV_HAS_REVIEWER; 231 + $edge_ref_task = PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK; 230 232 231 233 $results = parent::expandTransaction($object, $xaction); 232 234 switch ($xaction->getTransactionType()) { ··· 265 267 ->setMetadataValue('edge:type', $edge_reviewer) 266 268 ->setIgnoreOnNoEffect(true) 267 269 ->setNewValue(array('+' => $edits)); 270 + } 271 + 272 + // When a revision is updated and the diff comes from a branch named 273 + // "T123" or similar, automatically associate the commit with the 274 + // task that the branch names. 275 + 276 + $maniphest = 'PhabricatorApplicationManiphest'; 277 + if (PhabricatorApplication::isClassInstalled($maniphest)) { 278 + $diff = $this->loadDiff($xaction->getNewValue()); 279 + if ($diff) { 280 + $branch = $diff->getBranch(); 281 + 282 + // No "$", to allow for branches like T123_demo. 283 + $match = null; 284 + if (preg_match('/^T(\d+)/i', $branch, $match)) { 285 + $task_id = $match[1]; 286 + $tasks = id(new ManiphestTaskQuery()) 287 + ->setViewer($this->getActor()) 288 + ->withIDs(array($task_id)) 289 + ->execute(); 290 + if ($tasks) { 291 + $task = head($tasks); 292 + $task_phid = $task->getPHID(); 293 + 294 + $results[] = id(new DifferentialTransaction()) 295 + ->setTransactionType($type_edge) 296 + ->setMetadataValue('edge:type', $edge_ref_task) 297 + ->setIgnoreOnNoEffect(true) 298 + ->setNewValue(array('+' => array($task_phid => $task_phid))); 299 + } 300 + } 301 + } 268 302 } 269 303 break; 270 304 ··· 905 939 switch ($strongest->getTransactionType()) { 906 940 case DifferentialTransaction::TYPE_UPDATE: 907 941 $count = new PhutilNumber($object->getLineCount()); 908 - $action = pht('%s, %s line(s)', $action, $count); 942 + $action = pht('%s, %d line(s)', $action, $count); 909 943 break; 910 944 } 911 945
-26
src/applications/differential/field/specification/DifferentialBranchFieldSpecification.php
··· 43 43 return null; 44 44 } 45 45 46 - public function didWriteRevision(DifferentialRevisionEditor $editor) { 47 - $maniphest = 'PhabricatorApplicationManiphest'; 48 - if (!PhabricatorApplication::isClassInstalled($maniphest)) { 49 - return; 50 - } 51 - 52 - $branch = $this->getDiff()->getBranch(); 53 - $match = null; 54 - if (preg_match('/^T(\d+)/i', $branch, $match)) { // No $ to allow T123_demo. 55 - list(, $task_id) = $match; 56 - $task = id(new ManiphestTaskQuery()) 57 - ->setViewer($editor->requireActor()) 58 - ->withIDs(array($task_id)) 59 - ->executeOne(); 60 - if ($task) { 61 - id(new PhabricatorEdgeEditor()) 62 - ->setActor($this->getUser()) 63 - ->addEdge( 64 - $this->getRevision()->getPHID(), 65 - PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK, 66 - $task->getPHID()) 67 - ->save(); 68 - } 69 - } 70 - } 71 - 72 46 public function getCommitMessageTips() { 73 47 return array( 74 48 'Name branch "T123" to attach the diff to a task.',
-4
src/applications/differential/field/specification/DifferentialCCsFieldSpecification.php
··· 60 60 ->setValue($cc_map); 61 61 } 62 62 63 - public function willWriteRevision(DifferentialRevisionEditor $editor) { 64 - $editor->setCCPHIDs($this->ccs); 65 - } 66 - 67 63 public function shouldAppearOnCommitMessage() { 68 64 return true; 69 65 }
-4
src/applications/differential/field/specification/DifferentialEditPolicyFieldSpecification.php
··· 35 35 ->setName('editPolicy'); 36 36 } 37 37 38 - public function willWriteRevision(DifferentialRevisionEditor $editor) { 39 - $this->getRevision()->setEditPolicy($this->value); 40 - } 41 - 42 38 }
-32
src/applications/differential/field/specification/DifferentialFieldSpecification.php
··· 192 192 return false; 193 193 } 194 194 195 - /** 196 - * Hook for applying revision changes via the editor. Normally, you should 197 - * not implement this, but a number of builtin fields use the revision object 198 - * itself as storage. If you need to do something similar for whatever reason, 199 - * this method gives you an opportunity to interact with the editor or 200 - * revision before changes are saved (for example, you can write the field's 201 - * value into some property of the revision). 202 - * 203 - * @param DifferentialRevisionEditor Active editor which is applying changes 204 - * to the revision. 205 - * @return void 206 - * @task edit 207 - */ 208 - public function willWriteRevision(DifferentialRevisionEditor $editor) { 209 - return; 210 - } 211 - 212 - /** 213 - * Hook after an edit operation has completed. This allows you to update 214 - * link tables or do other write operations which should happen after the 215 - * revision is saved. Normally you don't need to implement this. 216 - * 217 - * 218 - * @param DifferentialRevisionEditor Active editor which has just applied 219 - * changes to the revision. 220 - * @return void 221 - * @task edit 222 - */ 223 - public function didWriteRevision(DifferentialRevisionEditor $editor) { 224 - return; 225 - } 226 - 227 195 228 196 /* -( Extending the Revision View Interface )------------------------------ */ 229 197
-28
src/applications/differential/field/specification/DifferentialFreeformFieldSpecification.php
··· 63 63 return $result; 64 64 } 65 65 66 - public function didWriteRevision(DifferentialRevisionEditor $editor) { 67 - $message = $this->renderValueForCommitMessage(false); 68 - 69 - $tasks = $this->findMentionedTasks($message); 70 - if ($tasks) { 71 - $tasks = id(new ManiphestTaskQuery()) 72 - ->setViewer($editor->getActor()) 73 - ->withIDs(array_keys($tasks)) 74 - ->execute(); 75 - $this->saveFieldEdges( 76 - $editor->getRevision(), 77 - PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK, 78 - mpull($tasks, 'getPHID')); 79 - } 80 - 81 - $dependents = $this->findDependentRevisions($message); 82 - if ($dependents) { 83 - $dependents = id(new DifferentialRevisionQuery()) 84 - ->setViewer($editor->getActor()) 85 - ->withIDs($dependents) 86 - ->execute(); 87 - $this->saveFieldEdges( 88 - $editor->getRevision(), 89 - PhabricatorEdgeConfig::TYPE_DREV_DEPENDS_ON_DREV, 90 - mpull($dependents, 'getPHID')); 91 - } 92 - } 93 - 94 66 private function saveFieldEdges( 95 67 DifferentialRevision $revision, 96 68 $edge_type,
-25
src/applications/differential/field/specification/DifferentialJIRAIssuesFieldSpecification.php
··· 167 167 return $xobjs; 168 168 } 169 169 170 - public function didWriteRevision(DifferentialRevisionEditor $editor) { 171 - $revision = $editor->getRevision(); 172 - $revision_phid = $revision->getPHID(); 173 - 174 - $edge_type = PhabricatorEdgeConfig::TYPE_PHOB_HAS_JIRAISSUE; 175 - $edge_dsts = mpull($this->loadDoorkeeperExternalObjects(), 'getPHID'); 176 - 177 - $edges = PhabricatorEdgeQuery::loadDestinationPHIDs( 178 - $revision_phid, 179 - $edge_type); 180 - 181 - $editor = id(new PhabricatorEdgeEditor()) 182 - ->setActor($this->getUser()); 183 - 184 - foreach (array_diff($edges, $edge_dsts) as $rem_edge) { 185 - $editor->removeEdge($revision_phid, $edge_type, $rem_edge); 186 - } 187 - 188 - foreach (array_diff($edge_dsts, $edges) as $add_edge) { 189 - $editor->addEdge($revision_phid, $edge_type, $add_edge); 190 - } 191 - 192 - $editor->save(); 193 - } 194 - 195 170 }
-28
src/applications/differential/field/specification/DifferentialManiphestTasksFieldSpecification.php
··· 43 43 PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK); 44 44 } 45 45 46 - /** 47 - * Attach the revision to the task(s) and the task(s) to the revision. 48 - * 49 - * @return void 50 - */ 51 - public function didWriteRevision(DifferentialRevisionEditor $editor) { 52 - $revision = $editor->getRevision(); 53 - $revision_phid = $revision->getPHID(); 54 - $edge_type = PhabricatorEdgeConfig::TYPE_DREV_HAS_RELATED_TASK; 55 - 56 - $old_phids = $this->oldManiphestTasks; 57 - $add_phids = $this->maniphestTasks; 58 - $rem_phids = array_diff($old_phids, $add_phids); 59 - 60 - $edge_editor = id(new PhabricatorEdgeEditor()) 61 - ->setActor($this->getUser()); 62 - 63 - foreach ($add_phids as $phid) { 64 - $edge_editor->addEdge($revision_phid, $edge_type, $phid); 65 - } 66 - 67 - foreach ($rem_phids as $phid) { 68 - $edge_editor->removeEdge($revision_phid, $edge_type, $phid); 69 - } 70 - 71 - $edge_editor->save(); 72 - } 73 - 74 46 protected function didSetRevision() { 75 47 $this->maniphestTasks = $this->getManiphestTaskPHIDs(); 76 48 $this->oldManiphestTasks = $this->maniphestTasks;
-4
src/applications/differential/field/specification/DifferentialRepositoryFieldSpecification.php
··· 41 41 ->setValue($value); 42 42 } 43 43 44 - public function willWriteRevision(DifferentialRevisionEditor $editor) { 45 - $this->getRevision()->setRepositoryPHID($this->value); 46 - } 47 - 48 44 }
-4
src/applications/differential/field/specification/DifferentialReviewersFieldSpecification.php
··· 100 100 ->setError($this->error); 101 101 } 102 102 103 - public function willWriteRevision(DifferentialRevisionEditor $editor) { 104 - $editor->setReviewers($this->reviewers); 105 - } 106 - 107 103 public function shouldAppearOnCommitMessage() { 108 104 return true; 109 105 }
-4
src/applications/differential/field/specification/DifferentialSummaryFieldSpecification.php
··· 38 38 return true; 39 39 } 40 40 41 - public function willWriteRevision(DifferentialRevisionEditor $editor) { 42 - $this->getRevision()->setSummary($this->summary); 43 - } 44 - 45 41 public function shouldAppearOnCommitMessage() { 46 42 return true; 47 43 }
-4
src/applications/differential/field/specification/DifferentialTestPlanFieldSpecification.php
··· 42 42 return true; 43 43 } 44 44 45 - public function willWriteRevision(DifferentialRevisionEditor $editor) { 46 - $this->getRevision()->setTestPlan($this->plan); 47 - } 48 - 49 45 public function validateField() { 50 46 if ($this->isRequired()) { 51 47 if (!strlen($this->plan)) {
-4
src/applications/differential/field/specification/DifferentialTitleFieldSpecification.php
··· 33 33 return true; 34 34 } 35 35 36 - public function willWriteRevision(DifferentialRevisionEditor $editor) { 37 - $this->getRevision()->setTitle($this->title); 38 - } 39 - 40 36 public function validateField() { 41 37 if (!strlen($this->title)) { 42 38 $this->error = 'Required';
-4
src/applications/differential/field/specification/DifferentialViewPolicyFieldSpecification.php
··· 35 35 ->setName('viewPolicy'); 36 36 } 37 37 38 - public function willWriteRevision(DifferentialRevisionEditor $editor) { 39 - $this->getRevision()->setViewPolicy($this->value); 40 - } 41 - 42 38 }