@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
at upstream/main 172 lines 4.2 kB view raw
1<?php 2 3abstract class PhabricatorProjectTriggerRule 4 extends Phobject { 5 6 private $record; 7 private $viewer; 8 private $column; 9 private $trigger; 10 private $object; 11 12 final public function getTriggerType() { 13 return $this->getPhobjectClassConstant('TRIGGERTYPE', 64); 14 } 15 16 final public static function getAllTriggerRules() { 17 return id(new PhutilClassMapQuery()) 18 ->setAncestorClass(self::class) 19 ->setUniqueMethod('getTriggerType') 20 ->execute(); 21 } 22 23 final public function setRecord(PhabricatorProjectTriggerRuleRecord $record) { 24 $value = $record->getValue(); 25 26 $this->assertValidRuleRecordFormat($value); 27 28 $this->record = $record; 29 return $this; 30 } 31 32 final public function getRecord() { 33 return $this->record; 34 } 35 36 final protected function getValue() { 37 return $this->getRecord()->getValue(); 38 } 39 40 protected function getValueForEditorField() { 41 return $this->getValue(); 42 } 43 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); 49 50 final public function getRuleRecordValueValidationException() { 51 try { 52 $this->assertValidRuleRecordValue($this->getRecord()->getValue()); 53 } catch (Exception $ex) { 54 return $ex; 55 } 56 57 return null; 58 } 59 60 protected function assertValidRuleRecordValue($value) { 61 return; 62 } 63 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(); 69 70 protected function isSelectableRule() { 71 return true; 72 } 73 74 protected function isValidRule() { 75 return true; 76 } 77 78 protected function newInvalidView() { 79 return null; 80 } 81 82 public function getSoundEffects() { 83 return array(); 84 } 85 86 final public function getDropTransactions($object, $value) { 87 return $this->newDropTransactions($object, $value); 88 } 89 90 final public function setViewer(PhabricatorUser $viewer) { 91 $this->viewer = $viewer; 92 return $this; 93 } 94 95 final public function getViewer() { 96 return $this->viewer; 97 } 98 99 final public function setColumn(PhabricatorProjectColumn $column) { 100 $this->column = $column; 101 return $this; 102 } 103 104 final public function getColumn() { 105 return $this->column; 106 } 107 108 final public function setTrigger(PhabricatorProjectTrigger $trigger) { 109 $this->trigger = $trigger; 110 return $this; 111 } 112 113 final public function getTrigger() { 114 return $this->trigger; 115 } 116 117 final public function setObject( 118 PhabricatorApplicationTransactionInterface $object) { 119 $this->object = $object; 120 return $this; 121 } 122 123 final public function getObject() { 124 return $this->object; 125 } 126 127 final protected function newTransaction() { 128 return $this->getObject()->getApplicationTransactionTemplate(); 129 } 130 131 final public function getDropEffects() { 132 return $this->newDropEffects($this->getValue()); 133 } 134 135 final protected function newEffect() { 136 return id(new PhabricatorProjectDropEffect()) 137 ->setIsTriggerEffect(true); 138 } 139 140 final public function toDictionary() { 141 $record = $this->getRecord(); 142 143 $is_valid = $this->isValidRule(); 144 if (!$is_valid) { 145 $invalid_view = hsprintf('%s', $this->newInvalidView()); 146 } else { 147 $invalid_view = null; 148 } 149 150 return array( 151 'type' => $record->getType(), 152 'value' => $this->getValueForEditorField(), 153 'isValidRule' => $is_valid, 154 'invalidView' => $invalid_view, 155 ); 156 } 157 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(), 167 ), 168 ); 169 } 170 171 172}