3 final class HeraldRuleManagementWorkflow
4 extends HeraldManagementWorkflow
{
6 protected function didConstruct() {
9 ->setExamples('**rule** --rule __rule__ --disable')
12 'Modify a rule, bypassing policies. This workflow can disable '.
13 'problematic personal rules.'))
19 'help' => pht('Apply changes to this rule.'),
23 'help' => pht('Disable the rule.'),
27 'help' => pht('Enable the rule.'),
32 public function execute(PhutilArgumentParser
$args) {
33 $viewer = $this->getViewer();
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>".'));
41 if (preg_match('/^H\d+/', $rule_name)) {
42 $rule_id = substr($rule_name, 1);
44 $rule_id = $rule_name;
47 $rule = id(new HeraldRuleQuery())
49 ->withIDs(array($rule_id))
52 throw new PhutilArgumentUsageException(
54 'Unable to load Herald rule with ID or monogram "%s".',
58 $is_disable = $args->getArg('disable');
59 $is_enable = $args->getArg('enable');
63 if ($is_disable && $is_enable) {
64 throw new PhutilArgumentUsageException(
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);
74 throw new PhutilArgumentUsageException(
76 'Use flags to specify at least one edit to apply to the '.
77 'rule (for example, use "--disable" to disable a rule).'));
80 $herald_phid = id(new PhabricatorHeraldApplication())->getPHID();
82 $editor = $rule->getApplicationTransactionEditor()
84 ->setActingAsPHID($herald_phid)
85 ->setContentSource($this->newContentSource())
86 ->setContinueOnMissingFields(true)
87 ->setContinueOnNoEffect(true);
92 'Applying changes to %s: %s...',
96 $editor->applyTransactions($rule, $xactions);