Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / search / engineextension / PhabricatorEdgeIndexEngineExtension.php
blob528285c17f55e6a9731ddd256665a99fe6240a79
1 <?php
3 abstract class PhabricatorEdgeIndexEngineExtension
4 extends PhabricatorIndexEngineExtension {
6 abstract protected function getIndexEdgeType();
7 abstract protected function getIndexDestinationPHIDs($object);
9 final public function indexObject(
10 PhabricatorIndexEngine $engine,
11 $object) {
13 $edge_type = $this->getIndexEdgeType();
15 $old_edges = PhabricatorEdgeQuery::loadDestinationPHIDs(
16 $object->getPHID(),
17 $edge_type);
18 $old_edges = array_fuse($old_edges);
20 $new_edges = $this->getIndexDestinationPHIDs($object);
21 $new_edges = array_fuse($new_edges);
23 $add_edges = array_diff_key($new_edges, $old_edges);
24 $rem_edges = array_diff_key($old_edges, $new_edges);
26 if (!$add_edges && !$rem_edges) {
27 return;
30 $editor = new PhabricatorEdgeEditor();
32 foreach ($add_edges as $phid) {
33 $editor->addEdge($object->getPHID(), $edge_type, $phid);
36 foreach ($rem_edges as $phid) {
37 $editor->removeEdge($object->getPHID(), $edge_type, $phid);
40 $editor->save();
43 final public function getIndexVersion($object) {
44 $phids = $this->getIndexDestinationPHIDs($object);
45 sort($phids);
46 $phids = implode(':', $phids);
47 return PhabricatorHash::digestForIndex($phids);