From 78eb81ffd069410360b38ec35cb17e3188978f32 Mon Sep 17 00:00:00 2001 From: epriestley Date: Fri, 2 Aug 2013 12:03:54 -0700 Subject: [PATCH] Remove almost all instances of HeraldContentTypeConfig Summary: Ref T2769. This cleans up almost every use of the HeraldContentTypeConfig class. Test Plan: Viewed and edited Herald rules. Reviewers: btrahan Reviewed By: btrahan CC: aran Maniphest Tasks: T2769 Differential Revision: https://secure.phabricator.com/D6662 --- src/applications/herald/adapter/HeraldAdapter.php | 15 ++++++++++++++- .../herald/adapter/HeraldCommitAdapter.php | 4 ---- .../adapter/HeraldDifferentialRevisionAdapter.php | 4 ---- .../herald/adapter/HeraldDryRunAdapter.php | 4 ---- .../herald/config/HeraldContentTypeConfig.php | 13 ------------- .../herald/controller/HeraldNewController.php | 2 +- .../herald/controller/HeraldRuleController.php | 2 +- .../controller/HeraldRuleListController.php | 2 +- .../controller/HeraldTestConsoleController.php | 2 +- src/applications/herald/engine/HeraldEngine.php | 4 ++-- .../herald/query/HeraldRuleSearchEngine.php | 4 ++-- .../PhabricatorRepositoryCommitHeraldWorker.php | 2 +- 12 files changed, 23 insertions(+), 35 deletions(-) diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index 2913fd747d..cbe17d2d9d 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -54,7 +54,6 @@ abstract class HeraldAdapter { abstract public function getPHID(); abstract public function getHeraldName(); - abstract public function getHeraldTypeName(); abstract public function getHeraldField($field_name); abstract public function applyHeraldEffects(array $effects); @@ -367,6 +366,20 @@ abstract class HeraldAdapter { $content_type)); } + public static function getEnabledAdapterMap() { + $map = array(); + + $adapters = HeraldAdapter::getAllEnabledAdapters(); + foreach ($adapters as $adapter) { + $type = $adapter->getAdapterContentType(); + $name = $adapter->getAdapterContentName(); + $map[$type] = $name; + } + + asort($map); + return $map; + } + } diff --git a/src/applications/herald/adapter/HeraldCommitAdapter.php b/src/applications/herald/adapter/HeraldCommitAdapter.php index e025e1c2ec..eb6a866f24 100644 --- a/src/applications/herald/adapter/HeraldCommitAdapter.php +++ b/src/applications/herald/adapter/HeraldCommitAdapter.php @@ -149,10 +149,6 @@ final class HeraldCommitAdapter extends HeraldAdapter { $this->commit->getCommitIdentifier(); } - public function getHeraldTypeName() { - return HeraldContentTypeConfig::CONTENT_TYPE_COMMIT; - } - public function loadAffectedPaths() { if ($this->affectedPaths === null) { $result = PhabricatorOwnerPathQuery::loadAffectedPaths( diff --git a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php index 885c727f9b..666f78f8a1 100644 --- a/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php +++ b/src/applications/herald/adapter/HeraldDifferentialRevisionAdapter.php @@ -95,10 +95,6 @@ final class HeraldDifferentialRevisionAdapter extends HeraldAdapter { return $this->revision->getTitle(); } - public function getHeraldTypeName() { - return HeraldContentTypeConfig::CONTENT_TYPE_DIFFERENTIAL; - } - public function loadRepository() { if ($this->repository === null) { $diff = $this->diff; diff --git a/src/applications/herald/adapter/HeraldDryRunAdapter.php b/src/applications/herald/adapter/HeraldDryRunAdapter.php index fc644add16..0b5526b823 100644 --- a/src/applications/herald/adapter/HeraldDryRunAdapter.php +++ b/src/applications/herald/adapter/HeraldDryRunAdapter.php @@ -18,10 +18,6 @@ final class HeraldDryRunAdapter extends HeraldAdapter { return 'Dry Run'; } - public function getHeraldTypeName() { - return null; - } - public function getHeraldField($field) { return null; } diff --git a/src/applications/herald/config/HeraldContentTypeConfig.php b/src/applications/herald/config/HeraldContentTypeConfig.php index 7b5c9485cc..36f04acb77 100644 --- a/src/applications/herald/config/HeraldContentTypeConfig.php +++ b/src/applications/herald/config/HeraldContentTypeConfig.php @@ -5,17 +5,4 @@ final class HeraldContentTypeConfig { const CONTENT_TYPE_DIFFERENTIAL = 'differential'; const CONTENT_TYPE_COMMIT = 'commit'; - public static function getContentTypeMap() { - $map = array(); - - $adapters = HeraldAdapter::getAllEnabledAdapters(); - foreach ($adapters as $adapter) { - $type = $adapter->getAdapterContentType(); - $name = $adapter->getAdapterContentName(); - $map[$type] = $name; - } - - asort($map); - return $map; - } } diff --git a/src/applications/herald/controller/HeraldNewController.php b/src/applications/herald/controller/HeraldNewController.php index 894ba9ed9b..03929977dc 100644 --- a/src/applications/herald/controller/HeraldNewController.php +++ b/src/applications/herald/controller/HeraldNewController.php @@ -15,7 +15,7 @@ final class HeraldNewController extends HeraldController { $request = $this->getRequest(); $user = $request->getUser(); - $content_type_map = HeraldContentTypeConfig::getContentTypeMap(); + $content_type_map = HeraldAdapter::getEnabledAdapterMap(); if (empty($content_type_map[$this->contentType])) { $this->contentType = head_key($content_type_map); } diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php index 5a2bae530d..2fd14b5deb 100644 --- a/src/applications/herald/controller/HeraldRuleController.php +++ b/src/applications/herald/controller/HeraldRuleController.php @@ -14,7 +14,7 @@ final class HeraldRuleController extends HeraldController { $request = $this->getRequest(); $user = $request->getUser(); - $content_type_map = HeraldContentTypeConfig::getContentTypeMap(); + $content_type_map = HeraldAdapter::getEnabledAdapterMap(); $rule_type_map = HeraldRuleTypeConfig::getRuleTypeMap(); if ($this->id) { diff --git a/src/applications/herald/controller/HeraldRuleListController.php b/src/applications/herald/controller/HeraldRuleListController.php index f0d8bdb4f1..9c117884ae 100644 --- a/src/applications/herald/controller/HeraldRuleListController.php +++ b/src/applications/herald/controller/HeraldRuleListController.php @@ -33,7 +33,7 @@ final class HeraldRuleListController extends HeraldController $phids = mpull($rules, 'getAuthorPHID'); $this->loadHandles($phids); - $content_type_map = HeraldContentTypeConfig::getContentTypeMap(); + $content_type_map = HeraldAdapter::getEnabledAdapterMap(); $list = id(new PhabricatorObjectItemListView()) ->setUser($viewer); diff --git a/src/applications/herald/controller/HeraldTestConsoleController.php b/src/applications/herald/controller/HeraldTestConsoleController.php index 5eb8fcce3f..26d682624b 100644 --- a/src/applications/herald/controller/HeraldTestConsoleController.php +++ b/src/applications/herald/controller/HeraldTestConsoleController.php @@ -69,7 +69,7 @@ final class HeraldTestConsoleController extends HeraldController { } $rules = HeraldRule::loadAllByContentTypeWithFullData( - $adapter->getHeraldTypeName(), + $adapter->getAdapterContentType(), $object->getPHID()); $engine = new HeraldEngine(); diff --git a/src/applications/herald/engine/HeraldEngine.php b/src/applications/herald/engine/HeraldEngine.php index 03043a970d..c585690cd3 100644 --- a/src/applications/herald/engine/HeraldEngine.php +++ b/src/applications/herald/engine/HeraldEngine.php @@ -11,7 +11,7 @@ final class HeraldEngine { protected $object = null; public static function loadAndApplyRules(HeraldAdapter $object) { - $content_type = $object->getHeraldTypeName(); + $content_type = $object->getAdapterContentType(); $rules = HeraldRule::loadAllByContentTypeWithFullData( $content_type, $object->getPHID()); @@ -90,7 +90,7 @@ final class HeraldEngine { $object_transcript = new HeraldObjectTranscript(); $object_transcript->setPHID($object->getPHID()); $object_transcript->setName($object->getHeraldName()); - $object_transcript->setType($object->getHeraldTypeName()); + $object_transcript->setType($object->getAdapterContentType()); $object_transcript->setFields($this->fieldCache); $this->transcript->setObjectTranscript($object_transcript); diff --git a/src/applications/herald/query/HeraldRuleSearchEngine.php b/src/applications/herald/query/HeraldRuleSearchEngine.php index fbde424fdc..3e787fa3b1 100644 --- a/src/applications/herald/query/HeraldRuleSearchEngine.php +++ b/src/applications/herald/query/HeraldRuleSearchEngine.php @@ -109,11 +109,11 @@ final class HeraldRuleSearchEngine private function getContentTypeOptions() { return array( '' => pht('(All Content Types)'), - ) + HeraldContentTypeConfig::getContentTypeMap(); + ) + HeraldAdapter::getEnabledAdapterMap(); } private function getContentTypeValues() { - return array_fuse(array_keys(HeraldContentTypeConfig::getContentTypeMap())); + return array_fuse(array_keys(HeraldAdapter::getEnabledAdapterMap())); } private function getRuleTypeOptions() { diff --git a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php index 1230a05137..9e74c6a820 100644 --- a/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php +++ b/src/applications/repository/worker/PhabricatorRepositoryCommitHeraldWorker.php @@ -22,7 +22,7 @@ final class PhabricatorRepositoryCommitHeraldWorker } $rules = HeraldRule::loadAllByContentTypeWithFullData( - HeraldContentTypeConfig::CONTENT_TYPE_COMMIT, + id(new HeraldCommitAdapter())->getAdapterContentType(), $commit->getPHID()); $adapter = HeraldCommitAdapter::newLegacyAdapter(