Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/herald/xaction/HeraldWebhookNameTransaction.php
12256 views
1
<?php
2
3
final class HeraldWebhookNameTransaction
4
extends HeraldWebhookTransactionType {
5
6
const TRANSACTIONTYPE = '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 webhook from %s to %s.',
19
$this->renderAuthor(),
20
$this->renderOldValue(),
21
$this->renderNewValue());
22
}
23
24
public function getTitleForFeed() {
25
return pht(
26
'%s renamed %s from %s to %s.',
27
$this->renderAuthor(),
28
$this->renderObject(),
29
$this->renderOldValue(),
30
$this->renderNewValue());
31
}
32
33
public function validateTransactions($object, array $xactions) {
34
$errors = array();
35
$viewer = $this->getActor();
36
37
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
38
$errors[] = $this->newRequiredError(
39
pht('Webhooks must have a name.'));
40
return $errors;
41
}
42
43
$max_length = $object->getColumnMaximumByteLength('name');
44
foreach ($xactions as $xaction) {
45
$old_value = $this->generateOldValue($object);
46
$new_value = $xaction->getNewValue();
47
48
$new_length = strlen($new_value);
49
if ($new_length > $max_length) {
50
$errors[] = $this->newInvalidError(
51
pht(
52
'Webhook names can be no longer than %s characters.',
53
new PhutilNumber($max_length)));
54
}
55
}
56
57
return $errors;
58
}
59
60
}
61
62