Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / xaction / AlmanacServiceNameTransaction.php
blobea1ccb8faa4180107d37565129f5c87408076ade
1 <?php
3 final class AlmanacServiceNameTransaction
4 extends AlmanacServiceTransactionType {
6 const TRANSACTIONTYPE = 'almanac:service:name';
8 public function generateOldValue($object) {
9 return $object->getName();
12 public function applyInternalEffects($object, $value) {
13 $object->setName($value);
16 public function getTitle() {
17 return pht(
18 '%s renamed this service from %s to %s.',
19 $this->renderAuthor(),
20 $this->renderOldValue(),
21 $this->renderNewValue());
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());
33 public function validateTransactions($object, array $xactions) {
34 $errors = array();
36 if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
37 $errors[] = $this->newRequiredError(
38 pht('Almanac services must have a name.'));
41 foreach ($xactions as $xaction) {
42 $name = $xaction->getNewValue();
44 $message = null;
45 try {
46 AlmanacNames::validateName($name);
47 } catch (Exception $ex) {
48 $message = $ex->getMessage();
51 if ($message !== null) {
52 $errors[] = $this->newInvalidError($message, $xaction);
53 continue;
56 if ($name === $object->getName()) {
57 continue;
60 $other = id(new AlmanacServiceQuery())
61 ->setViewer(PhabricatorUser::getOmnipotentUser())
62 ->withNames(array($name))
63 ->executeOne();
64 if ($other && ($other->getID() != $object->getID())) {
65 $errors[] = $this->newInvalidError(
66 pht('Almanac services must have unique names.'),
67 $xaction);
68 continue;
71 $namespace = AlmanacNamespace::loadRestrictedNamespace(
72 $this->getActor(),
73 $name);
74 if ($namespace) {
75 $errors[] = $this->newInvalidError(
76 pht(
77 'You do not have permission to create Almanac services '.
78 'within the "%s" namespace.',
79 $namespace->getName()),
80 $xaction);
81 continue;
85 return $errors;