@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 HeraldRuleNameTransaction
4 extends HeraldRuleTransactionType {
5
6 const TRANSACTIONTYPE = 'herald:name';
7
8 public function generateOldValue($object) {
9 return $object->getName();
10 }
11
12 public function applyInternalEffects($object, $value) {
13 $object->setName($value);
14 }
15
16 public function getTitle() {
17 return pht(
18 '%s renamed this rule from %s to %s.',
19 $this->renderAuthor(),
20 $this->renderOldValue(),
21 $this->renderNewValue());
22 }
23
24 public function validateTransactions($object, array $xactions) {
25 $errors = array();
26
27 if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
28 $errors[] = $this->newRequiredError(
29 pht('Rules must have a name.'));
30 }
31
32 $max_length = $object->getColumnMaximumByteLength('name');
33 foreach ($xactions as $xaction) {
34 $new_value = $xaction->getNewValue();
35
36 $new_length = strlen($new_value);
37 if ($new_length > $max_length) {
38 $errors[] = $this->newInvalidError(
39 pht(
40 'Rule names can be no longer than %s characters.',
41 new PhutilNumber($max_length)));
42 }
43 }
44
45 return $errors;
46 }
47
48}