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

at recaptime-dev/main 165 lines 4.5 kB view raw
1<?php 2 3final class PhabricatorConfigEditor 4 extends PhabricatorApplicationTransactionEditor { 5 6 public function getEditorApplicationClass() { 7 return PhabricatorConfigApplication::class; 8 } 9 10 public function getEditorObjectsDescription() { 11 return pht('Configuration'); 12 } 13 14 public function getTransactionTypes() { 15 $types = parent::getTransactionTypes(); 16 17 $types[] = PhabricatorConfigTransaction::TYPE_EDIT; 18 19 return $types; 20 } 21 22 protected function getCustomTransactionOldValue( 23 PhabricatorLiskDAO $object, 24 PhabricatorApplicationTransaction $xaction) { 25 26 switch ($xaction->getTransactionType()) { 27 case PhabricatorConfigTransaction::TYPE_EDIT: 28 return array( 29 'deleted' => (int)$object->getIsDeleted(), 30 'value' => $object->getValue(), 31 ); 32 } 33 } 34 35 protected function getCustomTransactionNewValue( 36 PhabricatorLiskDAO $object, 37 PhabricatorApplicationTransaction $xaction) { 38 39 switch ($xaction->getTransactionType()) { 40 case PhabricatorConfigTransaction::TYPE_EDIT: 41 return $xaction->getNewValue(); 42 } 43 } 44 45 protected function applyCustomInternalTransaction( 46 PhabricatorLiskDAO $object, 47 PhabricatorApplicationTransaction $xaction) { 48 49 switch ($xaction->getTransactionType()) { 50 case PhabricatorConfigTransaction::TYPE_EDIT: 51 $v = $xaction->getNewValue(); 52 53 // If this is a defined configuration option (vs a straggler from an 54 // old version of Phabricator or a configuration file misspelling) 55 // submit it to the validation gauntlet. 56 $key = $object->getConfigKey(); 57 $all_options = PhabricatorApplicationConfigOptions::loadAllOptions(); 58 $option = idx($all_options, $key); 59 if ($option) { 60 $option->getGroup()->validateOption( 61 $option, 62 $v['value']); 63 } 64 65 $object->setIsDeleted((int)$v['deleted']); 66 $object->setValue($v['value']); 67 break; 68 } 69 } 70 71 protected function applyCustomExternalTransaction( 72 PhabricatorLiskDAO $object, 73 PhabricatorApplicationTransaction $xaction) { 74 return; 75 } 76 77 protected function mergeTransactions( 78 PhabricatorApplicationTransaction $u, 79 PhabricatorApplicationTransaction $v) { 80 81 $type = $u->getTransactionType(); 82 switch ($type) { 83 case PhabricatorConfigTransaction::TYPE_EDIT: 84 return $v; 85 } 86 87 return parent::mergeTransactions($u, $v); 88 } 89 90 protected function transactionHasEffect( 91 PhabricatorLiskDAO $object, 92 PhabricatorApplicationTransaction $xaction) { 93 94 $old = $xaction->getOldValue(); 95 $new = $xaction->getNewValue(); 96 97 $type = $xaction->getTransactionType(); 98 switch ($type) { 99 case PhabricatorConfigTransaction::TYPE_EDIT: 100 // If an edit deletes an already-deleted entry, no-op it. 101 if (idx($old, 'deleted') && idx($new, 'deleted')) { 102 return false; 103 } 104 break; 105 } 106 107 return parent::transactionHasEffect($object, $xaction); 108 } 109 110 protected function didApplyTransactions($object, array $xactions) { 111 // Force all the setup checks to run on the next page load. 112 PhabricatorSetupCheck::deleteSetupCheckCache(); 113 114 return $xactions; 115 } 116 117 public static function storeNewValue( 118 PhabricatorUser $user, 119 PhabricatorConfigEntry $config_entry, 120 $value, 121 PhabricatorContentSource $source, 122 $acting_as_phid = null) { 123 124 $xaction = id(new PhabricatorConfigTransaction()) 125 ->setTransactionType(PhabricatorConfigTransaction::TYPE_EDIT) 126 ->setNewValue( 127 array( 128 'deleted' => false, 129 'value' => $value, 130 )); 131 132 $editor = id(new PhabricatorConfigEditor()) 133 ->setActor($user) 134 ->setContinueOnNoEffect(true) 135 ->setContentSource($source); 136 137 if ($acting_as_phid) { 138 $editor->setActingAsPHID($acting_as_phid); 139 } 140 141 $editor->applyTransactions($config_entry, array($xaction)); 142 } 143 144 public static function deleteConfig( 145 PhabricatorUser $user, 146 PhabricatorConfigEntry $config_entry, 147 PhabricatorContentSource $source) { 148 149 $xaction = id(new PhabricatorConfigTransaction()) 150 ->setTransactionType(PhabricatorConfigTransaction::TYPE_EDIT) 151 ->setNewValue( 152 array( 153 'deleted' => true, 154 'value' => null, 155 )); 156 157 $editor = id(new PhabricatorConfigEditor()) 158 ->setActor($user) 159 ->setContinueOnNoEffect(true) 160 ->setContentSource($source); 161 162 $editor->applyTransactions($config_entry, array($xaction)); 163 } 164 165}