@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
3final class PhabricatorEdgeChangeRecord
4 extends Phobject {
5
6 private $xaction;
7
8 public static function newFromTransaction(
9 PhabricatorApplicationTransaction $xaction) {
10 $record = new self();
11 $record->xaction = $xaction;
12 return $record;
13 }
14
15 public function getChangedPHIDs() {
16 $add = $this->getAddedPHIDs();
17 $rem = $this->getRemovedPHIDs();
18
19 $add = array_fuse($add);
20 $rem = array_fuse($rem);
21
22 return array_keys($add + $rem);
23 }
24
25 public function getAddedPHIDs() {
26 $old = $this->getOldDestinationPHIDs();
27 $new = $this->getNewDestinationPHIDs();
28
29 $old = array_fuse($old);
30 $new = array_fuse($new);
31
32 $add = array_diff_key($new, $old);
33 return array_keys($add);
34 }
35
36 public function getRemovedPHIDs() {
37 $old = $this->getOldDestinationPHIDs();
38 $new = $this->getNewDestinationPHIDs();
39
40 $old = array_fuse($old);
41 $new = array_fuse($new);
42
43 $rem = array_diff_key($old, $new);
44 return array_keys($rem);
45 }
46
47 public function getModernOldEdgeTransactionData() {
48 return $this->getRemovedPHIDs();
49 }
50
51 public function getModernNewEdgeTransactionData() {
52 return $this->getAddedPHIDs();
53 }
54
55 private function getOldDestinationPHIDs() {
56 if ($this->xaction) {
57 $old = $this->xaction->getOldValue();
58 return $this->getPHIDsFromTransactionValue($old);
59 }
60
61 throw new Exception(
62 pht('Edge change record is not configured with any change data.'));
63 }
64
65 private function getNewDestinationPHIDs() {
66 if ($this->xaction) {
67 $new = $this->xaction->getNewValue();
68 return $this->getPHIDsFromTransactionValue($new);
69 }
70
71 throw new Exception(
72 pht('Edge change record is not configured with any change data.'));
73 }
74
75 private function getPHIDsFromTransactionValue($value) {
76 if (!$value) {
77 return array();
78 }
79
80 // If the list items are arrays, this is an older-style map of
81 // dictionaries.
82 $head = head($value);
83 if (is_array($head)) {
84 return ipull($value, 'dst');
85 }
86
87 // If the list items are not arrays, this is a newer-style list of PHIDs.
88 return $value;
89 }
90
91}