@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class HeraldWebhookStatusTransaction
4 extends HeraldWebhookTransactionType {
5
6 const TRANSACTIONTYPE = '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 = HeraldWebhook::getDisplayNameForStatus($old_value);
21 $new_status = HeraldWebhook::getDisplayNameForStatus($new_value);
22
23 return pht(
24 '%s changed hook status from %s to %s.',
25 $this->renderAuthor(),
26 $this->renderValue($old_status),
27 $this->renderValue($new_status));
28 }
29
30 public function getTitleForFeed() {
31 $old_value = $this->getOldValue();
32 $new_value = $this->getNewValue();
33
34 $old_status = HeraldWebhook::getDisplayNameForStatus($old_value);
35 $new_status = HeraldWebhook::getDisplayNameForStatus($new_value);
36
37 return pht(
38 '%s changed %s from %s to %s.',
39 $this->renderAuthor(),
40 $this->renderObject(),
41 $this->renderValue($old_status),
42 $this->renderValue($new_status));
43 }
44
45 public function validateTransactions($object, array $xactions) {
46 $errors = array();
47 $viewer = $this->getActor();
48
49 $options = HeraldWebhook::getStatusDisplayNameMap();
50
51 foreach ($xactions as $xaction) {
52 $new_value = $xaction->getNewValue();
53
54 if (!isset($options[$new_value])) {
55 $errors[] = $this->newInvalidError(
56 pht(
57 'Webhook status "%s" is not valid. Valid statuses are: %s.',
58 $new_value,
59 implode(', ', array_keys($options))),
60 $xaction);
61 }
62 }
63
64 return $errors;
65 }
66
67}