1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-10 00:42: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',
'HeraldConditionConfig' => 'applications/herald/config/HeraldConditionConfig.php',
'HeraldConditionTranscript' => 'applications/herald/storage/transcript/HeraldConditionTranscript.php',
'HeraldContentTypeConfig' => 'applications/herald/config/HeraldContentTypeConfig.php',
'HeraldController' => 'applications/herald/controller/HeraldController.php',
'HeraldDAO' => 'applications/herald/storage/HeraldDAO.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) {
$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(
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
final class HeraldRepetitionPolicyConfig {
const FIRST = 'first'; // only execute the first time (no repeating)
const EVERY = 'every'; // repeat every time
@ -9,31 +10,11 @@ final class HeraldRepetitionPolicyConfig {
self::EVERY => 1,
);
private static $policyMap = array(
self::FIRST => 'only the first time',
self::EVERY => 'every time',
);
public static function getMap() {
return self::$policyMap;
}
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}'.");
}
return array(
self::EVERY => pht('every time'),
self::FIRST => pht('only the first time'),
);
}
public static function toInt($str) {
@ -43,4 +24,5 @@ final class HeraldRepetitionPolicyConfig {
public static function toString($int) {
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);
$repetition_selector = $this->renderRepetitionSelector($rule);
$repetition_selector = $this->renderRepetitionSelector($rule, $adapter);
$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
* time) this rule matches..." element.
*/
private function renderRepetitionSelector($rule) {
// Make the selector for choosing how often this rule should be repeated
private function renderRepetitionSelector($rule, HeraldAdapter $adapter) {
$repetition_policy = HeraldRepetitionPolicyConfig::toString(
$rule->getRepetitionPolicy());
$repetition_options = HeraldRepetitionPolicyConfig::getMapForContentType(
$rule->getContentType());
if (empty($repetition_options)) {
// default option is 'every time'
$repetition_selector = idx(
HeraldRepetitionPolicyConfig::getMap(),
HeraldRepetitionPolicyConfig::EVERY);
return $repetition_selector;
} 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;
$repetition_options = $adapter->getRepetitionOptions();
$repetition_names = HeraldRepetitionPolicyConfig::getMap();
$repetition_map = array_select_keys($repetition_names, $repetition_options);
if (count($repetition_map) < 2) {
return head($repetition_names);
} else {
return AphrontFormSelectControl::renderSelectTag(
$repetition_policy,
$repetition_options,
$repetition_map,
array(
'name' => 'repetition_policy',
));