Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/owners/xaction/PhabricatorOwnersPackageIgnoredTransaction.php
12256 views
1
<?php
2
3
final class PhabricatorOwnersPackageIgnoredTransaction
4
extends PhabricatorOwnersPackageTransactionType {
5
6
const TRANSACTIONTYPE = 'owners.ignored';
7
8
public function generateOldValue($object) {
9
return $object->getIgnoredPathAttributes();
10
}
11
12
public function generateNewValue($object, $value) {
13
return array_fill_keys($value, true);
14
}
15
16
public function applyInternalEffects($object, $value) {
17
$object->setIgnoredPathAttributes($value);
18
}
19
20
public function getTitle() {
21
$old = array_keys($this->getOldValue());
22
$new = array_keys($this->getNewValue());
23
24
$add = array_diff($new, $old);
25
$rem = array_diff($old, $new);
26
27
$all_n = new PhutilNumber(count($add) + count($rem));
28
$add_n = phutil_count($add);
29
$rem_n = phutil_count($rem);
30
31
if ($new && $old) {
32
return pht(
33
'%s changed %s ignored attribute(s), added %s: %s; removed %s: %s.',
34
$this->renderAuthor(),
35
$all_n,
36
$add_n,
37
$this->renderValueList($add),
38
$rem_n,
39
$this->renderValueList($rem));
40
} else if ($new) {
41
return pht(
42
'%s changed %s ignored attribute(s), added %s: %s.',
43
$this->renderAuthor(),
44
$all_n,
45
$add_n,
46
$this->rendervalueList($add));
47
} else {
48
return pht(
49
'%s changed %s ignored attribute(s), removed %s: %s.',
50
$this->renderAuthor(),
51
$all_n,
52
$rem_n,
53
$this->rendervalueList($rem));
54
}
55
}
56
57
public function validateTransactions($object, array $xactions) {
58
$errors = array();
59
60
$valid_attributes = array(
61
'generated' => true,
62
);
63
64
foreach ($xactions as $xaction) {
65
$new = $xaction->getNewValue();
66
67
foreach ($new as $attribute) {
68
if (isset($valid_attributes[$attribute])) {
69
continue;
70
}
71
72
$errors[] = $this->newInvalidError(
73
pht(
74
'Changeset attribute "%s" is not valid. Valid changeset '.
75
'attributes are: %s.',
76
$attribute,
77
implode(', ', array_keys($valid_attributes))),
78
$xaction);
79
}
80
}
81
82
return $errors;
83
}
84
85
}
86
87