@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

Index Herald fields, not just actions, when identifying objects related to a particular Herald rule

Summary:
Fixes T13408. Currently, when a package (or other object) appears in a field (rather than an action), it is not indexed.

Instead: index fields too, not just actions.

Test Plan:
- Wrote a rule like "[ Affected packages include ] ...".
- Updated the search index.
- Saw rule appear on "Affected By Herald Rules" on the package detail page.

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Maniphest Tasks: T13408

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

+39
+3
resources/sql/autopatches/20190909.herald.01.rebuild.php
··· 1 + <?php 2 + 3 + PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery('HeraldRuleQuery');
+14
src/applications/herald/engineextension/HeraldRuleIndexEngineExtension.php
··· 37 37 38 38 $phids = array(); 39 39 40 + $fields = HeraldField::getAllFields(); 41 + foreach ($rule->getConditions() as $condition_record) { 42 + $field = idx($fields, $condition_record->getFieldName()); 43 + 44 + if (!$field) { 45 + continue; 46 + } 47 + 48 + $affected_phids = $field->getPHIDsAffectedByCondition($condition_record); 49 + foreach ($affected_phids as $phid) { 50 + $phids[] = $phid; 51 + } 52 + } 53 + 40 54 $actions = HeraldAction::getAllActions(); 41 55 foreach ($rule->getActions() as $action_record) { 42 56 $action = idx($actions, $action_record->getAction());
+22
src/applications/herald/field/HeraldField.php
··· 176 176 return $value_type->renderEditorValue($value); 177 177 } 178 178 179 + public function getPHIDsAffectedByCondition(HeraldCondition $condition) { 180 + $phids = array(); 181 + 182 + $standard_type = $this->getHeraldFieldStandardType(); 183 + switch ($standard_type) { 184 + case self::STANDARD_PHID: 185 + case self::STANDARD_PHID_NULLABLE: 186 + $phid = $condition->getValue(); 187 + if ($phid) { 188 + $phids[] = $phid; 189 + } 190 + break; 191 + case self::STANDARD_PHID_LIST: 192 + foreach ($condition->getValue() as $phid) { 193 + $phids[] = $phid; 194 + } 195 + break; 196 + } 197 + 198 + return $phids; 199 + } 200 + 179 201 final public function setAdapter(HeraldAdapter $adapter) { 180 202 $this->adapter = $adapter; 181 203 return $this;