@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
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+31 -49
-1
src/__phutil_library_map__.php
··· 602 602 'HeraldCondition' => 'applications/herald/storage/HeraldCondition.php', 603 603 'HeraldConditionConfig' => 'applications/herald/config/HeraldConditionConfig.php', 604 604 'HeraldConditionTranscript' => 'applications/herald/storage/transcript/HeraldConditionTranscript.php', 605 - 'HeraldContentTypeConfig' => 'applications/herald/config/HeraldContentTypeConfig.php', 606 605 'HeraldController' => 'applications/herald/controller/HeraldController.php', 607 606 'HeraldDAO' => 'applications/herald/storage/HeraldDAO.php', 608 607 'HeraldDeleteController' => 'applications/herald/controller/HeraldDeleteController.php',
+10
src/applications/herald/adapter/HeraldAdapter.php
··· 292 292 } 293 293 294 294 295 + /* -( Repetition )--------------------------------------------------------- */ 296 + 297 + 298 + public function getRepetitionOptions() { 299 + return array( 300 + HeraldRepetitionPolicyConfig::EVERY, 301 + ); 302 + } 303 + 304 + 295 305 public static function applyFlagEffect(HeraldEffect $effect, $phid) { 296 306 $color = $effect->getTarget(); 297 307
+6
src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php
··· 46 46 ); 47 47 } 48 48 49 + public function getRepetitionOptions() { 50 + return array( 51 + HeraldRepetitionPolicyConfig::EVERY, 52 + HeraldRepetitionPolicyConfig::FIRST, 53 + ); 54 + } 49 55 50 56 public static function newLegacyAdapter( 51 57 DifferentialRevision $revision,
-8
src/applications/herald/config/HeraldContentTypeConfig.php
··· 1 - <?php 2 - 3 - final class HeraldContentTypeConfig { 4 - 5 - const CONTENT_TYPE_DIFFERENTIAL = 'differential'; 6 - const CONTENT_TYPE_COMMIT = 'commit'; 7 - 8 - }
+6 -24
src/applications/herald/config/HeraldRepetitionPolicyConfig.php
··· 1 1 <?php 2 2 3 3 final class HeraldRepetitionPolicyConfig { 4 + 4 5 const FIRST = 'first'; // only execute the first time (no repeating) 5 6 const EVERY = 'every'; // repeat every time 6 7 ··· 9 10 self::EVERY => 1, 10 11 ); 11 12 12 - private static $policyMap = array( 13 - self::FIRST => 'only the first time', 14 - self::EVERY => 'every time', 15 - ); 16 - 17 13 public static function getMap() { 18 - return self::$policyMap; 19 - } 20 - 21 - public static function getMapForContentType($type) { 22 - switch ($type) { 23 - case HeraldContentTypeConfig::CONTENT_TYPE_DIFFERENTIAL: 24 - return array_select_keys( 25 - self::$policyMap, 26 - array( 27 - self::EVERY, 28 - self::FIRST, 29 - )); 30 - 31 - case HeraldContentTypeConfig::CONTENT_TYPE_COMMIT: 32 - return array(); 33 - 34 - default: 35 - throw new Exception("Unknown content type '{$type}'."); 36 - } 14 + return array( 15 + self::EVERY => pht('every time'), 16 + self::FIRST => pht('only the first time'), 17 + ); 37 18 } 38 19 39 20 public static function toInt($str) { ··· 43 24 public static function toString($int) { 44 25 return idx(array_flip(self::$policyIntMap), $int, self::EVERY); 45 26 } 27 + 46 28 }
+9 -16
src/applications/herald/controller/HeraldRuleController.php
··· 86 86 } 87 87 88 88 $must_match_selector = $this->renderMustMatchSelector($rule); 89 - $repetition_selector = $this->renderRepetitionSelector($rule); 89 + $repetition_selector = $this->renderRepetitionSelector($rule, $adapter); 90 90 91 91 $handles = $this->loadHandlesForRule($rule); 92 92 ··· 492 492 * Render the selector for "Take these actions (every time | only the first 493 493 * time) this rule matches..." element. 494 494 */ 495 - private function renderRepetitionSelector($rule) { 496 - // Make the selector for choosing how often this rule should be repeated 495 + private function renderRepetitionSelector($rule, HeraldAdapter $adapter) { 497 496 $repetition_policy = HeraldRepetitionPolicyConfig::toString( 498 497 $rule->getRepetitionPolicy()); 499 - $repetition_options = HeraldRepetitionPolicyConfig::getMapForContentType( 500 - $rule->getContentType()); 501 498 502 - if (empty($repetition_options)) { 503 - // default option is 'every time' 504 - $repetition_selector = idx( 505 - HeraldRepetitionPolicyConfig::getMap(), 506 - HeraldRepetitionPolicyConfig::EVERY); 507 - return $repetition_selector; 508 - } else if (count($repetition_options) == 1) { 509 - // if there's only 1 option, just pick it for the user 510 - $repetition_selector = reset($repetition_options); 511 - return $repetition_selector; 499 + $repetition_options = $adapter->getRepetitionOptions(); 500 + $repetition_names = HeraldRepetitionPolicyConfig::getMap(); 501 + $repetition_map = array_select_keys($repetition_names, $repetition_options); 502 + 503 + if (count($repetition_map) < 2) { 504 + return head($repetition_names); 512 505 } else { 513 506 return AphrontFormSelectControl::renderSelectTag( 514 507 $repetition_policy, 515 - $repetition_options, 508 + $repetition_map, 516 509 array( 517 510 'name' => 'repetition_policy', 518 511 ));