2013-10-06 17:10:29 -07:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class HeraldRuleEditor
|
|
|
|
extends PhabricatorApplicationTransactionEditor {
|
|
|
|
|
2014-08-12 12:28:41 -07:00
|
|
|
public function getEditorApplicationClass() {
|
|
|
|
return 'PhabricatorHeraldApplication';
|
|
|
|
}
|
|
|
|
|
|
|
|
public function getEditorObjectsDescription() {
|
|
|
|
return pht('Herald Rules');
|
|
|
|
}
|
|
|
|
|
2013-10-06 17:10:29 -07:00
|
|
|
public function getTransactionTypes() {
|
|
|
|
$types = parent::getTransactionTypes();
|
|
|
|
|
|
|
|
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
2016-03-28 23:02:41 +00:00
|
|
|
$types[] = HeraldRuleTransaction::TYPE_EDIT;
|
|
|
|
$types[] = HeraldRuleTransaction::TYPE_NAME;
|
2013-10-06 17:10:29 -07:00
|
|
|
$types[] = HeraldRuleTransaction::TYPE_DISABLE;
|
|
|
|
|
|
|
|
return $types;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomTransactionOldValue(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case HeraldRuleTransaction::TYPE_DISABLE:
|
|
|
|
return (int)$object->getIsDisabled();
|
2016-03-28 23:02:41 +00:00
|
|
|
case HeraldRuleTransaction::TYPE_EDIT:
|
|
|
|
return id(new HeraldRuleSerializer())
|
|
|
|
->serializeRule($object);
|
|
|
|
case HeraldRuleTransaction::TYPE_NAME:
|
|
|
|
return $object->getName();
|
2013-10-06 17:10:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function getCustomTransactionNewValue(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case HeraldRuleTransaction::TYPE_DISABLE:
|
|
|
|
return (int)$xaction->getNewValue();
|
2016-03-28 23:02:41 +00:00
|
|
|
case HeraldRuleTransaction::TYPE_EDIT:
|
|
|
|
case HeraldRuleTransaction::TYPE_NAME:
|
|
|
|
return $xaction->getNewValue();
|
2013-10-06 17:10:29 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function applyCustomInternalTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
|
|
|
|
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case HeraldRuleTransaction::TYPE_DISABLE:
|
|
|
|
return $object->setIsDisabled($xaction->getNewValue());
|
2016-03-28 23:02:41 +00:00
|
|
|
case HeraldRuleTransaction::TYPE_NAME:
|
|
|
|
return $object->setName($xaction->getNewValue());
|
|
|
|
case HeraldRuleTransaction::TYPE_EDIT:
|
|
|
|
$new_state = id(new HeraldRuleSerializer())
|
|
|
|
->deserializeRuleComponents($xaction->getNewValue());
|
|
|
|
$object->setMustMatchAll((int)$new_state['match_all']);
|
|
|
|
$object->attachConditions($new_state['conditions']);
|
|
|
|
$object->attachActions($new_state['actions']);
|
|
|
|
$object->setRepetitionPolicy(
|
|
|
|
HeraldRepetitionPolicyConfig::toInt($new_state['repetition_policy']));
|
|
|
|
return $object;
|
2013-10-06 17:10:29 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
protected function applyCustomExternalTransaction(
|
|
|
|
PhabricatorLiskDAO $object,
|
|
|
|
PhabricatorApplicationTransaction $xaction) {
|
2016-03-28 23:02:41 +00:00
|
|
|
switch ($xaction->getTransactionType()) {
|
|
|
|
case HeraldRuleTransaction::TYPE_EDIT:
|
|
|
|
$object->saveConditions($object->getConditions());
|
|
|
|
$object->saveActions($object->getActions());
|
|
|
|
break;
|
|
|
|
}
|
2013-10-06 17:10:29 -07:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|