@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 legacy pre-loading of handles from Herald rendering

Summary: Ref T13480. When Herald renders rules, it partly uses a very old handle pre-loading mechanism where PHIDs are extracted and loaded upfront. This was obsoleted a long time ago and was pretty shaky even when it worked. Get rid of it to simplify the code a little.

Test Plan: Viewed Herald rules rendered into static text with PHID list actions, saw handles. Grepped for all affected methods.

Maniphest Tasks: T13480

Differential Revision: https://secure.phabricator.com/D20948

+13 -99
+11 -96
src/applications/herald/adapter/HeraldAdapter.php
··· 942 942 943 943 public function renderRuleAsText( 944 944 HeraldRule $rule, 945 - PhabricatorHandleList $handles, 946 945 PhabricatorUser $viewer) { 947 946 948 947 require_celerity_resource('herald-css'); ··· 973 972 ), 974 973 array( 975 974 $icon, 976 - $this->renderConditionAsText($condition, $handles, $viewer), 975 + $this->renderConditionAsText($condition, $viewer), 977 976 )); 978 977 } 979 978 ··· 1004 1003 ), 1005 1004 array( 1006 1005 $icon, 1007 - $this->renderActionAsText($viewer, $action, $handles), 1006 + $this->renderActionAsText($viewer, $action), 1008 1007 )); 1009 1008 } 1010 1009 ··· 1018 1017 1019 1018 private function renderConditionAsText( 1020 1019 HeraldCondition $condition, 1021 - PhabricatorHandleList $handles, 1022 1020 PhabricatorUser $viewer) { 1023 1021 1024 1022 $field_type = $condition->getFieldName(); ··· 1033 1031 $condition_type = $condition->getFieldCondition(); 1034 1032 $condition_name = idx($this->getConditionNameMap(), $condition_type); 1035 1033 1036 - $value = $this->renderConditionValueAsText($condition, $handles, $viewer); 1034 + $value = $this->renderConditionValueAsText($condition, $viewer); 1037 1035 1038 1036 return array( 1039 1037 $field_name, ··· 1046 1044 1047 1045 private function renderActionAsText( 1048 1046 PhabricatorUser $viewer, 1049 - HeraldActionRecord $action, 1050 - PhabricatorHandleList $handles) { 1047 + HeraldActionRecord $action_record) { 1051 1048 1052 - $impl = $this->getActionImplementation($action->getAction()); 1053 - if ($impl) { 1054 - $impl->setViewer($viewer); 1049 + $action_type = $action_record->getAction(); 1050 + $action_value = $action_record->getTarget(); 1055 1051 1056 - $value = $action->getTarget(); 1057 - return $impl->renderActionDescription($value); 1052 + $action = $this->getActionImplementation($action_type); 1053 + if (!$action) { 1054 + return pht('Unknown Action ("%s")', $action_type); 1058 1055 } 1059 1056 1060 - $rule_global = HeraldRuleTypeConfig::RULE_TYPE_GLOBAL; 1061 - 1062 - $action_type = $action->getAction(); 1063 - 1064 - $default = pht('(Unknown Action "%s") equals', $action_type); 1065 - 1066 - $action_name = idx( 1067 - $this->getActionNameMap($rule_global), 1068 - $action_type, 1069 - $default); 1070 - 1071 - $target = $this->renderActionTargetAsText($action, $handles); 1057 + $action->setViewer($viewer); 1072 1058 1073 - return hsprintf(' %s %s', $action_name, $target); 1059 + return $action->renderActionDescription($action_value); 1074 1060 } 1075 1061 1076 1062 private function renderConditionValueAsText( 1077 1063 HeraldCondition $condition, 1078 - PhabricatorHandleList $handles, 1079 1064 PhabricatorUser $viewer) { 1080 1065 1081 1066 $field = $this->requireFieldImplementation($condition->getFieldName()); ··· 1086 1071 $condition->getValue()); 1087 1072 } 1088 1073 1089 - private function renderActionTargetAsText( 1090 - HeraldActionRecord $action, 1091 - PhabricatorHandleList $handles) { 1092 - 1093 - // TODO: This should be driven through HeraldAction. 1094 - 1095 - $target = $action->getTarget(); 1096 - if (!is_array($target)) { 1097 - $target = array($target); 1098 - } 1099 - foreach ($target as $index => $val) { 1100 - switch ($action->getAction()) { 1101 - default: 1102 - $handle = $handles->getHandleIfExists($val); 1103 - if ($handle) { 1104 - $target[$index] = $handle->renderLink(); 1105 - } 1106 - break; 1107 - } 1108 - } 1109 - $target = phutil_implode_html(', ', $target); 1110 - return $target; 1111 - } 1112 - 1113 - /** 1114 - * Given a @{class:HeraldRule}, this function extracts all the phids that 1115 - * we'll want to load as handles later. 1116 - * 1117 - * This function performs a somewhat hacky approach to figuring out what 1118 - * is and is not a phid - try to get the phid type and if the type is 1119 - * *not* unknown assume its a valid phid. 1120 - * 1121 - * Don't try this at home. Use more strongly typed data at home. 1122 - * 1123 - * Think of the children. 1124 - */ 1125 - public static function getHandlePHIDs(HeraldRule $rule) { 1126 - $phids = array($rule->getAuthorPHID()); 1127 - foreach ($rule->getConditions() as $condition) { 1128 - $value = $condition->getValue(); 1129 - if (!is_array($value)) { 1130 - $value = array($value); 1131 - } 1132 - foreach ($value as $val) { 1133 - if (phid_get_type($val) != 1134 - PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) { 1135 - $phids[] = $val; 1136 - } 1137 - } 1138 - } 1139 - 1140 - foreach ($rule->getActions() as $action) { 1141 - $target = $action->getTarget(); 1142 - if (!is_array($target)) { 1143 - $target = array($target); 1144 - } 1145 - foreach ($target as $val) { 1146 - if (phid_get_type($val) != 1147 - PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN) { 1148 - $phids[] = $val; 1149 - } 1150 - } 1151 - } 1152 - 1153 - if ($rule->isObjectRule()) { 1154 - $phids[] = $rule->getTriggerObjectPHID(); 1155 - } 1156 - 1157 - return $phids; 1158 - } 1159 1074 1160 1075 /* -( Applying Effects )--------------------------------------------------- */ 1161 1076
+2 -3
src/applications/herald/controller/HeraldRuleViewController.php
··· 143 143 private function buildDescriptionView(HeraldRule $rule) { 144 144 $viewer = $this->getRequest()->getUser(); 145 145 $view = id(new PHUIPropertyListView()) 146 - ->setUser($viewer); 146 + ->setViewer($viewer); 147 147 148 148 $adapter = HeraldAdapter::getAdapterForContentType($rule->getContentType()); 149 149 if ($adapter) { 150 - $handles = $viewer->loadHandles(HeraldAdapter::getHandlePHIDs($rule)); 151 - $rule_text = $adapter->renderRuleAsText($rule, $handles, $viewer); 150 + $rule_text = $adapter->renderRuleAsText($rule, $viewer); 152 151 $view->addTextContent($rule_text); 153 152 return $view; 154 153 }