@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<?php
2
3final class PhabricatorProjectTriggerRulesetTransaction
4 extends PhabricatorProjectTriggerTransactionType {
5
6 const TRANSACTIONTYPE = 'ruleset';
7
8 public function generateOldValue($object) {
9 return $object->getRuleset();
10 }
11
12 public function applyInternalEffects($object, $value) {
13 $object->setRuleset($value);
14 }
15
16 public function getTitle() {
17 return pht(
18 '%s updated the ruleset for this trigger.',
19 $this->renderAuthor());
20 }
21
22 public function validateTransactions($object, array $xactions) {
23 $actor = $this->getActor();
24 $errors = array();
25
26 foreach ($xactions as $xaction) {
27 $ruleset = $xaction->getNewValue();
28
29 try {
30 $rules =
31 PhabricatorProjectTrigger::newTriggerRulesFromRuleSpecifications(
32 $ruleset,
33 $allow_invalid = false,
34 $actor);
35 } catch (PhabricatorProjectTriggerCorruptionException $ex) {
36 $errors[] = $this->newInvalidError(
37 pht(
38 'Ruleset specification is not valid. %s',
39 $ex->getMessage()),
40 $xaction);
41 continue;
42 }
43
44 foreach ($rules as $rule) {
45 $exception = $rule->getRuleRecordValueValidationException();
46 if ($exception) {
47 $errors[] = $this->newInvalidError(
48 pht(
49 'Value for "%s" rule is invalid: %s',
50 $rule->getSelectControlName(),
51 $exception->getMessage()),
52 $xaction);
53 continue;
54 }
55 }
56 }
57
58 return $errors;
59 }
60
61 public function hasChangeDetailView() {
62 return true;
63 }
64
65 public function newChangeDetailView() {
66 $viewer = $this->getViewer();
67
68 $old = $this->getOldValue();
69 $new = $this->getNewValue();
70
71 $json = new PhutilJSON();
72 $old_json = $json->encodeAsList($old);
73 $new_json = $json->encodeAsList($new);
74
75 return id(new PhabricatorApplicationTransactionTextDiffDetailView())
76 ->setViewer($viewer)
77 ->setOldText($old_json)
78 ->setNewText($new_json);
79 }
80
81}