Differential D20398 Diff 48689 src/applications/herald/engineextension/HeraldRuleIndexEngineExtension.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/herald/engineextension/HeraldRuleIndexEngineExtension.php
| <?php | <?php | ||||
| final class HeraldRuleIndexEngineExtension | final class HeraldRuleIndexEngineExtension | ||||
| extends PhabricatorIndexEngineExtension { | extends PhabricatorEdgeIndexEngineExtension { | ||||
| const EXTENSIONKEY = 'herald.actions'; | const EXTENSIONKEY = 'herald.actions'; | ||||
| public function getExtensionName() { | public function getExtensionName() { | ||||
| return pht('Herald Actions'); | return pht('Herald Actions'); | ||||
| } | } | ||||
| public function shouldIndexObject($object) { | public function shouldIndexObject($object) { | ||||
| if (!($object instanceof HeraldRule)) { | if (!($object instanceof HeraldRule)) { | ||||
| return false; | return false; | ||||
| } | } | ||||
| return true; | return true; | ||||
| } | } | ||||
| public function indexObject( | protected function getIndexEdgeType() { | ||||
| PhabricatorIndexEngine $engine, | return HeraldRuleActionAffectsObjectEdgeType::EDGECONST; | ||||
| $object) { | |||||
| $edge_type = HeraldRuleActionAffectsObjectEdgeType::EDGECONST; | |||||
| $old_edges = PhabricatorEdgeQuery::loadDestinationPHIDs( | |||||
| $object->getPHID(), | |||||
| $edge_type); | |||||
| $old_edges = array_fuse($old_edges); | |||||
| $new_edges = $this->getPHIDsAffectedByActions($object); | |||||
| $new_edges = array_fuse($new_edges); | |||||
| $add_edges = array_diff_key($new_edges, $old_edges); | |||||
| $rem_edges = array_diff_key($old_edges, $new_edges); | |||||
| if (!$add_edges && !$rem_edges) { | |||||
| return; | |||||
| } | } | ||||
| $editor = new PhabricatorEdgeEditor(); | protected function getIndexDestinationPHIDs($object) { | ||||
| $rule = $object; | |||||
| foreach ($add_edges as $phid) { | |||||
| $editor->addEdge($object->getPHID(), $edge_type, $phid); | |||||
| } | |||||
| foreach ($rem_edges as $phid) { | |||||
| $editor->removeEdge($object->getPHID(), $edge_type, $phid); | |||||
| } | |||||
| $editor->save(); | |||||
| } | |||||
| public function getIndexVersion($object) { | |||||
| $phids = $this->getPHIDsAffectedByActions($object); | |||||
| sort($phids); | |||||
| $phids = implode(':', $phids); | |||||
| return PhabricatorHash::digestForIndex($phids); | |||||
| } | |||||
| private function getPHIDsAffectedByActions(HeraldRule $rule) { | |||||
| $viewer = $this->getViewer(); | $viewer = $this->getViewer(); | ||||
| $rule = id(new HeraldRuleQuery()) | $rule = id(new HeraldRuleQuery()) | ||||
| ->setViewer($viewer) | ->setViewer($viewer) | ||||
| ->withIDs(array($rule->getID())) | ->withIDs(array($rule->getID())) | ||||
| ->needConditionsAndActions(true) | ->needConditionsAndActions(true) | ||||
| ->executeOne(); | ->executeOne(); | ||||
| if (!$rule) { | if (!$rule) { | ||||
| Show All 23 Lines | |||||