From 46bd6b30f8fd55b4ef964dfd0663eaba1e84357b Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 3 Aug 2015 17:05:21 -0700 Subject: [PATCH] Fix undefined ACTION_BLOCK class constant in Herald Summary: Fixes T9054. This didn't get fully cleaned up. Test Plan: Edited several rules, saw actions faithfully represented. Reviewers: joshuaspence, chad Reviewed By: chad Maniphest Tasks: T9054 Differential Revision: https://secure.phabricator.com/D13781 --- .../herald/action/HeraldAction.php | 17 +++++++++++++ .../herald/adapter/HeraldAdapter.php | 14 +++++++++-- .../controller/HeraldRuleController.php | 24 ++++--------------- 3 files changed, 34 insertions(+), 21 deletions(-) diff --git a/src/applications/herald/action/HeraldAction.php b/src/applications/herald/action/HeraldAction.php index bc47fee88b..02a9dfa60a 100644 --- a/src/applications/herald/action/HeraldAction.php +++ b/src/applications/herald/action/HeraldAction.php @@ -86,6 +86,23 @@ abstract class HeraldAction extends Phobject { return $value; } + public function getEditorValue(PhabricatorUser $viewer, $target) { + try { + $type = $this->getHeraldActionStandardType(); + } catch (PhutilMethodNotImplementedException $ex) { + return $target; + } + + switch ($type) { + case self::STANDARD_PHID_LIST: + $handles = $viewer->loadHandles($target); + $handles = iterator_to_array($handles); + return mpull($handles, 'getName', 'getPHID'); + } + + return $target; + } + final public function setAdapter(HeraldAdapter $adapter) { $this->adapter = $adapter; return $this; diff --git a/src/applications/herald/adapter/HeraldAdapter.php b/src/applications/herald/adapter/HeraldAdapter.php index b46e9430c1..bec6677230 100644 --- a/src/applications/herald/adapter/HeraldAdapter.php +++ b/src/applications/herald/adapter/HeraldAdapter.php @@ -770,8 +770,7 @@ abstract class HeraldAdapter extends Phobject { public function getEditorValueForCondition( PhabricatorUser $viewer, - HeraldCondition $condition, - array $handles) { + HeraldCondition $condition) { $field = $this->requireFieldImplementation($condition->getFieldName()); @@ -781,6 +780,17 @@ abstract class HeraldAdapter extends Phobject { $condition->getValue()); } + public function getEditorValueForAction( + PhabricatorUser $viewer, + HeraldActionRecord $action_record) { + + $action = $this->requireActionImplementation($action_record->getAction()); + + return $action->getEditorValue( + $viewer, + $action_record->getTarget()); + } + public function renderRuleAsText( HeraldRule $rule, PhabricatorHandleList $handles, diff --git a/src/applications/herald/controller/HeraldRuleController.php b/src/applications/herald/controller/HeraldRuleController.php index cd35307723..ce7a46cd00 100644 --- a/src/applications/herald/controller/HeraldRuleController.php +++ b/src/applications/herald/controller/HeraldRuleController.php @@ -348,8 +348,7 @@ final class HeraldRuleController extends HeraldController { foreach ($rule->getConditions() as $condition) { $value = $adapter->getEditorValueForCondition( $this->getViewer(), - $condition, - $handles); + $condition); $serial_conditions[] = array( $condition->getFieldName(), @@ -366,26 +365,13 @@ final class HeraldRuleController extends HeraldController { if ($rule->getActions()) { $serial_actions = array(); foreach ($rule->getActions() as $action) { - switch ($action->getAction()) { - case HeraldAdapter::ACTION_BLOCK: - $current_value = $action->getTarget(); - break; - default: - if (is_array($action->getTarget())) { - $target_map = array(); - foreach ((array)$action->getTarget() as $fbid) { - $target_map[$fbid] = $handles[$fbid]->getName(); - } - $current_value = $target_map; - } else { - $current_value = $action->getTarget(); - } - break; - } + $value = $adapter->getEditorValueForAction( + $this->getViewer(), + $action); $serial_actions[] = array( $action->getAction(), - $current_value, + $value, ); } }