Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/xaction/AlmanacDeviceStatusTransaction.php
12256 views
1
<?php
2
3
final class AlmanacDeviceStatusTransaction
4
extends AlmanacDeviceTransactionType {
5
6
const TRANSACTIONTYPE = 'almanac:device:status';
7
8
public function generateOldValue($object) {
9
return $object->getStatus();
10
}
11
12
public function applyInternalEffects($object, $value) {
13
$object->setStatus($value);
14
}
15
16
public function getTitle() {
17
$old_value = $this->getOldValue();
18
$new_value = $this->getNewValue();
19
20
$old_status = AlmanacDeviceStatus::newStatusFromValue($old_value);
21
$new_status = AlmanacDeviceStatus::newStatusFromValue($new_value);
22
23
$old_name = $old_status->getName();
24
$new_name = $new_status->getName();
25
26
return pht(
27
'%s changed the status of this device from %s to %s.',
28
$this->renderAuthor(),
29
$this->renderValue($old_name),
30
$this->renderValue($new_name));
31
}
32
33
public function validateTransactions($object, array $xactions) {
34
$errors = array();
35
36
$status_map = AlmanacDeviceStatus::getStatusMap();
37
38
$old_value = $this->generateOldValue($object);
39
foreach ($xactions as $xaction) {
40
$new_value = $xaction->getNewValue();
41
42
if ($new_value === $old_value) {
43
continue;
44
}
45
46
if (!isset($status_map[$new_value])) {
47
$errors[] = $this->newInvalidError(
48
pht(
49
'Almanac device status "%s" is unrecognized. Valid status '.
50
'values are: %s.',
51
$new_value,
52
implode(', ', array_keys($status_map))),
53
$xaction);
54
continue;
55
}
56
}
57
58
return $errors;
59
}
60
61
}
62
63