Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/xaction/HeraldRuleNameTransaction.php
12256 views
1
<?php
2
3
final 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
}
49
50