@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
at upstream/main 85 lines 2.2 kB view raw
1<?php 2 3final class DifferentialDiffEditor 4 extends PhabricatorApplicationTransactionEditor { 5 6 private $lookupRepository = true; 7 8 public function setLookupRepository($bool) { 9 $this->lookupRepository = $bool; 10 return $this; 11 } 12 13 public function getEditorApplicationClass() { 14 return PhabricatorDifferentialApplication::class; 15 } 16 17 public function getEditorObjectsDescription() { 18 return pht('Differential Diffs'); 19 } 20 21 public function getTransactionTypes() { 22 $types = parent::getTransactionTypes(); 23 24 $types[] = PhabricatorTransactions::TYPE_VIEW_POLICY; 25 $types[] = DifferentialDiffTransaction::TYPE_DIFF_CREATE; 26 27 return $types; 28 } 29 30 protected function didApplyInternalEffects( 31 PhabricatorLiskDAO $object, 32 array $xactions) { 33 34 // This method wasn't modularized. 35 36 foreach ($xactions as $xaction) { 37 switch ($xaction->getTransactionType()) { 38 case DifferentialDiffTransaction::TYPE_DIFF_CREATE: 39 $xaction->setNewValue(true); 40 break; 41 } 42 } 43 44 return $xactions; 45 } 46 47 48 protected function applyFinalEffects( 49 PhabricatorLiskDAO $object, 50 array $xactions) { 51 52 // If we didn't get an explicit `repositoryPHID` (which means the client 53 // is old, or couldn't figure out which repository the working copy 54 // belongs to), apply heuristics to try to figure it out. 55 56 if ($this->lookupRepository && !$object->getRepositoryPHID()) { 57 $repository = id(new DifferentialRepositoryLookup()) 58 ->setDiff($object) 59 ->setViewer($this->getActor()) 60 ->lookupRepository(); 61 if ($repository) { 62 $object->setRepositoryPHID($repository->getPHID()); 63 $object->setRepositoryUUID($repository->getUUID()); 64 $object->save(); 65 } 66 } 67 68 return $xactions; 69 } 70 71/* -( Herald Integration )------------------------------------------------- */ 72 73 /** 74 * See @{method:validateTransaction}. The only Herald action is to block 75 * the creation of Diffs. We thus have to be careful not to save any 76 * data and do this validation very early. 77 */ 78 protected function shouldApplyHeraldRules( 79 PhabricatorLiskDAO $object, 80 array $xactions) { 81 82 return false; 83 } 84 85}