@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
1<?php
2
3abstract class PhabricatorEdgeIndexEngineExtension
4 extends PhabricatorIndexEngineExtension {
5
6 abstract protected function getIndexEdgeType();
7 abstract protected function getIndexDestinationPHIDs($object);
8
9 final public function indexObject(
10 PhabricatorIndexEngine $engine,
11 $object) {
12
13 $edge_type = $this->getIndexEdgeType();
14
15 $old_edges = PhabricatorEdgeQuery::loadDestinationPHIDs(
16 $object->getPHID(),
17 $edge_type);
18 $old_edges = array_fuse($old_edges);
19
20 $new_edges = $this->getIndexDestinationPHIDs($object);
21 $new_edges = array_fuse($new_edges);
22
23 $add_edges = array_diff_key($new_edges, $old_edges);
24 $rem_edges = array_diff_key($old_edges, $new_edges);
25
26 if (!$add_edges && !$rem_edges) {
27 return;
28 }
29
30 $editor = new PhabricatorEdgeEditor();
31
32 foreach ($add_edges as $phid) {
33 $editor->addEdge($object->getPHID(), $edge_type, $phid);
34 }
35
36 foreach ($rem_edges as $phid) {
37 $editor->removeEdge($object->getPHID(), $edge_type, $phid);
38 }
39
40 $editor->save();
41 }
42
43 final public function getIndexVersion($object) {
44 $phids = $this->getIndexDestinationPHIDs($object);
45 sort($phids);
46 $phids = implode(':', $phids);
47 return PhabricatorHash::digestForIndex($phids);
48 }
49
50}