@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 106 lines 2.8 kB view raw
1<?php 2 3final class HeraldRuleManagementWorkflow 4 extends HeraldManagementWorkflow { 5 6 protected function didConstruct() { 7 $this 8 ->setName('rule') 9 ->setExamples('**rule** --rule __rule__ --disable') 10 ->setSynopsis( 11 pht( 12 'Modify a rule, bypassing policies. This workflow can disable '. 13 'problematic personal rules.')) 14 ->setArguments( 15 array( 16 array( 17 'name' => 'rule', 18 'param' => 'rule', 19 'help' => pht('Apply changes to this rule.'), 20 ), 21 array( 22 'name' => 'disable', 23 'help' => pht('Disable the rule.'), 24 ), 25 array( 26 'name' => 'enable', 27 'help' => pht('Enable the rule.'), 28 ), 29 )); 30 } 31 32 public function execute(PhutilArgumentParser $args) { 33 $viewer = $this->getViewer(); 34 35 $rule_name = $args->getArg('rule'); 36 if (!phutil_nonempty_string($rule_name)) { 37 throw new PhutilArgumentUsageException( 38 pht('Specify a rule to edit with "--rule <id|monogram>".')); 39 } 40 41 if (preg_match('/^H\d+/', $rule_name)) { 42 $rule_id = substr($rule_name, 1); 43 } else { 44 $rule_id = $rule_name; 45 } 46 47 $rule = id(new HeraldRuleQuery()) 48 ->setViewer($viewer) 49 ->withIDs(array($rule_id)) 50 ->executeOne(); 51 if (!$rule) { 52 throw new PhutilArgumentUsageException( 53 pht( 54 'Unable to load Herald rule with ID or monogram "%s".', 55 $rule_name)); 56 } 57 58 $is_disable = $args->getArg('disable'); 59 $is_enable = $args->getArg('enable'); 60 61 $xactions = array(); 62 63 if ($is_disable && $is_enable) { 64 throw new PhutilArgumentUsageException( 65 pht( 66 'Specify "--enable" or "--disable", but not both.')); 67 } else if ($is_disable || $is_enable) { 68 $xactions[] = $rule->getApplicationTransactionTemplate() 69 ->setTransactionType(HeraldRuleDisableTransaction::TRANSACTIONTYPE) 70 ->setNewValue($is_disable); 71 } 72 73 if (!$xactions) { 74 throw new PhutilArgumentUsageException( 75 pht( 76 'Use flags to specify at least one edit to apply to the '. 77 'rule (for example, use "--disable" to disable a rule).')); 78 } 79 80 $herald_phid = id(new PhabricatorHeraldApplication())->getPHID(); 81 82 $editor = $rule->getApplicationTransactionEditor() 83 ->setActor($viewer) 84 ->setActingAsPHID($herald_phid) 85 ->setContentSource($this->newContentSource()) 86 ->setContinueOnMissingFields(true) 87 ->setContinueOnNoEffect(true); 88 89 echo tsprintf( 90 "%s\n", 91 pht( 92 'Applying changes to %s: %s...', 93 $rule->getMonogram(), 94 $rule->getName())); 95 96 $editor->applyTransactions($rule, $xactions); 97 98 echo tsprintf( 99 "%s\n", 100 pht('Done.')); 101 102 103 return 0; 104 } 105 106}