Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / almanac / xaction / AlmanacDeviceNameTransaction.php
blobd72b380472cf5ce536389bc71f4de1129799dc99
1 <?php
3 final class AlmanacDeviceNameTransaction
4 extends AlmanacDeviceTransactionType {
6 const TRANSACTIONTYPE = 'almanac:device: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 device from %s to %s.',
19 $this->renderAuthor(),
20 $this->renderOldValue(),
21 $this->renderNewValue());
24 public function validateTransactions($object, array $xactions) {
25 $errors = array();
27 if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
28 $errors[] = $this->newRequiredError(
29 pht('Device name is required.'));
32 foreach ($xactions as $xaction) {
33 $name = $xaction->getNewValue();
35 $message = null;
36 try {
37 AlmanacNames::validateName($name);
38 } catch (Exception $ex) {
39 $message = $ex->getMessage();
42 if ($message !== null) {
43 $errors[] = $this->newInvalidError($message, $xaction);
44 continue;
47 if ($name === $object->getName()) {
48 continue;
51 $other = id(new AlmanacDeviceQuery())
52 ->setViewer(PhabricatorUser::getOmnipotentUser())
53 ->withNames(array($name))
54 ->executeOne();
55 if ($other && ($other->getID() != $object->getID())) {
56 $errors[] = $this->newInvalidError(
57 pht('Almanac devices must have unique names.'),
58 $xaction);
59 continue;
62 $namespace = AlmanacNamespace::loadRestrictedNamespace(
63 $this->getActor(),
64 $name);
65 if ($namespace) {
66 $errors[] = $this->newInvalidError(
67 pht(
68 'You do not have permission to create Almanac devices '.
69 'within the "%s" namespace.',
70 $namespace->getName()),
71 $xaction);
72 continue;
76 return $errors;