Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / project / trigger / PhabricatorProjectTriggerRule.php
blob58c7cd1f1a9b427b794f863ef6c69e8fcc512dc7
1 <?php
3 abstract class PhabricatorProjectTriggerRule
4 extends Phobject {
6 private $record;
7 private $viewer;
8 private $column;
9 private $trigger;
10 private $object;
12 final public function getTriggerType() {
13 return $this->getPhobjectClassConstant('TRIGGERTYPE', 64);
16 final public static function getAllTriggerRules() {
17 return id(new PhutilClassMapQuery())
18 ->setAncestorClass(__CLASS__)
19 ->setUniqueMethod('getTriggerType')
20 ->execute();
23 final public function setRecord(PhabricatorProjectTriggerRuleRecord $record) {
24 $value = $record->getValue();
26 $this->assertValidRuleRecordFormat($value);
28 $this->record = $record;
29 return $this;
32 final public function getRecord() {
33 return $this->record;
36 final protected function getValue() {
37 return $this->getRecord()->getValue();
40 protected function getValueForEditorField() {
41 return $this->getValue();
44 abstract public function getSelectControlName();
45 abstract public function getRuleViewLabel();
46 abstract public function getRuleViewDescription($value);
47 abstract public function getRuleViewIcon($value);
48 abstract protected function assertValidRuleRecordFormat($value);
50 final public function getRuleRecordValueValidationException() {
51 try {
52 $this->assertValidRuleRecordValue($this->getRecord()->getValue());
53 } catch (Exception $ex) {
54 return $ex;
57 return null;
60 protected function assertValidRuleRecordValue($value) {
61 return;
64 abstract protected function newDropTransactions($object, $value);
65 abstract protected function newDropEffects($value);
66 abstract protected function getDefaultValue();
67 abstract protected function getPHUIXControlType();
68 abstract protected function getPHUIXControlSpecification();
70 protected function isSelectableRule() {
71 return true;
74 protected function isValidRule() {
75 return true;
78 protected function newInvalidView() {
79 return null;
82 public function getSoundEffects() {
83 return array();
86 final public function getDropTransactions($object, $value) {
87 return $this->newDropTransactions($object, $value);
90 final public function setViewer(PhabricatorUser $viewer) {
91 $this->viewer = $viewer;
92 return $this;
95 final public function getViewer() {
96 return $this->viewer;
99 final public function setColumn(PhabricatorProjectColumn $column) {
100 $this->column = $column;
101 return $this;
104 final public function getColumn() {
105 return $this->column;
108 final public function setTrigger(PhabricatorProjectTrigger $trigger) {
109 $this->trigger = $trigger;
110 return $this;
113 final public function getTrigger() {
114 return $this->trigger;
117 final public function setObject(
118 PhabricatorApplicationTransactionInterface $object) {
119 $this->object = $object;
120 return $this;
123 final public function getObject() {
124 return $this->object;
127 final protected function newTransaction() {
128 return $this->getObject()->getApplicationTransactionTemplate();
131 final public function getDropEffects() {
132 return $this->newDropEffects($this->getValue());
135 final protected function newEffect() {
136 return id(new PhabricatorProjectDropEffect())
137 ->setIsTriggerEffect(true);
140 final public function toDictionary() {
141 $record = $this->getRecord();
143 $is_valid = $this->isValidRule();
144 if (!$is_valid) {
145 $invalid_view = hsprintf('%s', $this->newInvalidView());
146 } else {
147 $invalid_view = null;
150 return array(
151 'type' => $record->getType(),
152 'value' => $this->getValueForEditorField(),
153 'isValidRule' => $is_valid,
154 'invalidView' => $invalid_view,
158 final public function newTemplate() {
159 return array(
160 'type' => $this->getTriggerType(),
161 'name' => $this->getSelectControlName(),
162 'selectable' => $this->isSelectableRule(),
163 'defaultValue' => $this->getDefaultValue(),
164 'control' => array(
165 'type' => $this->getPHUIXControlType(),
166 'specification' => $this->getPHUIXControlSpecification(),