@@ -710,7 +710,9 @@ public static function getEnabledAdapterMap() {
710710  }
711711
712712
713-   public  function  renderRuleAsText (HeraldRule $ rule
713+   public  function  renderRuleAsText (HeraldRule $ rulearray  $ handles
714+     assert_instances_of ($ handles'PhabricatorObjectHandle ' );
715+ 
714716    $ outarray ();
715717
716718    if  ($ rulegetMustMatchAll ()) {
@@ -721,7 +723,7 @@ public function renderRuleAsText(HeraldRule $rule) {
721723
722724    $ outnull ;
723725    foreach  ($ rulegetConditions () as  $ condition
724-       $ out"      " . $ this renderConditionAsText ($ condition
726+       $ out$ this renderConditionAsText ($ condition,  $ handles 
725727    }
726728    $ outnull ;
727729
@@ -733,53 +735,116 @@ public function renderRuleAsText(HeraldRule $rule) {
733735
734736    $ outnull ;
735737    foreach  ($ rulegetActions () as  $ action
736-       $ out"      " . $ this renderActionAsText ($ action
738+       $ out$ this renderActionAsText ($ action,  $ handles 
737739    }
738740
739-     return  implode ("\n" , $ out
741+     return  phutil_implode_html ("\n" , $ out
740742  }
741743
742-   private  function  renderConditionAsText (HeraldCondition $ condition
744+   private  function  renderConditionAsText (
745+     HeraldCondition $ condition
746+     array  $ handles
743747    $ field_type$ conditiongetFieldName ();
744748    $ field_nameidx ($ this getFieldNameMap (), $ field_type
745749
746750    $ condition_type$ conditiongetFieldCondition ();
747751    $ condition_nameidx ($ this getConditionNameMap (), $ condition_type
748752
749-     $ value$ this renderConditionValueAsText ($ condition
753+     $ value$ this renderConditionValueAsText ($ condition,  $ handles 
750754
751-     return  "{ $ field_name}   { $ condition_name}   { $ value}" 
755+     return  hsprintf ( '     %s %s %s ' ,  $ field_name,  $ condition_name,  $ value) ;
752756  }
753757
754-   private  function  renderActionAsText (HeraldAction $ action
758+   private  function  renderActionAsText (
759+     HeraldAction $ action
760+     array  $ handles
755761    $ rule_globalRULE_TYPE_GLOBAL ;
756762
757763    $ action_type$ actiongetAction ();
758764    $ action_nameidx ($ this getActionNameMap ($ rule_global$ action_type
759765
760-     $ target$ this renderActionTargetAsText ($ action
766+     $ target$ this renderActionTargetAsText ($ action,  $ handles 
761767
762-     return  "{ $ action_name}   { $ target}" 
768+     return  hsprintf ( '     %s %s ' ,  $ action_name,  $ target) ;
763769  }
764770
765-   private  function  renderConditionValueAsText (HeraldCondition $ condition
766-     // TODO: This produces sketchy results for many conditions. 
771+   private  function  renderConditionValueAsText (
772+     HeraldCondition $ condition
773+     array  $ handles
774+ 
767775    $ value$ conditiongetValue ();
768-     if  (is_array ($ value
769-       $ valueimplode ( ' ,  ' ,  $ value
776+     if  (! is_array ($ value
777+       $ valuearray ( $ value
770778    }
779+     foreach  ($ valueas  $ index$ val
780+       $ handleidx ($ handles$ val
781+       if  ($ handle
782+         $ value$ index$ handlerenderLink ();
783+       }
784+     }
785+     $ valuephutil_implode_html (',  ' , $ value
771786    return  $ value
772787  }
773788
774-   private  function  renderActionTargetAsText (HeraldAction $ action
775-     // TODO: This produces sketchy results for Flags and PHIDs. 
789+   private  function  renderActionTargetAsText (
790+     HeraldAction $ action
791+     array  $ handles
792+ 
776793    $ target$ actiongetTarget ();
777-     if  (is_array ($ target
778-       $ targetimplode ( ' ,  ' ,  $ target
794+     if  (! is_array ($ target
795+       $ targetarray ( $ target
779796    }
780- 
797+     foreach  ($ targetas  $ index$ val
798+       $ handleidx ($ handles$ val
799+       if  ($ handle
800+         $ target$ index$ handlerenderLink ();
801+       }
802+     }
803+     $ targetphutil_implode_html (',  ' , $ target
781804    return  $ target
782805  }
783806
807+   /** 
808+    * Given a @{class:HeraldRule}, this function extracts all the phids that 
809+    * we'll want to load as handles later. 
810+    * 
811+    * This function performs a somewhat hacky approach to figuring out what 
812+    * is and is not a phid - try to get the phid type and if the type is 
813+    * *not* unknown assume its a valid phid. 
814+    * 
815+    * Don't try this at home. Use more strongly typed data at home. 
816+    * 
817+    * Think of the children. 
818+    */ 
819+   public  static  function  getHandlePHIDs (HeraldRule $ rule
820+     $ phidsarray ($ rulegetAuthorPHID ());
821+     foreach  ($ rulegetConditions () as  $ condition
822+       $ value$ conditiongetValue ();
823+       if  (!is_array ($ value
824+         $ valuearray ($ value
825+       }
826+       foreach  ($ valueas  $ val
827+         if  (phid_get_type ($ val
828+             PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN ) {
829+           $ phids$ val
830+         }
831+       }
832+     }
833+ 
834+     foreach  ($ rulegetActions () as  $ action
835+       $ target$ actiongetTarget ();
836+       if  (!is_array ($ target
837+         $ targetarray ($ target
838+       }
839+       foreach  ($ targetas  $ val
840+         if  (phid_get_type ($ val
841+             PhabricatorPHIDConstants::PHID_TYPE_UNKNOWN ) {
842+           $ phids$ val
843+         }
844+       }
845+     }
846+     return  $ phids
847+   }
848+ 
784849}
785850
0 commit comments