Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/owners/xaction/PhabricatorOwnersPackageOwnersTransaction.php
12256 views
1
<?php
2
3
final class PhabricatorOwnersPackageOwnersTransaction
4
extends PhabricatorOwnersPackageTransactionType {
5
6
const TRANSACTIONTYPE = 'owners.owners';
7
8
public function generateOldValue($object) {
9
$phids = mpull($object->getOwners(), 'getUserPHID');
10
$phids = array_values($phids);
11
return $phids;
12
}
13
14
public function generateNewValue($object, $value) {
15
$phids = array_unique($value);
16
$phids = array_values($phids);
17
return $phids;
18
}
19
20
public function applyExternalEffects($object, $value) {
21
$old = $this->generateOldValue($object);
22
$new = $value;
23
24
$owners = $object->getOwners();
25
$owners = mpull($owners, null, 'getUserPHID');
26
27
$rem = array_diff($old, $new);
28
foreach ($rem as $phid) {
29
if (isset($owners[$phid])) {
30
$owners[$phid]->delete();
31
unset($owners[$phid]);
32
}
33
}
34
35
$add = array_diff($new, $old);
36
foreach ($add as $phid) {
37
$owners[$phid] = id(new PhabricatorOwnersOwner())
38
->setPackageID($object->getID())
39
->setUserPHID($phid)
40
->save();
41
}
42
43
// TODO: Attach owners here
44
}
45
46
public function getTitle() {
47
$old = $this->getOldValue();
48
$new = $this->getNewValue();
49
50
$add = array_diff($new, $old);
51
$rem = array_diff($old, $new);
52
if ($add && !$rem) {
53
return pht(
54
'%s added %s owner(s): %s.',
55
$this->renderAuthor(),
56
count($add),
57
$this->renderHandleList($add));
58
} else if ($rem && !$add) {
59
return pht(
60
'%s removed %s owner(s): %s.',
61
$this->renderAuthor(),
62
count($rem),
63
$this->renderHandleList($rem));
64
} else {
65
return pht(
66
'%s changed %s package owner(s), added %s: %s; removed %s: %s.',
67
$this->renderAuthor(),
68
count($add) + count($rem),
69
count($add),
70
$this->renderHandleList($add),
71
count($rem),
72
$this->renderHandleList($rem));
73
}
74
}
75
76
}
77
78