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

Add "bin/herald rule ..." to modify Herald rules from the CLI

Summary:
Depends on D20566. Ref T13298. See PHI1280. Currently, there's no clean way to disable problematic personal rules. This comes up occasionally and sometimes isn't really the best approach to solving a problem, but is a generally reasonable capability to provide.

Allow Herald rules (including personal rules) to be disabled/enabled via `bin/herald rule ... --disable/--enable`.

Test Plan: Used the CLI to disable and enable a personal rule.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: jmeador

Maniphest Tasks: T13298

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

+108
+2
src/__phutil_library_map__.php
··· 1560 1560 'HeraldRuleIndexEngineExtension' => 'applications/herald/engineextension/HeraldRuleIndexEngineExtension.php', 1561 1561 'HeraldRuleListController' => 'applications/herald/controller/HeraldRuleListController.php', 1562 1562 'HeraldRuleListView' => 'applications/herald/view/HeraldRuleListView.php', 1563 + 'HeraldRuleManagementWorkflow' => 'applications/herald/management/HeraldRuleManagementWorkflow.php', 1563 1564 'HeraldRuleNameTransaction' => 'applications/herald/xaction/HeraldRuleNameTransaction.php', 1564 1565 'HeraldRulePHIDType' => 'applications/herald/phid/HeraldRulePHIDType.php', 1565 1566 'HeraldRuleQuery' => 'applications/herald/query/HeraldRuleQuery.php', ··· 7381 7382 'HeraldRuleIndexEngineExtension' => 'PhabricatorEdgeIndexEngineExtension', 7382 7383 'HeraldRuleListController' => 'HeraldController', 7383 7384 'HeraldRuleListView' => 'AphrontView', 7385 + 'HeraldRuleManagementWorkflow' => 'HeraldManagementWorkflow', 7384 7386 'HeraldRuleNameTransaction' => 'HeraldRuleTransactionType', 7385 7387 'HeraldRulePHIDType' => 'PhabricatorPHIDType', 7386 7388 'HeraldRuleQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
+106
src/applications/herald/management/HeraldRuleManagementWorkflow.php
··· 1 + <?php 2 + 3 + final 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 (!strlen($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 + }