Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / xaction / AlmanacDeviceStatusTransaction.php
blob57c7c05507dc2a6530b347df921da1bf942eb346
1 <?php
3 final class AlmanacDeviceStatusTransaction
4 extends AlmanacDeviceTransactionType {
6 const TRANSACTIONTYPE = 'almanac:device:status';
8 public function generateOldValue($object) {
9 return $object->getStatus();
12 public function applyInternalEffects($object, $value) {
13 $object->setStatus($value);
16 public function getTitle() {
17 $old_value = $this->getOldValue();
18 $new_value = $this->getNewValue();
20 $old_status = AlmanacDeviceStatus::newStatusFromValue($old_value);
21 $new_status = AlmanacDeviceStatus::newStatusFromValue($new_value);
23 $old_name = $old_status->getName();
24 $new_name = $new_status->getName();
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));
33 public function validateTransactions($object, array $xactions) {
34 $errors = array();
36 $status_map = AlmanacDeviceStatus::getStatusMap();
38 $old_value = $this->generateOldValue($object);
39 foreach ($xactions as $xaction) {
40 $new_value = $xaction->getNewValue();
42 if ($new_value === $old_value) {
43 continue;
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;
58 return $errors;