From d965d9a669b58ed8968cda51d1467d3aeb570fc9 Mon Sep 17 00:00:00 2001 From: epriestley Date: Mon, 9 Sep 2019 12:38:36 -0700 Subject: [PATCH] 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 --- .../20190909.herald.01.rebuild.php | 3 +++ .../HeraldRuleIndexEngineExtension.php | 14 ++++++++++++ src/applications/herald/field/HeraldField.php | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 resources/sql/autopatches/20190909.herald.01.rebuild.php diff --git a/resources/sql/autopatches/20190909.herald.01.rebuild.php b/resources/sql/autopatches/20190909.herald.01.rebuild.php new file mode 100644 index 0000000000..a29b7d2f45 --- /dev/null +++ b/resources/sql/autopatches/20190909.herald.01.rebuild.php @@ -0,0 +1,3 @@ +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()); diff --git a/src/applications/herald/field/HeraldField.php b/src/applications/herald/field/HeraldField.php index 611ea2cdb3..3df242712e 100644 --- a/src/applications/herald/field/HeraldField.php +++ b/src/applications/herald/field/HeraldField.php @@ -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;