1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-22 14:52:41 +01:00

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
This commit is contained in:
epriestley 2019-09-09 12:38:36 -07:00
parent aaaea57591
commit d965d9a669
3 changed files with 39 additions and 0 deletions

View file

@ -0,0 +1,3 @@
<?php
PhabricatorRebuildIndexesWorker::rebuildObjectsWithQuery('HeraldRuleQuery');

View file

@ -37,6 +37,20 @@ final class HeraldRuleIndexEngineExtension
$phids = array();
$fields = HeraldField::getAllFields();
foreach ($rule->getConditions() as $condition_record) {
$field = idx($fields, $condition_record->getFieldName());
if (!$field) {
continue;
}
$affected_phids = $field->getPHIDsAffectedByCondition($condition_record);
foreach ($affected_phids as $phid) {
$phids[] = $phid;
}
}
$actions = HeraldAction::getAllActions();
foreach ($rule->getActions() as $action_record) {
$action = idx($actions, $action_record->getAction());

View file

@ -176,6 +176,28 @@ abstract class HeraldField extends Phobject {
return $value_type->renderEditorValue($value);
}
public function getPHIDsAffectedByCondition(HeraldCondition $condition) {
$phids = array();
$standard_type = $this->getHeraldFieldStandardType();
switch ($standard_type) {
case self::STANDARD_PHID:
case self::STANDARD_PHID_NULLABLE:
$phid = $condition->getValue();
if ($phid) {
$phids[] = $phid;
}
break;
case self::STANDARD_PHID_LIST:
foreach ($condition->getValue() as $phid) {
$phids[] = $phid;
}
break;
}
return $phids;
}
final public function setAdapter(HeraldAdapter $adapter) {
$this->adapter = $adapter;
return $this;