Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/owners/xaction/PhabricatorOwnersPackageAuditingTransaction.php
12256 views
1
<?php
2
3
final class PhabricatorOwnersPackageAuditingTransaction
4
extends PhabricatorOwnersPackageTransactionType {
5
6
const TRANSACTIONTYPE = 'owners.auditing';
7
8
public function generateOldValue($object) {
9
return $object->getAuditingState();
10
}
11
12
public function generateNewValue($object, $value) {
13
return PhabricatorOwnersAuditRule::getStorageValueFromAPIValue($value);
14
}
15
16
public function applyInternalEffects($object, $value) {
17
$object->setAuditingState($value);
18
}
19
20
public function getTitle() {
21
$old_value = $this->getOldValue();
22
$new_value = $this->getNewValue();
23
24
$old_rule = PhabricatorOwnersAuditRule::newFromState($old_value);
25
$new_rule = PhabricatorOwnersAuditRule::newFromState($new_value);
26
27
return pht(
28
'%s changed the audit rule for this package from %s to %s.',
29
$this->renderAuthor(),
30
$this->renderValue($old_rule->getDisplayName()),
31
$this->renderValue($new_rule->getDisplayName()));
32
}
33
34
public function validateTransactions($object, array $xactions) {
35
$errors = array();
36
37
// See PHI1047. This transaction type accepted some weird stuff. Continue
38
// supporting it for now, but move toward sensible consistency.
39
40
$modern_options = PhabricatorOwnersAuditRule::getModernValueMap();
41
$deprecated_options = PhabricatorOwnersAuditRule::getDeprecatedValueMap();
42
43
foreach ($xactions as $xaction) {
44
$new_value = $xaction->getNewValue();
45
46
if (isset($modern_options[$new_value])) {
47
continue;
48
}
49
50
if (isset($deprecated_options[$new_value])) {
51
continue;
52
}
53
54
$errors[] = $this->newInvalidError(
55
pht(
56
'Package auditing value "%s" is not supported. Supported options '.
57
'are: %s. Deprecated options are: %s.',
58
$new_value,
59
implode(', ', $modern_options),
60
implode(', ', $deprecated_options)),
61
$xaction);
62
}
63
64
return $errors;
65
}
66
67
}
68
69