@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.

Herald - make herald condition of herald rule display better

Summary: ...by the surprising step of changing how this data is stored from id to phid. Also a small fix to not allow "disabled" rules to be used as herald rule conditions, i.e. can't make a rule that depends on a disabled rule.

Test Plan: viewed existing herald rule that had a rule condition and noted nice new display using handle. made a new rule that had a rule condition and verified it worked correctly.

Reviewers: epriestley

Reviewed By: epriestley

CC: Korvin, epriestley, aran

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

+54 -16
+31
resources/sql/autopatches/20140210.herald.rule-condition-mig.php
··· 1 + <?php 2 + 3 + $table = new HeraldCondition(); 4 + $conn_w = $table->establishConnection('w'); 5 + 6 + echo "Migrating Herald conditions of type Herald rule from IDs to PHIDs...\n"; 7 + foreach (new LiskMigrationIterator($table) as $condition) { 8 + if ($condition->getFieldName() != HeraldAdapter::FIELD_RULE) { 9 + continue; 10 + } 11 + 12 + $value = $condition->getValue(); 13 + if (!is_numeric($value)) { 14 + continue; 15 + } 16 + $id = $condition->getID(); 17 + echo "Updating condition {$id}...\n"; 18 + 19 + $rule = id(new HeraldRuleQuery()) 20 + ->setViewer(PhabricatorUser::getOmnipotentUser()) 21 + ->withIDs(array($value)) 22 + ->executeOne(); 23 + 24 + queryfx( 25 + $conn_w, 26 + 'UPDATE %T SET value = %s WHERE id = %d', 27 + $table->getTableName(), 28 + json_encode($rule->getPHID()), 29 + $id); 30 + } 31 + echo "Done.\n";
-1
src/applications/diffusion/herald/HeraldPreCommitContentAdapter.php
··· 44 44 self::FIELD_DIFFERENTIAL_REVIEWERS, 45 45 self::FIELD_DIFFERENTIAL_CCS, 46 46 self::FIELD_IS_MERGE_COMMIT, 47 - self::FIELD_RULE, 48 47 ), 49 48 parent::getFields()); 50 49 }
-1
src/applications/diffusion/herald/HeraldPreCommitRefAdapter.php
··· 41 41 self::FIELD_REPOSITORY_PROJECTS, 42 42 self::FIELD_PUSHER, 43 43 self::FIELD_PUSHER_PROJECTS, 44 - self::FIELD_RULE, 45 44 ), 46 45 parent::getFields()); 47 46 }
+10 -1
src/applications/herald/controller/HeraldRuleController.php
··· 414 414 } 415 415 416 416 $all_rules = $this->loadRulesThisRuleMayDependUpon($rule); 417 - $all_rules = mpull($all_rules, 'getName', 'getID'); 417 + $all_rules = mpull($all_rules, 'getName', 'getPHID'); 418 418 asort($all_rules); 419 419 420 420 $all_fields = $adapter->getFieldNameMap(); ··· 631 631 ->withContentTypes(array($rule->getContentType())) 632 632 ->withAuthorPHIDs(array($rule->getAuthorPHID())) 633 633 ->execute(); 634 + } 635 + 636 + // mark disabled rules as disabled since they are not useful as such; 637 + // don't filter though to keep edit cases sane / expected 638 + foreach ($all_rules as $current_rule) { 639 + if ($current_rule->getIsDisabled()) { 640 + $current_rule->makeEphemeral(); 641 + $current_rule->setName($rule->getName(). ' '.pht('(Disabled)')); 642 + } 634 643 } 635 644 636 645 // A rule can not depend upon itself.
+13 -13
src/applications/herald/engine/HeraldEngine.php
··· 20 20 return $this->dryRun; 21 21 } 22 22 23 - public function getRule($id) { 24 - return idx($this->rules, $id); 23 + public function getRule($phid) { 24 + return idx($this->rules, $phid); 25 25 } 26 26 27 27 public function loadRulesForAdapter(HeraldAdapter $adapter) { ··· 49 49 assert_instances_of($rules, 'HeraldRule'); 50 50 $t_start = microtime(true); 51 51 52 - $rules = mpull($rules, null, 'getID'); 52 + $rules = mpull($rules, null, 'getPHID'); 53 53 54 54 $this->transcript = new HeraldTranscript(); 55 55 $this->transcript->setObjectPHID((string)$object->getPHID()); ··· 59 59 $this->object = $object; 60 60 61 61 $effects = array(); 62 - foreach ($rules as $id => $rule) { 62 + foreach ($rules as $phid => $rule) { 63 63 $this->stack = array(); 64 64 try { 65 65 if (!$this->getDryRun() && ··· 70 70 // applied a single time, and it's already been applied... 71 71 // That means automatic failure. 72 72 $xscript = id(new HeraldRuleTranscript()) 73 - ->setRuleID($id) 73 + ->setRuleID($rule->getID()) 74 74 ->setResult(false) 75 75 ->setRuleName($rule->getName()) 76 76 ->setRuleOwner($rule->getAuthorPHID()) ··· 102 102 } 103 103 $rule_matches = false; 104 104 } 105 - $this->results[$id] = $rule_matches; 105 + $this->results[$phid] = $rule_matches; 106 106 107 107 if ($rule_matches) { 108 108 foreach ($this->getRuleEffects($rule, $object) as $effect) { ··· 210 210 HeraldRule $rule, 211 211 HeraldAdapter $object) { 212 212 213 - $id = $rule->getID(); 213 + $phid = $rule->getPHID(); 214 214 215 - if (isset($this->results[$id])) { 215 + if (isset($this->results[$phid])) { 216 216 // If we've already evaluated this rule because another rule depends 217 217 // on it, we don't need to reevaluate it. 218 - return $this->results[$id]; 218 + return $this->results[$phid]; 219 219 } 220 220 221 - if (isset($this->stack[$id])) { 221 + if (isset($this->stack[$phid])) { 222 222 // We've recursed, fail all of the rules on the stack. This happens when 223 223 // there's a dependency cycle with "Rule conditions match for rule ..." 224 224 // conditions. 225 - foreach ($this->stack as $rule_id => $ignored) { 226 - $this->results[$rule_id] = false; 225 + foreach ($this->stack as $rule_phid => $ignored) { 226 + $this->results[$rule_phid] = false; 227 227 } 228 228 throw new HeraldRecursiveConditionsException(); 229 229 } 230 230 231 - $this->stack[$id] = true; 231 + $this->stack[$phid] = true; 232 232 233 233 $all = $rule->getMustMatchAll(); 234 234