Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/almanac/xaction/AlmanacNamespaceNameTransaction.php
12256 views
1
<?php
2
3
final class AlmanacNamespaceNameTransaction
4
extends AlmanacNamespaceTransactionType {
5
6
const TRANSACTIONTYPE = 'almanac:namespace: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 namespace 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
36
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
37
$errors[] = $this->newRequiredError(
38
pht('Namespace name is required.'));
39
}
40
41
foreach ($xactions as $xaction) {
42
$name = $xaction->getNewValue();
43
44
$message = null;
45
try {
46
AlmanacNames::validateName($name);
47
} catch (Exception $ex) {
48
$message = $ex->getMessage();
49
}
50
51
if ($message !== null) {
52
$errors[] = $this->newInvalidError($message, $xaction);
53
continue;
54
}
55
56
if ($name === $object->getName()) {
57
continue;
58
}
59
60
$other = id(new AlmanacNamespaceQuery())
61
->setViewer(PhabricatorUser::getOmnipotentUser())
62
->withNames(array($name))
63
->executeOne();
64
if ($other && ($other->getID() != $object->getID())) {
65
$errors[] = $this->newInvalidError(
66
pht(
67
'The namespace name "%s" is already in use by another '.
68
'namespace. Each namespace must have a unique name.',
69
$name),
70
$xaction);
71
continue;
72
}
73
74
$namespace = AlmanacNamespace::loadRestrictedNamespace(
75
$this->getActor(),
76
$name);
77
if ($namespace) {
78
$errors[] = $this->newInvalidError(
79
pht(
80
'You do not have permission to create Almanac namespaces '.
81
'within the "%s" namespace.',
82
$namespace->getName()),
83
$xaction);
84
continue;
85
}
86
}
87
88
return $errors;
89
}
90
91
}
92
93