1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-27 09:12:41 +01:00

Remove HeraldContentTypeConfig and move repetition to Adapters

Summary: Ref T2769. Get rid of the last use of `HeraldContentTypeConfig` by moving repetition options into Adapters.

Test Plan: Viewed / edited Herald rules.

Reviewers: btrahan

Reviewed By: btrahan

CC: aran

Maniphest Tasks: T2769

Differential Revision: https://secure.phabricator.com/D6664
This commit is contained in:
epriestley 2013-08-02 12:35:33 -07:00
parent 0640931d30
commit ca66eeb07c
6 changed files with 31 additions and 49 deletions

View file

@ -602,7 +602,6 @@ phutil_register_library_map(array(
'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php', 'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php',
'HeraldConditionConfig' => 'applications/herald/config/HeraldConditionConfig.php', 'HeraldConditionConfig' => 'applications/herald/config/HeraldConditionConfig.php',
'HeraldConditionTranscript' => 'applications/herald/storage/transcript/HeraldConditionTranscript.php', 'HeraldConditionTranscript' => 'applications/herald/storage/transcript/HeraldConditionTranscript.php',
'HeraldContentTypeConfig' => 'applications/herald/config/HeraldContentTypeConfig.php',
'HeraldController' => 'applications/herald/controller/HeraldController.php', 'HeraldController' => 'applications/herald/controller/HeraldController.php',
'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php', 'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php',
'HeraldDeleteController' => 'applications/herald/controller/HeraldDeleteController.php', 'HeraldDeleteController' => 'applications/herald/controller/HeraldDeleteController.php',

View file

@ -292,6 +292,16 @@ abstract class HeraldAdapter {
} }
/* -( Repetition )--------------------------------------------------------- */
public function getRepetitionOptions() {
return array(
HeraldRepetitionPolicyConfig::EVERY,
);
}
public static function applyFlagEffect(HeraldEffect $effect, $phid) { public static function applyFlagEffect(HeraldEffect $effect, $phid) {
$color = $effect->getTarget(); $color = $effect->getTarget();

View file

@ -46,6 +46,12 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter {
); );
} }
public function getRepetitionOptions() {
return array(
HeraldRepetitionPolicyConfig::EVERY,
HeraldRepetitionPolicyConfig::FIRST,
);
}
public static function newLegacyAdapter( public static function newLegacyAdapter(
DifferentialRevision $revision, DifferentialRevision $revision,

View file

@ -1,8 +0,0 @@
<?php
final class HeraldContentTypeConfig {
const CONTENT_TYPE_DIFFERENTIAL = 'differential';
const CONTENT_TYPE_COMMIT = 'commit';
}

View file

@ -1,6 +1,7 @@
<?php <?php
final class HeraldRepetitionPolicyConfig { final class HeraldRepetitionPolicyConfig {
const FIRST = 'first'; // only execute the first time (no repeating) const FIRST = 'first'; // only execute the first time (no repeating)
const EVERY = 'every'; // repeat every time const EVERY = 'every'; // repeat every time
@ -9,31 +10,11 @@ final class HeraldRepetitionPolicyConfig {
self::EVERY => 1, self::EVERY => 1,
); );
private static $policyMap = array(
self::FIRST => 'only the first time',
self::EVERY => 'every time',
);
public static function getMap() { public static function getMap() {
return self::$policyMap; return array(
} self::EVERY => pht('every time'),
self::FIRST => pht('only the first time'),
public static function getMapForContentType($type) { );
switch ($type) {
case HeraldContentTypeConfig::CONTENT_TYPE_DIFFERENTIAL:
return array_select_keys(
self::$policyMap,
array(
self::EVERY,
self::FIRST,
));
case HeraldContentTypeConfig::CONTENT_TYPE_COMMIT:
return array();
default:
throw new Exception("Unknown content type '{$type}'.");
}
} }
public static function toInt($str) { public static function toInt($str) {
@ -43,4 +24,5 @@ final class HeraldRepetitionPolicyConfig {
public static function toString($int) { public static function toString($int) {
return idx(array_flip(self::$policyIntMap), $int, self::EVERY); return idx(array_flip(self::$policyIntMap), $int, self::EVERY);
} }
} }

View file

@ -86,7 +86,7 @@ final class HeraldRuleController extends HeraldController {
} }
$must_match_selector = $this->renderMustMatchSelector($rule); $must_match_selector = $this->renderMustMatchSelector($rule);
$repetition_selector = $this->renderRepetitionSelector($rule); $repetition_selector = $this->renderRepetitionSelector($rule, $adapter);
$handles = $this->loadHandlesForRule($rule); $handles = $this->loadHandlesForRule($rule);
@ -492,27 +492,20 @@ final class HeraldRuleController extends HeraldController {
* Render the selector for "Take these actions (every time | only the first * Render the selector for "Take these actions (every time | only the first
* time) this rule matches..." element. * time) this rule matches..." element.
*/ */
private function renderRepetitionSelector($rule) { private function renderRepetitionSelector($rule, HeraldAdapter $adapter) {
// Make the selector for choosing how often this rule should be repeated
$repetition_policy = HeraldRepetitionPolicyConfig::toString( $repetition_policy = HeraldRepetitionPolicyConfig::toString(
$rule->getRepetitionPolicy()); $rule->getRepetitionPolicy());
$repetition_options = HeraldRepetitionPolicyConfig::getMapForContentType(
$rule->getContentType());
if (empty($repetition_options)) { $repetition_options = $adapter->getRepetitionOptions();
// default option is 'every time' $repetition_names = HeraldRepetitionPolicyConfig::getMap();
$repetition_selector = idx( $repetition_map = array_select_keys($repetition_names, $repetition_options);
HeraldRepetitionPolicyConfig::getMap(),
HeraldRepetitionPolicyConfig::EVERY); if (count($repetition_map) < 2) {
return $repetition_selector; return head($repetition_names);
} else if (count($repetition_options) == 1) {
// if there's only 1 option, just pick it for the user
$repetition_selector = reset($repetition_options);
return $repetition_selector;
} else { } else {
return AphrontFormSelectControl::renderSelectTag( return AphrontFormSelectControl::renderSelectTag(
$repetition_policy, $repetition_policy,
$repetition_options, $repetition_map,
array( array(
'name' => 'repetition_policy', 'name' => 'repetition_policy',
)); ));