Page MenuHomePhabricator

D18926.diff
No OneTemporary

D18926.diff

diff --git a/src/__phutil_library_map__.php b/src/__phutil_library_map__.php
--- a/src/__phutil_library_map__.php
+++ b/src/__phutil_library_map__.php
@@ -1399,7 +1399,6 @@
'HeraldRelatedFieldGroup' => 'applications/herald/field/HeraldRelatedFieldGroup.php',
'HeraldRemarkupFieldValue' => 'applications/herald/value/HeraldRemarkupFieldValue.php',
'HeraldRemarkupRule' => 'applications/herald/remarkup/HeraldRemarkupRule.php',
- 'HeraldRepetitionPolicyConfig' => 'applications/herald/config/HeraldRepetitionPolicyConfig.php',
'HeraldRule' => 'applications/herald/storage/HeraldRule.php',
'HeraldRuleController' => 'applications/herald/controller/HeraldRuleController.php',
'HeraldRuleDatasource' => 'applications/herald/typeahead/HeraldRuleDatasource.php',
@@ -6602,7 +6601,6 @@
'HeraldRelatedFieldGroup' => 'HeraldFieldGroup',
'HeraldRemarkupFieldValue' => 'HeraldFieldValue',
'HeraldRemarkupRule' => 'PhabricatorObjectRemarkupRule',
- 'HeraldRepetitionPolicyConfig' => 'Phobject',
'HeraldRule' => array(
'HeraldDAO',
'PhabricatorApplicationTransactionInterface',
diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php
--- a/src/applications/herald/adapter/HeraldAdapter.php
+++ b/src/applications/herald/adapter/HeraldAdapter.php
@@ -766,14 +766,14 @@
public function getRepetitionOptions() {
$options = array();
- $options[] = HeraldRepetitionPolicyConfig::EVERY;
+ $options[] = HeraldRule::REPEAT_EVERY;
// Some rules, like pre-commit rules, only ever fire once. It doesn't
// make sense to use state-based repetition policies like "only the first
// time" for these rules.
if (!$this->isSingleEventAdapter()) {
- $options[] = HeraldRepetitionPolicyConfig::FIRST;
+ $options[] = HeraldRule::REPEAT_FIRST;
}
return $options;
@@ -897,10 +897,7 @@
));
}
- $integer_code_for_every = HeraldRepetitionPolicyConfig::toInt(
- HeraldRepetitionPolicyConfig::EVERY);
-
- if ($rule->getRepetitionPolicy() == $integer_code_for_every) {
+ if ($rule->isRepeatEvery()) {
$action_text =
pht('Take these actions every time this rule matches:');
} else {
diff --git a/src/applications/herald/config/HeraldRepetitionPolicyConfig.php b/src/applications/herald/config/HeraldRepetitionPolicyConfig.php
deleted file mode 100644
--- a/src/applications/herald/config/HeraldRepetitionPolicyConfig.php
+++ /dev/null
@@ -1,28 +0,0 @@
-<?php
-
-final class HeraldRepetitionPolicyConfig extends Phobject {
-
- const FIRST = 'first'; // only execute the first time (no repeating)
- const EVERY = 'every'; // repeat every time
-
- private static $policyIntMap = array(
- self::FIRST => 0,
- self::EVERY => 1,
- );
-
- public static function getMap() {
- return array(
- self::EVERY => pht('every time'),
- self::FIRST => pht('only the first time'),
- );
- }
-
- public static function toInt($str) {
- return idx(self::$policyIntMap, $str, self::$policyIntMap[self::EVERY]);
- }
-
- public static function toString($int) {
- return idx(array_flip(self::$policyIntMap), $int, self::EVERY);
- }
-
-}
diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php
--- a/src/applications/herald/controller/HeraldRuleController.php
+++ b/src/applications/herald/controller/HeraldRuleController.php
@@ -373,8 +373,7 @@
// mutate current rule, so it would be sent to the client in the right state
$rule->setMustMatchAll((int)$match_all);
$rule->setName($new_name);
- $rule->setRepetitionPolicy(
- HeraldRepetitionPolicyConfig::toInt($repetition_policy_param));
+ $rule->setRepetitionPolicyStringConstant($repetition_policy_param);
$rule->attachConditions($conditions);
$rule->attachActions($actions);
@@ -594,11 +593,10 @@
* time) this rule matches..." element.
*/
private function renderRepetitionSelector($rule, HeraldAdapter $adapter) {
- $repetition_policy = HeraldRepetitionPolicyConfig::toString(
- $rule->getRepetitionPolicy());
+ $repetition_policy = $rule->getRepetitionPolicyStringConstant();
$repetition_options = $adapter->getRepetitionOptions();
- $repetition_names = HeraldRepetitionPolicyConfig::getMap();
+ $repetition_names = HeraldRule::getRepetitionPolicySelectOptionMap();
$repetition_map = array_select_keys($repetition_names, $repetition_options);
if (count($repetition_map) < 2) {
diff --git a/src/applications/herald/editor/HeraldRuleEditor.php b/src/applications/herald/editor/HeraldRuleEditor.php
--- a/src/applications/herald/editor/HeraldRuleEditor.php
+++ b/src/applications/herald/editor/HeraldRuleEditor.php
@@ -66,8 +66,10 @@
$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']));
+
+ $new_repetition = $new_state['repetition_policy'];
+ $object->setRepetitionPolicyStringConstant($new_repetition);
+
return $object;
}
diff --git a/src/applications/herald/editor/HeraldRuleSerializer.php b/src/applications/herald/editor/HeraldRuleSerializer.php
--- a/src/applications/herald/editor/HeraldRuleSerializer.php
+++ b/src/applications/herald/editor/HeraldRuleSerializer.php
@@ -9,7 +9,7 @@
(bool)$rule->getMustMatchAll(),
$rule->getConditions(),
$rule->getActions(),
- HeraldRepetitionPolicyConfig::toString($rule->getRepetitionPolicy()));
+ $rule->getRepetitionPolicyStringConstant());
}
public function serializeRuleComponents(
diff --git a/src/applications/herald/engine/HeraldEngine.php b/src/applications/herald/engine/HeraldEngine.php
--- a/src/applications/herald/engine/HeraldEngine.php
+++ b/src/applications/herald/engine/HeraldEngine.php
@@ -68,9 +68,7 @@
foreach ($rules as $phid => $rule) {
$this->stack = array();
- $policy_first = HeraldRepetitionPolicyConfig::FIRST;
- $policy_first_int = HeraldRepetitionPolicyConfig::toInt($policy_first);
- $is_first_only = ($rule->getRepetitionPolicy() == $policy_first_int);
+ $is_first_only = $rule->isRepeatFirst();
try {
if (!$this->getDryRun() &&
@@ -175,8 +173,6 @@
$rules = mpull($rules, null, 'getID');
$applied_ids = array();
- $first_policy = HeraldRepetitionPolicyConfig::toInt(
- HeraldRepetitionPolicyConfig::FIRST);
// Mark all the rules that have had their effects applied as having been
// executed for the current object.
@@ -194,7 +190,7 @@
continue;
}
- if ($rule->getRepetitionPolicy() == $first_policy) {
+ if ($rule->isRepeatFirst()) {
$applied_ids[] = $rule_id;
}
}
diff --git a/src/applications/herald/storage/HeraldRule.php b/src/applications/herald/storage/HeraldRule.php
--- a/src/applications/herald/storage/HeraldRule.php
+++ b/src/applications/herald/storage/HeraldRule.php
@@ -30,6 +30,9 @@
private $actions;
private $triggerObject = self::ATTACHABLE;
+ const REPEAT_EVERY = 'every';
+ const REPEAT_FIRST = 'first';
+
protected function getConfiguration() {
return array(
self::CONFIG_AUX_PHID => true,
@@ -254,6 +257,74 @@
}
+/* -( Repetition Policies )------------------------------------------------ */
+
+
+ public function getRepetitionPolicyStringConstant() {
+ $map = self::getRepetitionPolicyMap();
+ $map = ipull($map, 'key.string', 'key.int');
+
+ return idx($map, $this->getRepetitionPolicyIntegerConstant());
+ }
+
+ public function getRepetitionPolicyIntegerConstant() {
+ $map = self::getRepetitionPolicyMap();
+ $map = ipull($map, 'key.int', 'key.int');
+ $int = $this->getRepetitionPolicy();
+
+ if (!isset($map[$int])) {
+ return head_key($map);
+ }
+
+ return $int;
+ }
+
+ public function setRepetitionPolicyStringConstant($value) {
+ $map = self::getRepetitionPolicyMap();
+ $map = ipull($map, 'key.int', 'key.string');
+
+ if (!isset($map[$value])) {
+ throw new Exception(
+ pht(
+ 'Rule repetition string constant "%s" is unknown.',
+ $value));
+ }
+
+ $int = $map[$value];
+
+ return $this->setRepetitionPolicy($int);
+ }
+
+ public function isRepeatEvery() {
+ return ($this->getRepetitionPolicyStringConstant() === self::REPEAT_EVERY);
+ }
+
+ public function isRepeatFirst() {
+ return ($this->getRepetitionPolicyStringConstant() === self::REPEAT_FIRST);
+ }
+
+ public static function getRepetitionPolicySelectOptionMap() {
+ $map = self::getRepetitionPolicyMap();
+ $map = ipull($map, 'select', 'key.string');
+ return $map;
+ }
+
+ private static function getRepetitionPolicyMap() {
+ return array(
+ self::REPEAT_EVERY => array(
+ 'key.int' => 1,
+ 'key.string' => self::REPEAT_EVERY,
+ 'select' => pht('every time'),
+ ),
+ self::REPEAT_FIRST => array(
+ 'key.int' => 0,
+ 'key.string' => self::REPEAT_FIRST,
+ 'select' => pht('only the first time'),
+ ),
+ );
+ }
+
+
/* -( PhabricatorApplicationTransactionInterface )------------------------- */

File Metadata

Mime Type
text/plain
Expires
Tue, Mar 18, 4:57 PM (2 d, 8 h ago)
Storage Engine
blob
Storage Format
Encrypted (AES-256-CBC)
Storage Handle
7367664
Default Alt Text
D18926.diff (9 KB)

Event Timeline