Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/harbormaster/xaction/plan/HarbormasterBuildPlanStatusTransaction.php
12264 views
1
<?php
2
3
final class HarbormasterBuildPlanStatusTransaction
4
extends HarbormasterBuildPlanTransactionType {
5
6
const TRANSACTIONTYPE = 'harbormaster:status';
7
8
public function generateOldValue($object) {
9
return $object->getPlanStatus();
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$object->setPlanStatus($value);
14
}
15
16
public function getTitle() {
17
$new = $this->getNewValue();
18
if ($new === HarbormasterBuildPlan::STATUS_DISABLED) {
19
return pht(
20
'%s disabled this build plan.',
21
$this->renderAuthor());
22
} else {
23
return pht(
24
'%s enabled this build plan.',
25
$this->renderAuthor());
26
}
27
}
28
29
public function validateTransactions($object, array $xactions) {
30
$errors = array();
31
32
$options = array(
33
HarbormasterBuildPlan::STATUS_DISABLED,
34
HarbormasterBuildPlan::STATUS_ACTIVE,
35
);
36
$options = array_fuse($options);
37
38
foreach ($xactions as $xaction) {
39
$new = $xaction->getNewValue();
40
41
if (!isset($options[$new])) {
42
$errors[] = $this->newInvalidError(
43
pht(
44
'Status "%s" is not a valid build plan status. Valid '.
45
'statuses are: %s.',
46
$new,
47
implode(', ', $options)));
48
continue;
49
}
50
51
}
52
53
return $errors;
54
}
55
56
public function getTransactionTypeForConduit($xaction) {
57
return 'status';
58
}
59
60
public function getFieldValuesForConduit($xaction, $data) {
61
return array(
62
'old' => $xaction->getOldValue(),
63
'new' => $xaction->getNewValue(),
64
);
65
}
66
67
}
68
69